Skip to content

Commit

Permalink
update create2 cmd to receive slat
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Apr 9, 2024
1 parent 5a59891 commit f104891
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions x/evm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"fmt"
"os"
"strconv"
"strings"

"cosmossdk.io/core/address"
Expand Down Expand Up @@ -94,30 +95,41 @@ $ %s tx evm create \

func Create2Cmd(ac address.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "create2 [bin file1] [bin file2] [...]",
Use: "create2 [slat]:[bin file1] [salt]:[bin file2] [...]",
Short: "Deploy evm contracts with CREATE2 opcode",
Long: strings.TrimSpace(
fmt.Sprintf(`
Deploy evm contracts. allowed to upload up to 100 files at once.
Example:
$ %s tx evm create2 \
ERC20.bin \
1:ERC20.bin \
CustomDex.bin --from mykey
`, version.AppName,
),
),
Args: cobra.RangeArgs(1, 100),
Args: cobra.RangeArgs(2, 100),
Aliases: []string{"CREATE2"},
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

salts := make([]uint64, len(args))
contracts := make([][]byte, len(args))
for i, arg := range args {
hexStrBz, err := os.ReadFile(arg)
s := strings.Split(arg, ":")
if len(s) != 2 {
return fmt.Errorf("invalid argument: %s", arg)
}

salts[i], err = strconv.ParseUint(s[0], 10, 64)
if err != nil {
return err
}

hexStrBz, err := os.ReadFile(s[1])
if err != nil {
return err
}
Expand All @@ -137,6 +149,7 @@ $ %s tx evm create2 \
for i, contract := range contracts {
msgs[i] = &types.MsgCreate2{
Sender: sender,
Salt: salts[i],
Code: hexutil.Encode(contract),
}
}
Expand Down

0 comments on commit f104891

Please sign in to comment.