aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/abi_encoder/calldata/calldata_block.ts
diff options
context:
space:
mode:
authorGreg Hysen <greg.hysen@gmail.com>2018-11-21 05:24:45 +0800
committerGreg Hysen <greg.hysen@gmail.com>2018-11-29 08:38:11 +0800
commitaed8b083b587e7b420ac6129b04004dea95c3f3a (patch)
treef6eacabc4061d6f616b85886a5f02d3149e16537 /packages/utils/src/abi_encoder/calldata/calldata_block.ts
parente6ab6f38bacdec90c960ff1db4781d161b1f4103 (diff)
downloaddexon-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/calldata_block.ts')
-rw-r--r--packages/utils/src/abi_encoder/calldata/calldata_block.ts77
1 files changed, 77 insertions, 0 deletions
diff --git a/packages/utils/src/abi_encoder/calldata/calldata_block.ts b/packages/utils/src/abi_encoder/calldata/calldata_block.ts
new file mode 100644
index 000000000..35bd994e5
--- /dev/null
+++ b/packages/utils/src/abi_encoder/calldata/calldata_block.ts
@@ -0,0 +1,77 @@
+import * as ethUtil from 'ethereumjs-util';
+
+export abstract class CalldataBlock {
+ private readonly _signature: string;
+ private readonly _parentName: string;
+ private _name: string;
+ private _offsetInBytes: number;
+ private _headerSizeInBytes: number;
+ private _bodySizeInBytes: number;
+
+ constructor(
+ name: string,
+ signature: string,
+ parentName: string,
+ headerSizeInBytes: number,
+ bodySizeInBytes: number,
+ ) {
+ this._name = name;
+ this._signature = signature;
+ this._parentName = parentName;
+ this._offsetInBytes = 0;
+ this._headerSizeInBytes = headerSizeInBytes;
+ this._bodySizeInBytes = bodySizeInBytes;
+ }
+
+ protected _setHeaderSize(headerSizeInBytes: number): void {
+ this._headerSizeInBytes = headerSizeInBytes;
+ }
+
+ protected _setBodySize(bodySizeInBytes: number): void {
+ this._bodySizeInBytes = bodySizeInBytes;
+ }
+
+ protected _setName(name: string): void {
+ this._name = name;
+ }
+
+ public getName(): string {
+ return this._name;
+ }
+
+ public getParentName(): string {
+ return this._parentName;
+ }
+
+ public getSignature(): string {
+ return this._signature;
+ }
+ public getHeaderSizeInBytes(): number {
+ return this._headerSizeInBytes;
+ }
+
+ public getBodySizeInBytes(): number {
+ return this._bodySizeInBytes;
+ }
+
+ public getSizeInBytes(): number {
+ return this.getHeaderSizeInBytes() + this.getBodySizeInBytes();
+ }
+
+ public getOffsetInBytes(): number {
+ return this._offsetInBytes;
+ }
+
+ public setOffset(offsetInBytes: number): void {
+ this._offsetInBytes = offsetInBytes;
+ }
+
+ public computeHash(): Buffer {
+ const rawData = this.getRawData();
+ const hash = ethUtil.sha3(rawData);
+ return hash;
+ }
+
+ public abstract toBuffer(): Buffer;
+ public abstract getRawData(): Buffer;
+}