feat: eth cli: Strip out empty spaces around contract bytes
This commit is contained in:
parent
4f5fea848c
commit
b0fa75f13e
@ -413,6 +413,10 @@ func DecodeHexString(s string) ([]byte, error) {
|
|||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DecodeHexStringTrimSpace(s string) ([]byte, error) {
|
||||||
|
return DecodeHexString(strings.TrimSpace(s))
|
||||||
|
}
|
||||||
|
|
||||||
func handleHexStringPrefix(s string) string {
|
func handleHexStringPrefix(s string) string {
|
||||||
// Strip the leading 0x or 0X prefix since hex.DecodeString does not support it.
|
// Strip the leading 0x or 0X prefix since hex.DecodeString does not support it.
|
||||||
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
|
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
|
||||||
|
10
cli/evm.go
10
cli/evm.go
@ -107,7 +107,7 @@ var EvmCallSimulateCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
params, err := ethtypes.DecodeHexString(cctx.Args().Get(2))
|
params, err := ethtypes.DecodeHexStringTrimSpace(cctx.Args().Get(2))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ var EvmGetContractAddress = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
salt, err := ethtypes.DecodeHexString(cctx.Args().Get(1))
|
salt, err := ethtypes.DecodeHexStringTrimSpace(cctx.Args().Get(1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("Could not decode salt: %w", err)
|
return xerrors.Errorf("Could not decode salt: %w", err)
|
||||||
}
|
}
|
||||||
@ -170,7 +170,7 @@ var EvmGetContractAddress = &cli.Command{
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
contract, err := ethtypes.DecodeHexString(string(contractHex))
|
contract, err := ethtypes.DecodeHexStringTrimSpace(string(contractHex))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("Could not decode contract file: %w", err)
|
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)
|
return xerrors.Errorf("failed to read contract: %w", err)
|
||||||
}
|
}
|
||||||
if cctx.Bool("hex") {
|
if cctx.Bool("hex") {
|
||||||
contract, err = ethtypes.DecodeHexString(string(contract))
|
contract, err = ethtypes.DecodeHexStringTrimSpace(string(contract))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("failed to decode contract: %w", err)
|
return xerrors.Errorf("failed to decode contract: %w", err)
|
||||||
}
|
}
|
||||||
@ -341,7 +341,7 @@ var EvmInvokeCmd = &cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
var calldata []byte
|
var calldata []byte
|
||||||
calldata, err = ethtypes.DecodeHexString(cctx.Args().Get(1))
|
calldata, err = ethtypes.DecodeHexStringTrimSpace(cctx.Args().Get(1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("decoding hex input data: %w", err)
|
return xerrors.Errorf("decoding hex input data: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user