diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-28 08:20:56 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:11 +0800 |
commit | f196dc9e35d12aad281142371af4d2c32db1fd60 (patch) | |
tree | 9aafca26c7abd3ea395cf8943aca7eb7b5707c64 /packages/utils/src | |
parent | e7bdf4717da9d1fd50cda3dba4e9549dfbc337f7 (diff) | |
download | dexon-sol-tools-f196dc9e35d12aad281142371af4d2c32db1fd60.tar dexon-sol-tools-f196dc9e35d12aad281142371af4d2c32db1fd60.tar.gz dexon-sol-tools-f196dc9e35d12aad281142371af4d2c32db1fd60.tar.bz2 dexon-sol-tools-f196dc9e35d12aad281142371af4d2c32db1fd60.tar.lz dexon-sol-tools-f196dc9e35d12aad281142371af4d2c32db1fd60.tar.xz dexon-sol-tools-f196dc9e35d12aad281142371af4d2c32db1fd60.tar.zst dexon-sol-tools-f196dc9e35d12aad281142371af4d2c32db1fd60.zip |
Use ethUti.isValidAddress in encoder
Diffstat (limited to 'packages/utils/src')
-rw-r--r-- | packages/utils/src/abi_encoder/evm_data_types/address.ts | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/packages/utils/src/abi_encoder/evm_data_types/address.ts b/packages/utils/src/abi_encoder/evm_data_types/address.ts index 25ff55903..950901ea8 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/address.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/address.ts @@ -7,8 +7,6 @@ import { RawCalldata } from '../calldata'; import * as Constants from '../utils/constants'; export class Address extends AbstractDataTypes.Blob { - public static ERROR_MESSAGE_ADDRESS_MUST_START_WITH_0X = "Address must start with '0x'"; - public static ERROR_MESSAGE_ADDRESS_MUST_BE_20_BYTES = 'Address must be 20 bytes'; private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = true; private static readonly _ADDRESS_SIZE_IN_BYTES = 20; private static readonly _DECODED_ADDRESS_OFFSET_IN_BYTES = Constants.EVM_WORD_WIDTH_IN_BYTES - @@ -28,13 +26,10 @@ export class Address extends AbstractDataTypes.Blob { // Disable prefer-function-over-method for inherited abstract methods. /* tslint:disable prefer-function-over-method */ public encodeValue(value: string): Buffer { - if (!_.startsWith(value, '0x')) { - throw new Error(Address.ERROR_MESSAGE_ADDRESS_MUST_START_WITH_0X); + if (!ethUtil.isValidAddress(value)) { + throw new Error(`Invalid address: '${value}'`); } const valueBuf = ethUtil.toBuffer(value); - if (valueBuf.byteLength !== Address._ADDRESS_SIZE_IN_BYTES) { - throw new Error(Address.ERROR_MESSAGE_ADDRESS_MUST_BE_20_BYTES); - } const encodedValueBuf = ethUtil.setLengthLeft(valueBuf, Constants.EVM_WORD_WIDTH_IN_BYTES); return encodedValueBuf; } |