From a895dacd4e20238087245c274564f694c71f7f6e Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Tue, 20 Nov 2018 14:18:01 -0800 Subject: moved abi encoder constants into utils dir --- .../src/abi_encoder/abstract_data_types/dependent_data_type.ts | 2 +- .../utils/src/abi_encoder/abstract_data_types/member_data_type.ts | 2 +- packages/utils/src/abi_encoder/calldata/calldata.ts | 2 +- .../utils/src/abi_encoder/calldata/dependent_calldata_block.ts | 2 +- packages/utils/src/abi_encoder/calldata/raw_calldata.ts | 2 +- packages/utils/src/abi_encoder/constants.ts | 8 -------- packages/utils/src/abi_encoder/evm_data_types/address.ts | 4 ++-- packages/utils/src/abi_encoder/evm_data_types/array.ts | 2 +- packages/utils/src/abi_encoder/evm_data_types/bool.ts | 2 +- packages/utils/src/abi_encoder/evm_data_types/dynamic_bytes.ts | 2 +- packages/utils/src/abi_encoder/evm_data_types/method.ts | 2 +- packages/utils/src/abi_encoder/evm_data_types/number.ts | 2 +- packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts | 4 ++-- packages/utils/src/abi_encoder/evm_data_types/string.ts | 2 +- packages/utils/src/abi_encoder/utils/constants.ts | 8 ++++++++ 15 files changed, 23 insertions(+), 23 deletions(-) delete mode 100644 packages/utils/src/abi_encoder/constants.ts create mode 100644 packages/utils/src/abi_encoder/utils/constants.ts (limited to 'packages/utils/src/abi_encoder') diff --git a/packages/utils/src/abi_encoder/abstract_data_types/dependent_data_type.ts b/packages/utils/src/abi_encoder/abstract_data_types/dependent_data_type.ts index e9f390b22..f4992dd0f 100644 --- a/packages/utils/src/abi_encoder/abstract_data_types/dependent_data_type.ts +++ b/packages/utils/src/abi_encoder/abstract_data_types/dependent_data_type.ts @@ -3,7 +3,7 @@ import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; import { CalldataBlock, DependentCalldataBlock, RawCalldata } from '../calldata'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; import { DecodingRules } from '../utils/rules'; import { DataType } from './data_type'; diff --git a/packages/utils/src/abi_encoder/abstract_data_types/member_data_type.ts b/packages/utils/src/abi_encoder/abstract_data_types/member_data_type.ts index f44a6dd30..318564e21 100644 --- a/packages/utils/src/abi_encoder/abstract_data_types/member_data_type.ts +++ b/packages/utils/src/abi_encoder/abstract_data_types/member_data_type.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash'; import { BigNumber } from '../../configured_bignumber'; import { CalldataBlock, MemberCalldataBlock, RawCalldata } from '../calldata'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; import { DecodingRules } from '../utils/rules'; import { DataType } from './data_type'; diff --git a/packages/utils/src/abi_encoder/calldata/calldata.ts b/packages/utils/src/abi_encoder/calldata/calldata.ts index 1abf1b681..154a81b7f 100644 --- a/packages/utils/src/abi_encoder/calldata/calldata.ts +++ b/packages/utils/src/abi_encoder/calldata/calldata.ts @@ -1,7 +1,7 @@ import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; import { Queue } from '../utils/queue'; import { EncodingRules } from '../utils/rules'; diff --git a/packages/utils/src/abi_encoder/calldata/dependent_calldata_block.ts b/packages/utils/src/abi_encoder/calldata/dependent_calldata_block.ts index 4aec5eabc..16b9a6fe6 100644 --- a/packages/utils/src/abi_encoder/calldata/dependent_calldata_block.ts +++ b/packages/utils/src/abi_encoder/calldata/dependent_calldata_block.ts @@ -1,6 +1,6 @@ import * as ethUtil from 'ethereumjs-util'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; import { CalldataBlock } from './calldata_block'; diff --git a/packages/utils/src/abi_encoder/calldata/raw_calldata.ts b/packages/utils/src/abi_encoder/calldata/raw_calldata.ts index b7bd35737..27a59c6a3 100644 --- a/packages/utils/src/abi_encoder/calldata/raw_calldata.ts +++ b/packages/utils/src/abi_encoder/calldata/raw_calldata.ts @@ -1,6 +1,6 @@ import * as ethUtil from 'ethereumjs-util'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; import { Queue } from '../utils/queue'; export class RawCalldata { diff --git a/packages/utils/src/abi_encoder/constants.ts b/packages/utils/src/abi_encoder/constants.ts deleted file mode 100644 index 3d85fbdb8..000000000 --- a/packages/utils/src/abi_encoder/constants.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const EVM_WORD_WIDTH_IN_BYTES = 32; -export const EVM_WORD_WIDTH_IN_BITS = 256; -export const HEX_BASE = 16; -export const DEC_BASE = 10; -export const BIN_BASE = 2; -export const HEX_SELECTOR_LENGTH_IN_CHARS = 10; -export const HEX_SELECTOR_LENGTH_IN_BYTES = 4; -export const HEX_SELECTOR_BYTE_OFFSET_IN_CALLDATA = 0; 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 0107fdc50..aab5a0605 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/address.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/address.ts @@ -5,7 +5,7 @@ import * as _ from 'lodash'; import { DataTypeFactory, PayloadDataType } from '../abstract_data_types'; import { RawCalldata } from '../calldata'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; export class Address extends PayloadDataType { public static ERROR_MESSAGE_ADDRESS_MUST_START_WITH_0X = "Address must start with '0x'"; @@ -13,7 +13,7 @@ export class Address extends PayloadDataType { 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 - - Address._ADDRESS_SIZE_IN_BYTES; + Address._ADDRESS_SIZE_IN_BYTES; public static matchType(type: string): boolean { return type === 'address'; diff --git a/packages/utils/src/abi_encoder/evm_data_types/array.ts b/packages/utils/src/abi_encoder/evm_data_types/array.ts index f334282b8..9963b6f32 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/array.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/array.ts @@ -1,7 +1,7 @@ import { DataItem } from 'ethereum-types'; import { DataTypeFactory, MemberDataType } from '../abstract_data_types'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; export class Array extends MemberDataType { private static readonly _matcher = RegExp('^(.+)\\[([0-9]*)\\]$'); 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 4b9dd32b1..6bc299544 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/bool.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/bool.ts @@ -6,7 +6,7 @@ import * as _ from 'lodash'; import { BigNumber } from '../../configured_bignumber'; import { DataTypeFactory, PayloadDataType } from '../abstract_data_types'; import { RawCalldata } from '../calldata'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; export class Bool extends PayloadDataType { private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = true; 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 5fca668e4..626e266c9 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 @@ -5,7 +5,7 @@ import * as _ from 'lodash'; import { DataTypeFactory, PayloadDataType } from '../abstract_data_types'; import { RawCalldata } from '../calldata'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; export class DynamicBytes extends PayloadDataType { private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = false; diff --git a/packages/utils/src/abi_encoder/evm_data_types/method.ts b/packages/utils/src/abi_encoder/evm_data_types/method.ts index ce33755f1..50d676b4a 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/method.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/method.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash'; import { DataType, DataTypeFactory, MemberDataType } from '../abstract_data_types'; import { RawCalldata } from '../calldata'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; import { DecodingRules, EncodingRules } from '../utils/rules'; import { StaticBytes } from './static_bytes'; diff --git a/packages/utils/src/abi_encoder/evm_data_types/number.ts b/packages/utils/src/abi_encoder/evm_data_types/number.ts index 8ff5e9a6a..86acdce07 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/number.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/number.ts @@ -5,7 +5,7 @@ import * as _ from 'lodash'; import { BigNumber } from '../../configured_bignumber'; import { DataTypeFactory, PayloadDataType } from '../abstract_data_types'; import { RawCalldata } from '../calldata'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; export abstract class Number extends PayloadDataType { private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = true; diff --git a/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts b/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts index 4e49db609..77dde1333 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/static_bytes.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash'; import { DataTypeFactory, PayloadDataType } from '../abstract_data_types'; import { RawCalldata } from '../calldata'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; export class StaticBytes extends PayloadDataType { private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = true; @@ -46,7 +46,7 @@ export class StaticBytes extends PayloadDataType { if (valueBuf.byteLength > this._width) { throw new Error( `Tried to assign ${value} (${ - valueBuf.byteLength + valueBuf.byteLength } bytes), which exceeds max bytes that can be stored in a ${this.getSignature()}`, ); } else if (value.length % 2 !== 0) { 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 c0bde8649..47ad7cb97 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/string.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/string.ts @@ -5,7 +5,7 @@ import * as _ from 'lodash'; import { DataTypeFactory, PayloadDataType } from '../abstract_data_types'; import { RawCalldata } from '../calldata'; -import * as Constants from '../constants'; +import * as Constants from '../utils/constants'; export class String extends PayloadDataType { private static readonly _SIZE_KNOWN_AT_COMPILE_TIME: boolean = false; diff --git a/packages/utils/src/abi_encoder/utils/constants.ts b/packages/utils/src/abi_encoder/utils/constants.ts new file mode 100644 index 000000000..3d85fbdb8 --- /dev/null +++ b/packages/utils/src/abi_encoder/utils/constants.ts @@ -0,0 +1,8 @@ +export const EVM_WORD_WIDTH_IN_BYTES = 32; +export const EVM_WORD_WIDTH_IN_BITS = 256; +export const HEX_BASE = 16; +export const DEC_BASE = 10; +export const BIN_BASE = 2; +export const HEX_SELECTOR_LENGTH_IN_CHARS = 10; +export const HEX_SELECTOR_LENGTH_IN_BYTES = 4; +export const HEX_SELECTOR_BYTE_OFFSET_IN_CALLDATA = 0; -- cgit v1.2.3