Skip to content

Commit

Permalink
Fix: calldata flag to not request rpc and keyfile
Browse files Browse the repository at this point in the history
  • Loading branch information
karacurt committed Nov 22, 2024
1 parent 3c4f3e8 commit 37dea13
Show file tree
Hide file tree
Showing 2 changed files with 424 additions and 400 deletions.
125 changes: 65 additions & 60 deletions evm/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -1320,12 +1320,15 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command {
Use: "deploy",
Short: "Deploy a new {{.StructName}} contract",
PreRunE: func(cmd *cobra.Command, args []string) error {
if keyfile == "" {
return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)")
}
if rpc == "" {
return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)")
if !calldata {
if keyfile == "" {
return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)")
}
if rpc == "" {
return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)")
}
}
if safeAddress != "" {
Expand Down Expand Up @@ -1395,6 +1398,22 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
// Generate deploy bytecode with constructor arguments
deployCalldata, err := generate{{.StructName}}DeployBytecode(
{{- range .DeployHandler.MethodArgs}}
{{.CLIVar}},
{{- end}}
)
if err != nil {
return fmt.Errorf("failed to generate deploy bytecode: %v", err)
}
if calldata {
deployCalldataHex := hex.EncodeToString(deployCalldata)
cmd.Printf(deployCalldataHex)
return nil
}
client, clientErr := NewClient(rpc)
if clientErr != nil {
return clientErr
Expand All @@ -1419,22 +1438,6 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command {
SetTransactionParametersFromArgs(transactionOpts, nonce, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, gasLimit, simulate)
// Generate deploy bytecode with constructor arguments
deployCalldata, err := generate{{.StructName}}DeployBytecode(
{{- range .DeployHandler.MethodArgs}}
{{.CLIVar}},
{{- end}}
)
if err != nil {
return fmt.Errorf("failed to generate deploy bytecode: %v", err)
}
if calldata {
deployCalldataHex := hex.EncodeToString(deployCalldata)
cmd.Printf(deployCalldataHex)
return nil
}
if safeAddress != "" {
// Create Safe proposal for deployment
value := transactionOpts.Value
Expand Down Expand Up @@ -1673,19 +1676,21 @@ func {{.HandlerName}}() *cobra.Command {
Use: "{{(KebabCase .MethodName)}}",
Short: "Execute the {{.MethodName}} method on a {{$structName}} contract",
PreRunE: func(cmd *cobra.Command, args []string) error {
if contractAddressRaw == "" {
return fmt.Errorf("--contract not specified")
} else if !common.IsHexAddress(contractAddressRaw) {
return fmt.Errorf("--contract is not a valid Ethereum address")
}
contractAddress = common.HexToAddress(contractAddressRaw)
if !calldata {
if contractAddressRaw == "" {
return fmt.Errorf("--contract not specified")
} else if !common.IsHexAddress(contractAddressRaw) {
return fmt.Errorf("--contract is not a valid Ethereum address")
}
contractAddress = common.HexToAddress(contractAddressRaw)
if keyfile == "" {
return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)")
}
if keyfile == "" {
return fmt.Errorf("--keystore not specified (this should be a path to an Ethereum account keystore file)")
}
if rpc == "" {
return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)")
if rpc == "" {
return fmt.Errorf("--rpc not specified (this should be a URL to an Ethereum JSONRPC API)")
}
}
if safeAddress != "" {
Expand Down Expand Up @@ -1729,6 +1734,34 @@ func {{.HandlerName}}() *cobra.Command {
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
abi, err := {{$structName}}MetaData.GetAbi()
if err != nil {
return fmt.Errorf("failed to get ABI: %v", err)
}
// Generate transaction data (override method name if safe function is specified)
methodName := "{{ToLowerCamel .MethodName}}"
if safeFunction != "" {
methodName = safeFunction
}
txCalldata, err := abi.Pack(
methodName,
{{- range .MethodArgs}}
{{.CLIVar}},
{{- end}}
)
if err != nil {
return err
}
if calldata {
txCalldataHex := hex.EncodeToString(txCalldata)
cmd.Printf(txCalldataHex)
return nil
}
client, clientErr := NewClient(rpc)
if clientErr != nil {
return clientErr
Expand Down Expand Up @@ -1763,34 +1796,6 @@ func {{.HandlerName}}() *cobra.Command {
TransactOpts: *transactionOpts,
}
abi, err := {{$structName}}MetaData.GetAbi()
if err != nil {
return fmt.Errorf("failed to get ABI: %v", err)
}
// Generate transaction data (override method name if safe function is specified)
methodName := "{{ToLowerCamel .MethodName}}"
if safeFunction != "" {
methodName = safeFunction
}
txCalldata, err := abi.Pack(
methodName,
{{- range .MethodArgs}}
{{.CLIVar}},
{{- end}}
)
if err != nil {
return err
}
if calldata {
txCalldataHex := hex.EncodeToString(txCalldata)
cmd.Printf(txCalldataHex)
return nil
}
if safeAddress != "" {
// Create Safe proposal for transaction
value := transactionOpts.Value
Expand Down
Loading

0 comments on commit 37dea13

Please sign in to comment.