diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5f326503..2bdf3118 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,7 +18,7 @@ jobs: uses: actions/checkout@v3 - name: Compute diff 📜 - uses: technote-space/get-diff-action@v6.1.0 + uses: technote-space/get-diff-action@v6.1.2 with: SUFFIX_FILTER: | .go @@ -27,9 +27,9 @@ jobs: - name: Setup Go 🧰 if: "env.GIT_DIFF != ''" - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: "1.20" - name: Run lint ✅ if: "env.GIT_DIFF != ''" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3f4204dd..3fe0cf38 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,9 +24,9 @@ jobs: uses: actions/checkout@v3 - name: Setup Go 🧰 - uses: actions/setup-go@v3 + uses: actions/setup-go@v4 with: - go-version: 1.19 + go-version: "1.20" - name: Compute diff 📜 uses: technote-space/get-diff-action@v6.1.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 1758d565..6d81f829 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,22 @@ +## Unreleased +### Changes +- ([\#97](https://github.com/forbole/juno/pull/97)) Add `x/authz` message parser + +## v5.1.0 +### Changes +- Bumped Go version to `1.20` +- Fixed a bug that caused messages type urls to be empty in the database +- Implemented a better default `EncodingConfigBuilder` +- Added the ability to set `DatabaseConfig` field values using setter methods +- ([\#96](https://github.com/forbole/juno/pull/96)) Export `Codec` and `LegacyAmino` from the `Database` implementation + +## v5.0.0 +### Changes +- Updated Cosmos SDK to `v0.47.2` + +### Database +- ([\#96](https://github.com/forbole/juno/pull/96)) Exported Codec and LegacyAmino codec inside Database wrapper + ## v4.2.0 ### Changes - ([\#93](https://github.com/forbole/juno/pull/93)) Decode IBC transfer data to JSON for `/ibc.core.channel.v1.MsgRecvPacket` message diff --git a/modules/messages/account_parser.go b/modules/messages/account_parser.go index 49f78c98..35eab967 100644 --- a/modules/messages/account_parser.go +++ b/modules/messages/account_parser.go @@ -2,6 +2,7 @@ package messages import ( "fmt" + "strings" "github.com/gogo/protobuf/proto" @@ -14,6 +15,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + authztypes "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -55,6 +57,7 @@ var CosmosMessageAddressesParser = JoinMessageParsers( IBCTransferMessagesParser, SlashingMessagesParser, StakingMessagesParser, + AuthzMessageParser, DefaultMessagesParser, ) @@ -230,3 +233,96 @@ func StakingMessagesParser(_ codec.Codec, cosmosMsg sdk.Msg) ([]string, error) { return nil, MessageNotSupported(cosmosMsg) } + +// AuthzMessageParser returns the list of all the accounts involved in the given +// message if it's related to the x/authz module +func AuthzMessageParser(c codec.Codec, cosmosMsg sdk.Msg) ([]string, error) { + switch msg := cosmosMsg.(type) { + case *authztypes.MsgGrant: + return []string{msg.Grantee, msg.Granter}, nil + case *authztypes.MsgRevoke: + return []string{msg.Grantee, msg.Granter}, nil + case *authztypes.MsgExec: + for _, index := range msg.Msgs { + var executedMsg sdk.Msg + if err := c.UnpackAny(index, &executedMsg); err != nil { + return nil, fmt.Errorf("error while unpacking message from authz: %s", err) + } + + switch { + case strings.Contains(index.TypeUrl, "bank"): + addresses, err := BankMessagesParser(c, executedMsg) + if err != nil { + return nil, MessageNotSupported(executedMsg) + } + addresses = append(addresses, msg.Grantee) + return addresses, nil + case strings.Contains(index.TypeUrl, "crisis"): + addresses, err := CrisisMessagesParser(c, executedMsg) + if err != nil { + return nil, MessageNotSupported(executedMsg) + } + addresses = append(addresses, msg.Grantee) + return addresses, nil + case strings.Contains(index.TypeUrl, "distribution"): + addresses, err := DistributionMessagesParser(c, executedMsg) + if err != nil { + return nil, MessageNotSupported(executedMsg) + } + addresses = append(addresses, msg.Grantee) + return addresses, nil + case strings.Contains(index.TypeUrl, "evidence"): + addresses, err := EvidenceMessagesParser(c, executedMsg) + if err != nil { + return nil, MessageNotSupported(executedMsg) + } + addresses = append(addresses, msg.Grantee) + return addresses, nil + case strings.Contains(index.TypeUrl, "gov.v1beta1"): + addresses, err := GovV1Beta1MessagesParser(c, executedMsg) + if err != nil { + return nil, MessageNotSupported(executedMsg) + } + addresses = append(addresses, msg.Grantee) + return addresses, nil + case strings.Contains(index.TypeUrl, "gov.v1."): + addresses, err := GovV1MessageParser(c, executedMsg) + if err != nil { + return nil, MessageNotSupported(executedMsg) + } + addresses = append(addresses, msg.Grantee) + return addresses, nil + case strings.Contains(index.TypeUrl, "ibc"): + addresses, err := IBCTransferMessagesParser(c, executedMsg) + if err != nil { + return nil, MessageNotSupported(executedMsg) + } + addresses = append(addresses, msg.Grantee) + return addresses, nil + case strings.Contains(index.TypeUrl, "slashing"): + addresses, err := SlashingMessagesParser(c, executedMsg) + if err != nil { + return nil, MessageNotSupported(executedMsg) + } + addresses = append(addresses, msg.Grantee) + return addresses, nil + case strings.Contains(index.TypeUrl, "staking"): + addresses, err := StakingMessagesParser(c, executedMsg) + if err != nil { + return nil, MessageNotSupported(executedMsg) + } + addresses = append(addresses, msg.Grantee) + return addresses, nil + default: + addresses, err := DefaultMessagesParser(c, executedMsg) + if err != nil { + return nil, MessageNotSupported(executedMsg) + } + addresses = append(addresses, msg.Grantee) + return addresses, nil + } + } + } + + return nil, MessageNotSupported(cosmosMsg) +}