Merge pull request #10224 from filecoin-project/feat/ethcli-strip-spaces

feat: eth cli: Strip out empty spaces around contract bytes
This commit is contained in:
Łukasz Magiera 2023-02-09 19:24:49 +01:00 committed by GitHub
commit 0f05232199
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -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") {

View File

@ -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)
}