/
tx.go
154 lines (125 loc) · 4.06 KB
/
tx.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package cli
import (
"encoding/json"
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
cmtypes "github.com/nephirim/blackfury/x/claimsmanager/types"
"github.com/nephirim/blackfury/x/participationrewards/types"
)
// GetTxCmd returns a root CLI command handler for all x/bank transaction commands.
func GetTxCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: types.ModuleName,
Short: "Participation rewards transaction subcommands",
Aliases: []string{"pr"},
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}
txCmd.AddCommand(GetSubmitClaimTxCmd())
return txCmd
}
func GetSubmitClaimTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "claim [zone] [src-zone] [claim-type] [payload-file].json",
Short: `Submit proof of assets held in the given zone.`,
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
zone := args[0]
srcZone := args[1]
claimTypeStr := args[2]
fileName := args[3]
claimType, ok := cmtypes.ClaimType_value[claimTypeStr]
if !ok {
return fmt.Errorf("invalid claim type: %s", claimTypeStr)
}
contents, err := os.ReadFile(fileName)
if err != nil {
return err
}
var proofs []*cmtypes.Proof
if err := json.Unmarshal(contents, &proofs); err != nil {
return err
}
msg := types.NewMsgSubmitClaim(clientCtx.GetFromAddress(), zone, srcZone, cmtypes.ClaimType(claimType), proofs)
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}
// GetCmdAddProtocolDataProposal implements the command to submit a add protocol data proposal.
func GetCmdAddProtocolDataProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "add-protocol-data [proposal-file]",
Args: cobra.ExactArgs(1),
Short: "Submit an add protocol data proposal",
Long: strings.TrimSpace(
`Submit an add protocol data proposal along with an initial deposit.
The proposal details must be supplied via a JSON file.
Example:
$ %s tx gov submit-proposal add-protocol-data <path/to/proposal.json> --from=<key_or_address>
Where proposal.json contains:
{
"title": "Add Osmosis Atom/qAtom Pool",
"description": "Add Osmosis Atom/qAtom Pool to support participation rewards",
"protocol": "osmosis",
"key": "pools/XXX",
"type": "osmosispool",
"data": {
"poolID": "596",
"ibcToken": "27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
"localDenom": "uqatom"
},
"deposit": "512000000ufury"
}
`),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
proposal, err := ParseAddProtocolDataProposal(clientCtx.Codec, args[0])
if err != nil {
return err
}
// parseData based on protocol
deposit, err := sdk.ParseCoinsNormalized(proposal.Deposit)
if err != nil {
return err
}
from := clientCtx.GetFromAddress()
content := types.NewAddProtocolDataProposal(proposal.Title, proposal.Description, proposal.Type, proposal.Protocol, proposal.Key,
proposal.Data)
msg, err := govv1beta1.NewMsgSubmitProposal(content, deposit, from)
if err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
return cmd
}
func ParseAddProtocolDataProposal(cdc codec.JSONCodec, proposalFile string) (types.AddProtocolDataProposalWithDeposit, error) {
proposal := types.AddProtocolDataProposalWithDeposit{}
contents, err := os.ReadFile(proposalFile)
if err != nil {
return proposal, err
}
if err := cdc.UnmarshalJSON(contents, &proposal); err != nil {
return proposal, err
}
return proposal, nil
}