diff options
Diffstat (limited to 'packages/utils')
19 files changed, 46 insertions, 43 deletions
diff --git a/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts b/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts index 10e5c2540..13cc87e2a 100644 --- a/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts +++ b/packages/utils/src/abi_encoder/abstract_data_types/data_type.ts @@ -1,7 +1,9 @@ import { DataItem } from 'ethereum-types'; import * as _ from 'lodash'; -import { Calldata, CalldataBlock, RawCalldata } from '../calldata'; +import { Calldata } from '../calldata/calldata'; +import { CalldataBlock } from '../calldata/calldata_block'; +import { RawCalldata } from '../calldata/raw_calldata'; import { constants } from '../utils/constants'; import { DecodingRules, EncodingRules } from '../utils/rules'; diff --git a/packages/utils/src/abi_encoder/abstract_data_types/interfaces.ts b/packages/utils/src/abi_encoder/abstract_data_types/interfaces.ts index bd4d2effd..2f2f60871 100644 --- a/packages/utils/src/abi_encoder/abstract_data_types/interfaces.ts +++ b/packages/utils/src/abi_encoder/abstract_data_types/interfaces.ts @@ -1,6 +1,6 @@ import { DataItem } from 'ethereum-types'; -import { RawCalldata } from '../calldata'; +import { RawCalldata } from '../calldata/raw_calldata'; import { DataType } from './data_type'; diff --git a/packages/utils/src/abi_encoder/abstract_data_types/types/blob.ts b/packages/utils/src/abi_encoder/abstract_data_types/types/blob.ts index cd2119673..a091e55b9 100644 --- a/packages/utils/src/abi_encoder/abstract_data_types/types/blob.ts +++ b/packages/utils/src/abi_encoder/abstract_data_types/types/blob.ts @@ -1,7 +1,9 @@ import { DataItem } from 'ethereum-types'; import * as _ from 'lodash'; -import { CalldataBlock, CalldataBlocks, RawCalldata } from '../../calldata'; +import { BlobCalldataBlock } from '../../calldata/blocks/blob'; +import { CalldataBlock } from '../../calldata/calldata_block'; +import { RawCalldata } from '../../calldata/raw_calldata'; import { DecodingRules } from '../../utils/rules'; import { DataType } from '../data_type'; @@ -15,12 +17,12 @@ export abstract class AbstractBlobDataType extends DataType { this._sizeKnownAtCompileTime = sizeKnownAtCompileTime; } - public generateCalldataBlock(value: any, parentBlock?: CalldataBlock): CalldataBlocks.Blob { + public generateCalldataBlock(value: any, parentBlock?: CalldataBlock): BlobCalldataBlock { const encodedValue = this.encodeValue(value); const name = this.getDataItem().name; const signature = this.getSignature(); const parentName = _.isUndefined(parentBlock) ? '' : parentBlock.getName(); - const block = new CalldataBlocks.Blob(name, signature, parentName, encodedValue); + const block = new BlobCalldataBlock(name, signature, parentName, encodedValue); return block; } diff --git a/packages/utils/src/abi_encoder/abstract_data_types/types/pointer.ts b/packages/utils/src/abi_encoder/abstract_data_types/types/pointer.ts index b6a6a7613..0f3c55280 100644 --- a/packages/utils/src/abi_encoder/abstract_data_types/types/pointer.ts +++ b/packages/utils/src/abi_encoder/abstract_data_types/types/pointer.ts @@ -2,7 +2,9 @@ import { DataItem } from 'ethereum-types'; import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; -import { CalldataBlock, CalldataBlocks, RawCalldata } from '../../calldata'; +import { PointerCalldataBlock } from '../../calldata/blocks/pointer'; +import { CalldataBlock } from '../../calldata/calldata_block'; +import { RawCalldata } from '../../calldata/raw_calldata'; import { constants } from '../../utils/constants'; import { DecodingRules } from '../../utils/rules'; @@ -19,7 +21,7 @@ export abstract class AbstractPointerDataType extends DataType { this._parent = parent; } - public generateCalldataBlock(value: any, parentBlock?: CalldataBlock): CalldataBlocks.Pointer { + public generateCalldataBlock(value: any, parentBlock?: CalldataBlock): PointerCalldataBlock { if (_.isUndefined(parentBlock)) { throw new Error(`DependentDataType requires a parent block to generate its block`); } @@ -27,7 +29,7 @@ export abstract class AbstractPointerDataType extends DataType { const name = this.getDataItem().name; const signature = this.getSignature(); const parentName = parentBlock.getName(); - const block = new CalldataBlocks.Pointer(name, signature, parentName, destinationBlock, parentBlock); + const block = new PointerCalldataBlock(name, signature, parentName, destinationBlock, parentBlock); return block; } diff --git a/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts b/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts index 4c8bb7b1a..bbe29eff0 100644 --- a/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts +++ b/packages/utils/src/abi_encoder/abstract_data_types/types/set.ts @@ -3,7 +3,9 @@ import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; import { BigNumber } from '../../../configured_bignumber'; -import { CalldataBlock, CalldataBlocks, RawCalldata } from '../../calldata'; +import { SetCalldataBlock } from '../../calldata/blocks/set'; +import { CalldataBlock } from '../../calldata/calldata_block'; +import { RawCalldata } from '../../calldata/raw_calldata'; import { constants } from '../../utils/constants'; import { DecodingRules } from '../../utils/rules'; @@ -39,7 +41,7 @@ export abstract class AbstractSetDataType extends DataType { } } - public generateCalldataBlock(value: any[] | object, parentBlock?: CalldataBlock): CalldataBlocks.Set { + public generateCalldataBlock(value: any[] | object, parentBlock?: CalldataBlock): SetCalldataBlock { const block = value instanceof Array ? this._generateCalldataBlockFromArray(value, parentBlock) @@ -94,7 +96,7 @@ export abstract class AbstractSetDataType extends DataType { return isStatic; } - protected _generateCalldataBlockFromArray(value: any[], parentBlock?: CalldataBlock): CalldataBlocks.Set { + protected _generateCalldataBlockFromArray(value: any[], parentBlock?: CalldataBlock): SetCalldataBlock { // Sanity check: if the set has a defined length then `value` must have the same length. if (!_.isUndefined(this._arrayLength) && value.length !== this._arrayLength) { throw new Error( @@ -105,7 +107,7 @@ export abstract class AbstractSetDataType extends DataType { } // Create a new calldata block for this set. const parentName = _.isUndefined(parentBlock) ? '' : parentBlock.getName(); - const block: CalldataBlocks.Set = new CalldataBlocks.Set( + const block = new SetCalldataBlock( this.getDataItem().name, this.getSignature(), parentName, @@ -130,10 +132,10 @@ export abstract class AbstractSetDataType extends DataType { return block; } - protected _generateCalldataBlockFromObject(obj: object, parentBlock?: CalldataBlock): CalldataBlocks.Set { + protected _generateCalldataBlockFromObject(obj: object, parentBlock?: CalldataBlock): SetCalldataBlock { // Create a new calldata block for this set. const parentName = _.isUndefined(parentBlock) ? '' : parentBlock.getName(); - const block: CalldataBlocks.Set = new CalldataBlocks.Set( + const block = new SetCalldataBlock( this.getDataItem().name, this.getSignature(), parentName, diff --git a/packages/utils/src/abi_encoder/calldata/blocks/blob.ts b/packages/utils/src/abi_encoder/calldata/blocks/blob.ts index 210ef6420..219ea6c61 100644 --- a/packages/utils/src/abi_encoder/calldata/blocks/blob.ts +++ b/packages/utils/src/abi_encoder/calldata/blocks/blob.ts @@ -1,6 +1,6 @@ import { CalldataBlock } from '../calldata_block'; -export class Blob extends CalldataBlock { +export class BlobCalldataBlock extends CalldataBlock { private readonly _blob: Buffer; constructor(name: string, signature: string, parentName: string, blob: Buffer) { diff --git a/packages/utils/src/abi_encoder/calldata/blocks/index.ts b/packages/utils/src/abi_encoder/calldata/blocks/index.ts deleted file mode 100644 index 958582dae..000000000 --- a/packages/utils/src/abi_encoder/calldata/blocks/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './blob'; -export * from './pointer'; -export * from './set'; diff --git a/packages/utils/src/abi_encoder/calldata/blocks/pointer.ts b/packages/utils/src/abi_encoder/calldata/blocks/pointer.ts index 1daf33f7e..c706fe908 100644 --- a/packages/utils/src/abi_encoder/calldata/blocks/pointer.ts +++ b/packages/utils/src/abi_encoder/calldata/blocks/pointer.ts @@ -5,7 +5,7 @@ import { constants } from '../../utils/constants'; import { CalldataBlock } from '../calldata_block'; -export class Pointer extends CalldataBlock { +export class PointerCalldataBlock extends CalldataBlock { public static readonly RAW_DATA_START = new Buffer('<'); public static readonly RAW_DATA_END = new Buffer('>'); private static readonly _DEPENDENT_PAYLOAD_SIZE_IN_BYTES = 32; @@ -15,8 +15,8 @@ export class Pointer extends CalldataBlock { private _aliasFor: CalldataBlock | undefined; constructor(name: string, signature: string, parentName: string, dependency: CalldataBlock, parent: CalldataBlock) { - const headerSizeInBytes = Pointer._EMPTY_HEADER_SIZE; - const bodySizeInBytes = Pointer._DEPENDENT_PAYLOAD_SIZE_IN_BYTES; + const headerSizeInBytes = PointerCalldataBlock._EMPTY_HEADER_SIZE; + const bodySizeInBytes = PointerCalldataBlock._DEPENDENT_PAYLOAD_SIZE_IN_BYTES; super(name, signature, parentName, headerSizeInBytes, bodySizeInBytes); this._parent = parent; this._dependency = dependency; @@ -51,9 +51,9 @@ export class Pointer extends CalldataBlock { public getRawData(): Buffer { const dependencyRawData = this._dependency.getRawData(); const rawDataComponents: Buffer[] = []; - rawDataComponents.push(Pointer.RAW_DATA_START); + rawDataComponents.push(PointerCalldataBlock.RAW_DATA_START); rawDataComponents.push(dependencyRawData); - rawDataComponents.push(Pointer.RAW_DATA_END); + rawDataComponents.push(PointerCalldataBlock.RAW_DATA_END); const rawData = Buffer.concat(rawDataComponents); return rawData; } diff --git a/packages/utils/src/abi_encoder/calldata/blocks/set.ts b/packages/utils/src/abi_encoder/calldata/blocks/set.ts index 81455b364..d1abc4986 100644 --- a/packages/utils/src/abi_encoder/calldata/blocks/set.ts +++ b/packages/utils/src/abi_encoder/calldata/blocks/set.ts @@ -2,7 +2,7 @@ import * as _ from 'lodash'; import { CalldataBlock } from '../calldata_block'; -export class Set extends CalldataBlock { +export class SetCalldataBlock extends CalldataBlock { private _header: Buffer | undefined; private _members: CalldataBlock[]; diff --git a/packages/utils/src/abi_encoder/calldata/calldata.ts b/packages/utils/src/abi_encoder/calldata/calldata.ts index e5858b524..5f3eee94a 100644 --- a/packages/utils/src/abi_encoder/calldata/calldata.ts +++ b/packages/utils/src/abi_encoder/calldata/calldata.ts @@ -4,7 +4,8 @@ import * as _ from 'lodash'; import { constants } from '../utils/constants'; import { EncodingRules } from '../utils/rules'; -import * as CalldataBlocks from './blocks'; +import { PointerCalldataBlock } from './blocks/pointer'; +import { SetCalldataBlock } from './blocks/set'; import { CalldataBlock } from './calldata_block'; import { CalldataIterator, ReverseCalldataIterator } from './iterator'; @@ -112,7 +113,7 @@ export class Calldata { for (const block of iterator) { // If a block is a pointer and its value has already been observed, then update // the pointer to resolve to the existing value. - if (block instanceof CalldataBlocks.Pointer) { + if (block instanceof PointerCalldataBlock) { const dependencyBlockHashBuf = block.getDependency().computeHash(); const dependencyBlockHash = ethUtil.bufferToHex(dependencyBlockHashBuf); if (dependencyBlockHash in blocksByHash) { @@ -214,7 +215,7 @@ export class Calldata { ), ) .padEnd(valuePadding); - if (block instanceof CalldataBlocks.Set) { + if (block instanceof SetCalldataBlock) { nameStr = `### ${prettyName.padEnd(namePadding)}`; lineStr = `\n${offsetStr}${valueStr}${nameStr}`; } else { diff --git a/packages/utils/src/abi_encoder/calldata/index.ts b/packages/utils/src/abi_encoder/calldata/index.ts deleted file mode 100644 index 2ef75e8d0..000000000 --- a/packages/utils/src/abi_encoder/calldata/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './calldata'; -export * from './calldata_block'; -export * from './raw_calldata'; -import * as CalldataBlocks from './blocks'; -export { CalldataBlocks }; diff --git a/packages/utils/src/abi_encoder/calldata/iterator.ts b/packages/utils/src/abi_encoder/calldata/iterator.ts index 5307f7944..333b32b4f 100644 --- a/packages/utils/src/abi_encoder/calldata/iterator.ts +++ b/packages/utils/src/abi_encoder/calldata/iterator.ts @@ -3,7 +3,9 @@ import * as _ from 'lodash'; import { Queue } from '../utils/queue'; -import * as CalldataBlocks from './blocks'; +import { BlobCalldataBlock } from './blocks/blob'; +import { PointerCalldataBlock } from './blocks/pointer'; +import { SetCalldataBlock } from './blocks/set'; import { CalldataBlock } from './calldata_block'; /** @@ -42,7 +44,7 @@ abstract class BaseIterator implements Iterable<CalldataBlock> { private static _createQueue(block: CalldataBlock): Queue<CalldataBlock> { const queue = new Queue<CalldataBlock>(); // Base case - if (!(block instanceof CalldataBlocks.Set)) { + if (!(block instanceof SetCalldataBlock)) { queue.pushBack(block); return queue; } @@ -55,7 +57,7 @@ abstract class BaseIterator implements Iterable<CalldataBlock> { _.each(set.getMembers(), (member: CalldataBlock) => { // Traverse child if it is a unique pointer. // A pointer that is an alias for another pointer is ignored. - if (member instanceof CalldataBlocks.Pointer && _.isUndefined(member.getAlias())) { + if (member instanceof PointerCalldataBlock && _.isUndefined(member.getAlias())) { const dependency = member.getDependency(); queue.mergeBack(BaseIterator._createQueue(dependency)); } @@ -82,7 +84,7 @@ abstract class BaseIterator implements Iterable<CalldataBlock> { } return { done: true, - value: new CalldataBlocks.Blob('', '', '', new Buffer('')), + value: new BlobCalldataBlock('', '', '', new Buffer('')), }; }, }; 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 17363b5f3..88846b1fa 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/address.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/address.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash'; import { DataTypeFactory } from '../abstract_data_types/interfaces'; import { AbstractBlobDataType } from '../abstract_data_types/types/blob'; -import { RawCalldata } from '../calldata'; +import { RawCalldata } from '../calldata/raw_calldata'; import { constants } from '../utils/constants'; export class AddressDataType extends AbstractBlobDataType { 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 778a01d8a..d713d5a94 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/bool.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/bool.ts @@ -5,7 +5,7 @@ import * as _ from 'lodash'; import { BigNumber } from '../../configured_bignumber'; import { DataTypeFactory } from '../abstract_data_types/interfaces'; import { AbstractBlobDataType } from '../abstract_data_types/types/blob'; -import { RawCalldata } from '../calldata'; +import { RawCalldata } from '../calldata/raw_calldata'; import { constants } from '../utils/constants'; export class BoolDataType extends AbstractBlobDataType { 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 ac8e2b716..5277efd6c 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 @@ -4,7 +4,7 @@ import * as _ from 'lodash'; import { DataTypeFactory } from '../abstract_data_types/interfaces'; import { AbstractBlobDataType } from '../abstract_data_types/types/blob'; -import { RawCalldata } from '../calldata'; +import { RawCalldata } from '../calldata/raw_calldata'; import { constants } from '../utils/constants'; export class DynamicBytesDataType extends AbstractBlobDataType { 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 6b5c3bf78..f1dcf5ea1 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/int.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/int.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash'; import { BigNumber } from '../../configured_bignumber'; import { DataTypeFactory } from '../abstract_data_types/interfaces'; import { AbstractBlobDataType } from '../abstract_data_types/types/blob'; -import { RawCalldata } from '../calldata'; +import { RawCalldata } from '../calldata/raw_calldata'; import { constants } from '../utils/constants'; import * as EncoderMath from '../utils/math'; 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 28584d445..2e371c505 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 } from '../abstract_data_types/interfaces'; import { AbstractBlobDataType } from '../abstract_data_types/types/blob'; -import { RawCalldata } from '../calldata'; +import { RawCalldata } from '../calldata/raw_calldata'; import { constants } from '../utils/constants'; export class StaticBytesDataType extends AbstractBlobDataType { 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 7b6af747b..91a72ad3f 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/string.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/string.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash'; import { DataTypeFactory } from '../abstract_data_types/interfaces'; import { AbstractBlobDataType } from '../abstract_data_types/types/blob'; -import { RawCalldata } from '../calldata'; +import { RawCalldata } from '../calldata/raw_calldata'; import { constants } from '../utils/constants'; export class StringDataType extends AbstractBlobDataType { 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 45cb366f7..5180f0cf3 100644 --- a/packages/utils/src/abi_encoder/evm_data_types/uint.ts +++ b/packages/utils/src/abi_encoder/evm_data_types/uint.ts @@ -4,7 +4,7 @@ import * as _ from 'lodash'; import { BigNumber } from '../../configured_bignumber'; import { DataTypeFactory } from '../abstract_data_types/interfaces'; import { AbstractBlobDataType } from '../abstract_data_types/types/blob'; -import { RawCalldata } from '../calldata'; +import { RawCalldata } from '../calldata/raw_calldata'; import { constants } from '../utils/constants'; import * as EncoderMath from '../utils/math'; |