diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-28 07:28:26 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:11 +0800 |
commit | f479212410b238a7673983148f403b3a220083af (patch) | |
tree | 4d3ebe1ee98ec0a03b8eb99275878f5cc2062123 /packages/utils/src/abi_encoder/evm_data_types | |
parent | ffb8b0a619be3b8fb30a6acc99f590a6b40d49e1 (diff) | |
download | dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar.gz dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar.bz2 dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar.lz dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar.xz dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.tar.zst dexon-0x-contracts-f479212410b238a7673983148f403b3a220083af.zip |
Style cleanup. Improved wording of some error messages.
Diffstat (limited to 'packages/utils/src/abi_encoder/evm_data_types')
6 files changed, 28 insertions, 22 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 52fc8e7b9..25ff55903 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/address.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/address.ts @@ -1,4 +1,3 @@ -/* tslint:disable prefer-function-over-method */ import { DataItem } from 'ethereum-types'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; @@ -26,10 +25,8 @@ export class Address extends AbstractDataTypes.Blob { } } - public getSignature(): string { - return 'address'; - } - + // 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); @@ -48,4 +45,9 @@ export class Address extends AbstractDataTypes.Blob { const value = ethUtil.bufferToHex(valueBuf); return value; } + + public getSignature(): string { + return 'address'; + } + /* tslint:enable prefer-function-over-method */ } diff --git a/packages/utils/src/abi_encoder/evm_data_types/bool.ts b/packages/utils/src/abi_encoder/evm_data_types/bool.ts index fa115bb87..7e135aba9 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/bool.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/bool.ts @@ -1,4 +1,3 @@ -/* tslint:disable prefer-function-over-method */ import { DataItem } from 'ethereum-types'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; @@ -22,6 +21,8 @@ export class Bool extends AbstractDataTypes.Blob { } } + // Disable prefer-function-over-method for inherited abstract methods. + /* tslint:disable prefer-function-over-method */ public encodeValue(value: boolean): Buffer { const encodedValue = value ? '0x1' : '0x0'; const encodedValueBuf = ethUtil.setLengthLeft( @@ -47,4 +48,5 @@ export class Bool extends AbstractDataTypes.Blob { public getSignature(): string { return 'bool'; } + /* tslint:enable prefer-function-over-method */ } diff --git a/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts b/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts index 98d90b7e4..ad22c8c6e 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts @@ -1,4 +1,3 @@ -/* tslint:disable prefer-function-over-method */ import { DataItem } from 'ethereum-types'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; @@ -14,6 +13,17 @@ export class DynamicBytes extends AbstractDataTypes.Blob { return type === 'bytes'; } + private static _sanityCheckValue(value: string | Buffer): void { + if (typeof value !== 'string') { + return; + } + if (!_.startsWith(value, '0x')) { + throw new Error(`Tried to encode non-hex value. Value must inlcude '0x' prefix.`); + } else if (value.length % 2 !== 0) { + throw new Error(`Tried to assign ${value}, which is contains a half-byte. Use full bytes only.`); + } + } + public constructor(dataItem: DataItem, dataTypeFactory: DataTypeFactory) { super(dataItem, dataTypeFactory, DynamicBytes._SIZE_KNOWN_AT_COMPILE_TIME); if (!DynamicBytes.matchType(dataItem.type)) { @@ -21,6 +31,8 @@ export class DynamicBytes extends AbstractDataTypes.Blob { } } + // Disable prefer-function-over-method for inherited abstract methods. + /* tslint:disable prefer-function-over-method */ public encodeValue(value: string | Buffer): Buffer { // Encoded value is of the form: <length><value>, with each field padded to be word-aligned. // 1/3 Construct the length @@ -48,22 +60,12 @@ export class DynamicBytes extends AbstractDataTypes.Blob { const valueBufPadded = calldata.popWords(wordsToStoreValuePadded); const valueBuf = valueBufPadded.slice(0, length); const value = ethUtil.bufferToHex(valueBuf); - this._sanityCheckValue(value); + DynamicBytes._sanityCheckValue(value); return value; } public getSignature(): string { return 'bytes'; } - - private _sanityCheckValue(value: string | Buffer): void { - if (typeof value !== 'string') { - return; - } - if (!_.startsWith(value, '0x')) { - throw new Error(`Tried to encode non-hex value. Value must inlcude '0x' prefix.`); - } else if (value.length % 2 !== 0) { - throw new Error(`Tried to assign ${value}, which is contains a half-byte. Use full bytes only.`); - } - } + /* tslint:enable prefer-function-over-method */ } diff --git a/packages/utils/src/abi_encoder/evm_data_types/int.ts b/packages/utils/src/abi_encoder/evm_data_types/int.ts index 5c5193644..9d328bba9 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/int.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/int.ts @@ -1,4 +1,3 @@ -/* tslint:disable prefer-function-over-method */ import { DataItem } from 'ethereum-types'; import * as _ from 'lodash'; diff --git a/packages/utils/src/abi_encoder/evm_data_types/string.ts b/packages/utils/src/abi_encoder/evm_data_types/string.ts index 6ab3513c9..08f928d8a 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/string.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/string.ts @@ -1,4 +1,3 @@ -/* tslint:disable prefer-function-over-method */ import { DataItem } from 'ethereum-types'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; @@ -21,6 +20,8 @@ export class String extends AbstractDataTypes.Blob { } } + // Disable prefer-function-over-method for inherited abstract methods. + /* tslint:disable prefer-function-over-method */ public encodeValue(value: string): Buffer { // Encoded value is of the form: <length><value>, with each field padded to be word-aligned. // 1/3 Construct the length @@ -53,4 +54,5 @@ export class String extends AbstractDataTypes.Blob { public getSignature(): string { return 'string'; } + /* tslint:enable prefer-function-over-method */ } diff --git a/packages/utils/src/abi_encoder/evm_data_types/uint.ts b/packages/utils/src/abi_encoder/evm_data_types/uint.ts index 76b944610..4357f15d2 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/uint.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/uint.ts @@ -1,4 +1,3 @@ -/* tslint:disable prefer-function-over-method */ import { DataItem } from 'ethereum-types'; import * as _ from 'lodash'; |