diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-26 10:24:46 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:11 +0800 |
commit | 9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0 (patch) | |
tree | 1978be0aa6086aeba0337d37dae01e26871278f9 /packages/utils/src/abi_encoder/calldata/raw_calldata.ts | |
parent | bb4d02e413119132f283ee17549cf5e1732d75b5 (diff) | |
download | dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar.gz dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar.bz2 dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar.lz dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar.xz dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.tar.zst dexon-sol-tools-9a51af46ee4a35b3d1ce2fcdc6f561aa68307cf0.zip |
Payload -> Blob, Dependent -> Pointer, Member -> Set
Diffstat (limited to 'packages/utils/src/abi_encoder/calldata/raw_calldata.ts')
-rw-r--r-- | packages/utils/src/abi_encoder/calldata/raw_calldata.ts | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/packages/utils/src/abi_encoder/calldata/raw_calldata.ts b/packages/utils/src/abi_encoder/calldata/raw_calldata.ts index 9e72bbd62..b13cbdfd9 100644 --- a/packages/utils/src/abi_encoder/calldata/raw_calldata.ts +++ b/packages/utils/src/abi_encoder/calldata/raw_calldata.ts @@ -8,26 +8,25 @@ export class RawCalldata { private readonly _value: Buffer; private readonly _selector: string; private readonly _scopes: Queue<number>; - private _offset: number; // tracks current offset into raw calldata; used for parsing + private _offset: number; - constructor(value: string | Buffer, hasSelectorPrefix: boolean = true) { + public constructor(value: string | Buffer, hasSelector: boolean = true) { + // Sanity check if (typeof value === 'string' && !value.startsWith('0x')) { throw new Error(`Expected raw calldata to start with '0x'`); } - const valueBuf = ethUtil.toBuffer(value); - if (hasSelectorPrefix) { - this._selector = ethUtil.bufferToHex( - valueBuf.slice(Constants.HEX_SELECTOR_BYTE_OFFSET_IN_CALLDATA, Constants.HEX_SELECTOR_LENGTH_IN_BYTES), - ); - this._value = valueBuf.slice(Constants.HEX_SELECTOR_LENGTH_IN_BYTES); // disregard selector - } else { - this._selector = '0x'; - this._value = valueBuf; - } - + // Construct initial values + this._value = ethUtil.toBuffer(value); + this._selector = '0x'; this._scopes = new Queue<number>(); this._scopes.pushBack(RawCalldata._INITIAL_OFFSET); this._offset = RawCalldata._INITIAL_OFFSET; + // If there's a selector then slice it + if (hasSelector) { + const selectorBuf = this._value.slice(Constants.HEX_SELECTOR_LENGTH_IN_BYTES); + this._value = this._value.slice(Constants.HEX_SELECTOR_LENGTH_IN_BYTES); + this._selector = ethUtil.bufferToHex(selectorBuf); + } } public popBytes(lengthInBytes: number): Buffer { |