github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/evm/client/cli/tx.go (about) 1 package cli 2 3 import ( 4 "bufio" 5 "fmt" 6 "strings" 7 8 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/client/context" 9 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 10 interfacetypes "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec/types" 11 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 12 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/version" 13 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth" 14 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/auth/client/utils" 15 evmutils "github.com/fibonacci-chain/fbc/x/evm/client/utils" 16 "github.com/fibonacci-chain/fbc/x/evm/types" 17 "github.com/fibonacci-chain/fbc/x/gov" 18 "github.com/spf13/cobra" 19 ) 20 21 // GetCmdManageContractDeploymentWhitelistProposal implements a command handler for submitting a manage contract deployment 22 // whitelist proposal transaction 23 func GetCmdManageContractDeploymentWhitelistProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 24 return &cobra.Command{ 25 Use: "update-contract-deployment-whitelist [proposal-file]", 26 Args: cobra.ExactArgs(1), 27 Short: "Submit an update contract deployment whitelist proposal", 28 Long: strings.TrimSpace( 29 fmt.Sprintf(`Submit an update contract deployment whitelist proposal along with an initial deposit. 30 The proposal details must be supplied via a JSON file. 31 32 Example: 33 $ %s tx gov submit-proposal update-contract-deployment-whitelist <path/to/proposal.json> --from=<key_or_address> 34 35 Where proposal.json contains: 36 37 { 38 "title": "update contract proposal whitelist with a distributor address list", 39 "description": "add a distributor address list into the whitelist", 40 "distributor_addresses": [ 41 "fb1cftp8q8g4aa65nw9s5trwexe77d9t6cr8ndu02", 42 "fb1k0wwsg7xf9tjt3rvxdewz42e74sp286agrf9qc" 43 ], 44 "is_added": true, 45 "deposit": [ 46 { 47 "denom": "%s", 48 "amount": "100.000000000000000000" 49 } 50 ] 51 } 52 `, version.ClientName, sdk.DefaultBondDenom, 53 )), 54 RunE: func(cmd *cobra.Command, args []string) error { 55 cdc := cdcP.GetCdc() 56 inBuf := bufio.NewReader(cmd.InOrStdin()) 57 txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc)) 58 cliCtx := context.NewCLIContext().WithCodec(cdc) 59 60 proposal, err := evmutils.ParseManageContractDeploymentWhitelistProposalJSON(cdc, args[0]) 61 if err != nil { 62 return err 63 } 64 65 content := types.NewManageContractDeploymentWhitelistProposal( 66 proposal.Title, 67 proposal.Description, 68 proposal.DistributorAddrs, 69 proposal.IsAdded, 70 ) 71 72 err = content.ValidateBasic() 73 if err != nil { 74 return err 75 } 76 77 msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, cliCtx.GetFromAddress()) 78 return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) 79 }, 80 } 81 } 82 83 // GetCmdManageContractBlockedListProposal implements a command handler for submitting a manage contract blocked list 84 // proposal transaction 85 func GetCmdManageContractBlockedListProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 86 return &cobra.Command{ 87 Use: "update-contract-blocked-list [proposal-file]", 88 Args: cobra.ExactArgs(1), 89 Short: "Submit an update contract blocked list proposal", 90 Long: strings.TrimSpace( 91 fmt.Sprintf(`Submit an update contract blocked list proposal along with an initial deposit. 92 The proposal details must be supplied via a JSON file. 93 94 Example: 95 $ %s tx gov submit-proposal update-contract-blocked-list <path/to/proposal.json> --from=<key_or_address> 96 97 Where proposal.json contains: 98 99 { 100 "title": "update contract blocked list proposal with a contract address list", 101 "description": "add a contract address list into the blocked list", 102 "contract_addresses": [ 103 "fb1cftp8q8g4aa65nw9s5trwexe77d9t6cr8ndu02", 104 "fb1k0wwsg7xf9tjt3rvxdewz42e74sp286agrf9qc" 105 ], 106 "is_added": true, 107 "deposit": [ 108 { 109 "denom": "%s", 110 "amount": "100.000000000000000000" 111 } 112 ] 113 } 114 `, version.ClientName, sdk.DefaultBondDenom, 115 )), 116 RunE: func(cmd *cobra.Command, args []string) error { 117 cdc := cdcP.GetCdc() 118 inBuf := bufio.NewReader(cmd.InOrStdin()) 119 txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc)) 120 cliCtx := context.NewCLIContext().WithCodec(cdc) 121 122 proposal, err := evmutils.ParseManageContractBlockedListProposalJSON(cdc, args[0]) 123 if err != nil { 124 return err 125 } 126 127 content := types.NewManageContractBlockedListProposal( 128 proposal.Title, 129 proposal.Description, 130 proposal.ContractAddrs, 131 proposal.IsAdded, 132 ) 133 134 err = content.ValidateBasic() 135 if err != nil { 136 return err 137 } 138 139 msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, cliCtx.GetFromAddress()) 140 return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) 141 }, 142 } 143 } 144 145 // GetCmdManageContractMethodBlockedListProposal implements a command handler for submitting a manage contract blocked list 146 // proposal transaction 147 func GetCmdManageContractMethodBlockedListProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 148 return &cobra.Command{ 149 Use: "update-contract-method-blocked-list [proposal-file]", 150 Args: cobra.ExactArgs(1), 151 Short: "Submit an update contract method blocked list proposal", 152 Long: strings.TrimSpace( 153 fmt.Sprintf(`Submit an update method contract blocked list proposal along with an initial deposit. 154 The proposal details must be supplied via a JSON file. 155 156 Example: 157 $ %s tx gov submit-proposal update-contract-blocked-list <path/to/proposal.json> --from=<key_or_address> 158 159 Where proposal.json contains: 160 161 { 162 "title":"update contract blocked list proposal with a contract address list", 163 "description":"add a contract address list into the blocked list", 164 "contract_addresses":[ 165 { 166 "address":"fb1k0wwsg7xf9tjt3rvxdewz42e74sp286agrf9qc", 167 "block_methods": [ 168 { 169 "sign": "0x371303c0", 170 "extra": "inc()" 171 }, 172 { 173 "sign": "0x579be378", 174 "extra": "onc()" 175 } 176 ] 177 }, 178 { 179 "address":"fb1s0vrf96rrsknl64jj65lhf89ltwj7lksr7m3r9", 180 "block_methods": [ 181 { 182 "sign": "0x371303c0", 183 "extra": "inc()" 184 }, 185 { 186 "sign": "0x579be378", 187 "extra": "onc()" 188 } 189 ] 190 } 191 ], 192 "is_added":true, 193 "deposit":[ 194 { 195 "denom":"%s", 196 "amount":"100.000000000000000000" 197 } 198 ] 199 } 200 `, version.ClientName, sdk.DefaultBondDenom, 201 )), 202 RunE: func(cmd *cobra.Command, args []string) error { 203 cdc := cdcP.GetCdc() 204 inBuf := bufio.NewReader(cmd.InOrStdin()) 205 txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc)) 206 cliCtx := context.NewCLIContext().WithCodec(cdc) 207 208 proposal, err := evmutils.ParseManageContractMethodBlockedListProposalJSON(cdc, args[0]) 209 if err != nil { 210 return err 211 } 212 213 content := types.NewManageContractMethodBlockedListProposal( 214 proposal.Title, 215 proposal.Description, 216 proposal.ContractList, 217 proposal.IsAdded, 218 ) 219 220 err = content.ValidateBasic() 221 if err != nil { 222 return err 223 } 224 225 msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, cliCtx.GetFromAddress()) 226 return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) 227 }, 228 } 229 } 230 231 // GetCmdManageSysContractAddressProposal implements a command handler for submitting a manage system contract address 232 // proposal transaction 233 func GetCmdManageSysContractAddressProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 234 return &cobra.Command{ 235 Use: "system-contract-address [proposal-file]", 236 Args: cobra.ExactArgs(1), 237 Short: "Submit a system contract address proposal", 238 Long: strings.TrimSpace( 239 fmt.Sprintf(`Submit a system contract address proposal. 240 The proposal details must be supplied via a JSON file. 241 242 Example: 243 $ %s tx gov submit-proposal system-contract-address <path/to/proposal.json> --from=<key_or_address> 244 245 Where proposal.json contains: 246 247 { 248 "title":"Update system contract address", 249 "description":"Will change the system contract address", 250 "contract_addresses": "0x1033796B018B2bf0Fc9CB88c0793b2F275eDB624", 251 "is_added":true, 252 "deposit": [ 253 { 254 "denom": "%s", 255 "amount": "100.000000000000000000" 256 } 257 ] 258 } 259 `, version.ClientName, sdk.DefaultBondDenom, 260 )), 261 RunE: func(cmd *cobra.Command, args []string) error { 262 cdc := cdcP.GetCdc() 263 inBuf := bufio.NewReader(cmd.InOrStdin()) 264 txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc)) 265 cliCtx := context.NewCLIContext().WithCodec(cdc) 266 267 proposal, err := evmutils.ParseManageSysContractAddressProposalJSON(cdc, args[0]) 268 if err != nil { 269 return err 270 } 271 272 content := types.NewManageSysContractAddressProposal( 273 proposal.Title, 274 proposal.Description, 275 proposal.ContractAddr, 276 proposal.IsAdded, 277 ) 278 279 err = content.ValidateBasic() 280 if err != nil { 281 return err 282 } 283 284 msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, cliCtx.GetFromAddress()) 285 return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) 286 }, 287 } 288 } 289 290 // GetCmdManageContractMethodGuFactorProposal implements a command handler for submitting a manage contract method gu-factor proposal transaction 291 func GetCmdManageContractMethodGuFactorProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 292 return &cobra.Command{ 293 Use: "update-contract-method-gu-factor [proposal-file]", 294 Args: cobra.ExactArgs(1), 295 Short: "Submit an update contract method gu-factor proposal", 296 Long: strings.TrimSpace( 297 fmt.Sprintf(`Submit an update method contract gu-factor proposal along with an initial deposit. 298 The proposal details must be supplied via a JSON file. 299 300 Example: 301 $ %s tx gov submit-proposal update-contract-method-gu-factor <path/to/proposal.json> --from=<key_or_address> 302 303 Where proposal.json contains: 304 305 { 306 "title":"update contract method gu-factor proposal with a contract address list", 307 "description":"add a contract method gu-factor list into chain", 308 "contract_addresses":[ 309 { 310 "address":"fb1k0wwsg7xf9tjt3rvxdewz42e74sp286agrf9qc", 311 "block_methods": [ 312 { 313 "sign": "0x371303c0", 314 "extra": "{\"gu_factor\":\"10.000000000000000000\"}" 315 }, 316 { 317 "sign": "0x579be378", 318 "extra": "{\"gu_factor\":\"20.000000000000000000\"}" 319 } 320 ] 321 }, 322 { 323 "address":"fb1s0vrf96rrsknl64jj65lhf89ltwj7lksr7m3r9", 324 "block_methods": [ 325 { 326 "sign": "0x371303c0", 327 "extra": "{\"gu_factor\":\"30.000000000000000000\"}" 328 }, 329 { 330 "sign": "0x579be378", 331 "extra": "{\"gu_factor\":\"40.000000000000000000\"}" 332 } 333 ] 334 } 335 ], 336 "is_added":true, 337 "deposit":[ 338 { 339 "denom":"%s", 340 "amount":"100.000000000000000000" 341 } 342 ] 343 } 344 `, version.ClientName, sdk.DefaultBondDenom, 345 )), 346 RunE: func(cmd *cobra.Command, args []string) error { 347 cdc := cdcP.GetCdc() 348 inBuf := bufio.NewReader(cmd.InOrStdin()) 349 txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc)) 350 cliCtx := context.NewCLIContext().WithCodec(cdc) 351 352 proposal, err := evmutils.ParseManageContractMethodBlockedListProposalJSON(cdc, args[0]) 353 if err != nil { 354 return err 355 } 356 357 content := types.NewManageContractMethodBlockedListProposal( 358 proposal.Title, 359 proposal.Description, 360 proposal.ContractList, 361 proposal.IsAdded, 362 ) 363 364 err = content.ValidateBasic() 365 if err != nil { 366 return err 367 } 368 369 msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, cliCtx.GetFromAddress()) 370 return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) 371 }, 372 } 373 } 374 375 // GetCmdManageContractByteCodeProposal implements a command handler for submitting a manage contract bytecode proposal transaction 376 func GetCmdManageContractByteCodeProposal(cdcP *codec.CodecProxy, reg interfacetypes.InterfaceRegistry) *cobra.Command { 377 return &cobra.Command{ 378 Use: "update-contract-bytecode [proposal-file]", 379 Args: cobra.ExactArgs(1), 380 Short: "Submit an update contract bytecode proposal", 381 Long: strings.TrimSpace( 382 fmt.Sprintf(`Submit an update contract bytecode proposal along with an initial deposit. 383 The proposal details must be supplied via a JSON file. 384 Example: 385 $ %s tx gov submit-proposal update-contract-bytecode <path/to/proposal.json> --from=<key_or_address> 386 Where proposal.json contains: 387 { 388 "title":"update contract bytecode", 389 "description":"update contract bytecode", 390 "contract":"0x9a59ae3Fc0948717F94242fc170ac1d5dB3f0D5D", 391 "substitute_contract":"0xFc0b06f1C1e82eFAdC0E5c226616B092D2cb97fF", 392 "deposit":[ 393 { 394 "denom":"%s", 395 "amount":"100.000000000000000000" 396 } 397 ] 398 } 399 `, version.ClientName, sdk.DefaultBondDenom, 400 )), 401 RunE: func(cmd *cobra.Command, args []string) error { 402 cdc := cdcP.GetCdc() 403 inBuf := bufio.NewReader(cmd.InOrStdin()) 404 txBldr := auth.NewTxBuilderFromCLI(inBuf).WithTxEncoder(utils.GetTxEncoder(cdc)) 405 cliCtx := context.NewCLIContext().WithCodec(cdc) 406 407 proposal, err := evmutils.ParseManageContractBytecodeProposalJSON(cdc, args[0]) 408 if err != nil { 409 return err 410 } 411 412 content := types.NewManageContractByteCodeProposal( 413 proposal.Title, 414 proposal.Description, 415 proposal.Contract, 416 proposal.SubstituteContract, 417 ) 418 419 err = content.ValidateBasic() 420 if err != nil { 421 return err 422 } 423 424 msg := gov.NewMsgSubmitProposal(content, proposal.Deposit, cliCtx.GetFromAddress()) 425 return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) 426 }, 427 } 428 }