aboutsummaryrefslogtreecommitdiffstats
path: root/packages/utils/src/abi_encoder/calldata/calldata_block.ts
blob: 35bd994e53f63ee0a23c8fe0c264a18109a9a5d2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;
}