Skip to content

Commit

Permalink
Merge pull request #10224 from filecoin-project/feat/ethcli-strip-spaces
Browse files Browse the repository at this point in the history
feat: eth cli: Strip out empty spaces around contract bytes
  • Loading branch information
magik6k authored Feb 9, 2023
2 parents 1c13a59 + b0fa75f commit 0f05232
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ func DecodeHexString(s string) ([]byte, error) {
return b, nil
}

func DecodeHexStringTrimSpace(s string) ([]byte, error) {
return DecodeHexString(strings.TrimSpace(s))
}

func handleHexStringPrefix(s string) string {
// Strip the leading 0x or 0X prefix since hex.DecodeString does not support it.
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
Expand Down
10 changes: 5 additions & 5 deletions cli/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ var EvmCallSimulateCmd = &cli.Command{
return err
}

params, err := ethtypes.DecodeHexString(cctx.Args().Get(2))
params, err := ethtypes.DecodeHexStringTrimSpace(cctx.Args().Get(2))
if err != nil {
return err
}
Expand Down Expand Up @@ -151,7 +151,7 @@ var EvmGetContractAddress = &cli.Command{
return err
}

salt, err := ethtypes.DecodeHexString(cctx.Args().Get(1))
salt, err := ethtypes.DecodeHexStringTrimSpace(cctx.Args().Get(1))
if err != nil {
return xerrors.Errorf("Could not decode salt: %w", err)
}
Expand All @@ -170,7 +170,7 @@ var EvmGetContractAddress = &cli.Command{

return err
}
contract, err := ethtypes.DecodeHexString(string(contractHex))
contract, err := ethtypes.DecodeHexStringTrimSpace(string(contractHex))
if err != nil {
return xerrors.Errorf("Could not decode contract file: %w", err)
}
Expand Down Expand Up @@ -219,7 +219,7 @@ var EvmDeployCmd = &cli.Command{
return xerrors.Errorf("failed to read contract: %w", err)
}
if cctx.Bool("hex") {
contract, err = ethtypes.DecodeHexString(string(contract))
contract, err = ethtypes.DecodeHexStringTrimSpace(string(contract))
if err != nil {
return xerrors.Errorf("failed to decode contract: %w", err)
}
Expand Down Expand Up @@ -341,7 +341,7 @@ var EvmInvokeCmd = &cli.Command{
}

var calldata []byte
calldata, err = ethtypes.DecodeHexString(cctx.Args().Get(1))
calldata, err = ethtypes.DecodeHexStringTrimSpace(cctx.Args().Get(1))
if err != nil {
return xerrors.Errorf("decoding hex input data: %w", err)
}
Expand Down

0 comments on commit 0f05232

Please sign in to comment.