Skip to content

Commit

Permalink
add group msg decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
colmazia authored and RogerKSI committed Sep 21, 2023
1 parent 092c4b4 commit 560578a
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions hooks/emitter/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
feegranttypes "github.com/cosmos/cosmos-sdk/x/feegrant"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
"github.com/cosmos/cosmos-sdk/x/group"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
Expand Down Expand Up @@ -124,6 +125,34 @@ func DecodeMsg(msg sdk.Msg, detail common.JsDict) {
DecodeMsgGrantAllowance(msg, detail)
case *feegranttypes.MsgRevokeAllowance:
DecodeMsgRevokeAllowance(msg, detail)
case *group.MsgCreateGroup:
DecodeGroupMsgCreateGroup(msg, detail)
case *group.MsgCreateGroupPolicy:
DecodeGroupMsgCreateGroupPolicy(msg, detail)
case *group.MsgCreateGroupWithPolicy:
DecodeGroupMsgCreateGroupWithPolicy(msg, detail)
case *group.MsgExec:
DecodeGroupMsgExec(msg, detail)
case *group.MsgLeaveGroup:
DecodeGroupMsgLeaveGroup(msg, detail)
case *group.MsgSubmitProposal:
DecodeGroupMsgSubmitProposal(msg, detail)
case *group.MsgUpdateGroupAdmin:
DecodeGroupMsgUpdateGroupAdmin(msg, detail)
case *group.MsgUpdateGroupMembers:
DecodeGroupMsgUpdateGroupMembers(msg, detail)
case *group.MsgUpdateGroupMetadata:
DecodeGroupMsgUpdateGroupMetadata(msg, detail)
case *group.MsgUpdateGroupPolicyAdmin:
DecodeGroupMsgUpdateGroupPolicyAdmin(msg, detail)
case *group.MsgUpdateGroupPolicyDecisionPolicy:
DecodeGroupMsgUpdateGroupPolicyDecisionPolicy(msg, detail)
case *group.MsgUpdateGroupPolicyMetadata:
DecodeGroupMsgUpdateGroupPolicyMetadata(msg, detail)
case *group.MsgVote:
DecodeGroupMsgVote(msg, detail)
case *group.MsgWithdrawProposal:
DecodeGroupMsgWithdrawProposal(msg, detail)
default:
break
}
Expand Down Expand Up @@ -618,3 +647,108 @@ func DecodeDescription(des stakingtypes.Description) common.JsDict {
"website": des.GetWebsite(),
}
}

func DecodeGroupMsgCreateGroup(msg *group.MsgCreateGroup, detail common.JsDict) {
detail["admin"] = msg.Admin
detail["members"] = msg.Members
detail["metadata"] = msg.Metadata
}

func DecodeGroupMsgCreateGroupPolicy(msg *group.MsgCreateGroupPolicy, detail common.JsDict) {
detail["admin"] = msg.Admin
detail["group_id"] = msg.GroupId
detail["metadata"] = msg.Metadata
detail["decision_policy"] = msg.DecisionPolicy.GetCachedValue()
}

func DecodeGroupMsgCreateGroupWithPolicy(msg *group.MsgCreateGroupWithPolicy, detail common.JsDict) {
detail["admin"] = msg.Admin
detail["members"] = msg.Members
detail["group_metadata"] = msg.GroupMetadata
detail["group_policy_metadata"] = msg.GroupPolicyMetadata
detail["group_policy_as_admin"] = msg.GroupPolicyAsAdmin
detail["decision_policy"] = msg.DecisionPolicy.GetCachedValue()
}

func DecodeGroupMsgExec(msg *group.MsgExec, detail common.JsDict) {
detail["proposal_id"] = msg.ProposalId
detail["executor"] = msg.Executor
}

func DecodeGroupMsgLeaveGroup(msg *group.MsgLeaveGroup, detail common.JsDict) {
detail["address"] = msg.Address
detail["group_id"] = msg.GroupId
}

func DecodeGroupMsgSubmitProposal(msg *group.MsgSubmitProposal, detail common.JsDict) {
detail["group_policy_address"] = msg.GroupPolicyAddress
detail["proposers"] = msg.Proposers
detail["metadata"] = msg.Metadata

msgs, _ := msg.GetMsgs()
messages := make([]common.JsDict, len(msgs))
for i, m := range msgs {
detail := make(common.JsDict)
DecodeMsg(m, detail)
messages[i] = common.JsDict{
"msg": detail,
"type": sdk.MsgTypeURL(m),
}
}
detail["msgs"] = messages

detail["exec"] = msg.Exec.String()
detail["summary"] = msg.Summary
}

func DecodeGroupMsgUpdateGroupAdmin(msg *group.MsgUpdateGroupAdmin, detail common.JsDict) {
detail["admin"] = msg.Admin
detail["group_id"] = msg.GroupId
detail["new_admin"] = msg.NewAdmin
}

func DecodeGroupMsgUpdateGroupMembers(msg *group.MsgUpdateGroupMembers, detail common.JsDict) {
detail["admin"] = msg.Admin
detail["group_id"] = msg.GroupId
detail["members"] = msg.MemberUpdates
}

func DecodeGroupMsgUpdateGroupMetadata(msg *group.MsgUpdateGroupMetadata, detail common.JsDict) {
detail["admin"] = msg.Admin
detail["group_id"] = msg.GroupId
detail["metadata"] = msg.Metadata
}

func DecodeGroupMsgUpdateGroupPolicyAdmin(msg *group.MsgUpdateGroupPolicyAdmin, detail common.JsDict) {
detail["admin"] = msg.Admin
detail["group_policy_address"] = msg.GroupPolicyAddress
detail["new_admin"] = msg.NewAdmin
}

func DecodeGroupMsgUpdateGroupPolicyDecisionPolicy(
msg *group.MsgUpdateGroupPolicyDecisionPolicy,
detail common.JsDict,
) {
detail["admin"] = msg.Admin
detail["group_policy_address"] = msg.GroupPolicyAddress
detail["decision_policy"] = msg.DecisionPolicy.GetCachedValue()
}

func DecodeGroupMsgUpdateGroupPolicyMetadata(msg *group.MsgUpdateGroupPolicyMetadata, detail common.JsDict) {
detail["admin"] = msg.Admin
detail["group_policy_address"] = msg.GroupPolicyAddress
detail["metadata"] = msg.Metadata
}

func DecodeGroupMsgVote(msg *group.MsgVote, detail common.JsDict) {
detail["proposal_id"] = msg.ProposalId
detail["voter"] = msg.Voter
detail["option"] = msg.Option
detail["metadata"] = msg.Metadata
detail["exec"] = msg.Exec.String()
}

func DecodeGroupMsgWithdrawProposal(msg *group.MsgWithdrawProposal, detail common.JsDict) {
detail["proposal_id"] = msg.ProposalId
detail["address"] = msg.Address
}

0 comments on commit 560578a

Please sign in to comment.