From b0fa75f13e9b0b285990454c139049a17ad5bd4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 9 Feb 2023 18:49:08 +0100 Subject: [PATCH] feat: eth cli: Strip out empty spaces around contract bytes --- chain/types/ethtypes/eth_types.go | 4 ++++ cli/evm.go | 10 +++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/chain/types/ethtypes/eth_types.go b/chain/types/ethtypes/eth_types.go index 7ddf3b79a..ea083f6c1 100644 --- a/chain/types/ethtypes/eth_types.go +++ b/chain/types/ethtypes/eth_types.go @@ -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") { diff --git a/cli/evm.go b/cli/evm.go index 1c02f92b4..2169a3486 100644 --- a/cli/evm.go +++ b/cli/evm.go @@ -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 } @@ -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) } @@ -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) } @@ -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) } @@ -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) }