diff options
author | Greg Hysen <greg.hysen@gmail.com> | 2018-11-21 05:24:45 +0800 |
---|---|---|
committer | Greg Hysen <greg.hysen@gmail.com> | 2018-11-29 08:38:11 +0800 |
commit | aed8b083b587e7b420ac6129b04004dea95c3f3a (patch) | |
tree | f6eacabc4061d6f616b85886a5f02d3149e16537 /packages/utils/src/abi_encoder/calldata/member_calldata_block.ts | |
parent | e6ab6f38bacdec90c960ff1db4781d161b1f4103 (diff) | |
download | dexon-sol-tools-aed8b083b587e7b420ac6129b04004dea95c3f3a.tar dexon-sol-tools-aed8b083b587e7b420ac6129b04004dea95c3f3a.tar.gz dexon-sol-tools-aed8b083b587e7b420ac6129b04004dea95c3f3a.tar.bz2 dexon-sol-tools-aed8b083b587e7b420ac6129b04004dea95c3f3a.tar.lz dexon-sol-tools-aed8b083b587e7b420ac6129b04004dea95c3f3a.tar.xz dexon-sol-tools-aed8b083b587e7b420ac6129b04004dea95c3f3a.tar.zst dexon-sol-tools-aed8b083b587e7b420ac6129b04004dea95c3f3a.zip |
Split Calldata into multiple files - 1 class per file
Diffstat (limited to 'packages/utils/src/abi_encoder/calldata/member_calldata_block.ts')
-rw-r--r-- | packages/utils/src/abi_encoder/calldata/member_calldata_block.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/packages/utils/src/abi_encoder/calldata/member_calldata_block.ts b/packages/utils/src/abi_encoder/calldata/member_calldata_block.ts new file mode 100644 index 000000000..e9bcb2f34 --- /dev/null +++ b/packages/utils/src/abi_encoder/calldata/member_calldata_block.ts @@ -0,0 +1,48 @@ +import * as _ from 'lodash'; + +import { CalldataBlock } from './calldata_block'; + +export class MemberCalldataBlock extends CalldataBlock { + private _header: Buffer | undefined; + private _members: CalldataBlock[]; + + constructor(name: string, signature: string, parentName: string) { + super(name, signature, parentName, 0, 0); + this._members = []; + this._header = undefined; + } + + public getRawData(): Buffer { + const rawDataComponents: Buffer[] = []; + if (this._header !== undefined) { + rawDataComponents.push(this._header); + } + _.each(this._members, (member: CalldataBlock) => { + const memberBuffer = member.getRawData(); + rawDataComponents.push(memberBuffer); + }); + + const rawData = Buffer.concat(rawDataComponents); + return rawData; + } + + public setMembers(members: CalldataBlock[]): void { + this._members = members; + } + + public setHeader(header: Buffer): void { + this._setHeaderSize(header.byteLength); + this._header = header; + } + + public toBuffer(): Buffer { + if (this._header !== undefined) { + return this._header; + } + return new Buffer(''); + } + + public getMembers(): CalldataBlock[] { + return this._members; + } +}
\ No newline at end of file |