@alephium/web3 0.36.1 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +6 -1
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/api/types.d.ts +1 -1
- package/dist/src/codec/array-codec.d.ts +17 -0
- package/dist/src/codec/array-codec.js +59 -0
- package/dist/src/codec/asset-output-codec.d.ts +27 -0
- package/dist/src/codec/asset-output-codec.js +135 -0
- package/dist/src/codec/bigint-codec.d.ts +5 -0
- package/dist/src/codec/bigint-codec.js +86 -0
- package/dist/src/codec/bytestring-codec.d.ts +16 -0
- package/dist/src/codec/bytestring-codec.js +50 -0
- package/dist/src/codec/codec.d.ts +8 -0
- package/dist/src/codec/codec.js +9 -0
- package/dist/src/codec/compact-int-codec.d.ts +51 -0
- package/dist/src/codec/compact-int-codec.js +300 -0
- package/dist/src/codec/contract-codec.d.ts +23 -0
- package/dist/src/codec/contract-codec.js +81 -0
- package/dist/src/codec/contract-output-codec.d.ts +21 -0
- package/dist/src/codec/contract-output-codec.js +82 -0
- package/dist/src/codec/contract-output-ref-codec.d.ts +15 -0
- package/dist/src/codec/contract-output-ref-codec.js +38 -0
- package/dist/src/codec/either-codec.d.ts +17 -0
- package/dist/src/codec/either-codec.js +67 -0
- package/dist/src/codec/hash.d.ts +4 -0
- package/dist/src/codec/hash.js +23 -0
- package/dist/src/codec/index.d.ts +23 -0
- package/dist/src/codec/index.js +69 -0
- package/dist/src/codec/input-codec.d.ts +22 -0
- package/dist/src/codec/input-codec.js +71 -0
- package/dist/src/codec/instr-codec.d.ts +230 -0
- package/dist/src/codec/instr-codec.js +471 -0
- package/dist/src/codec/lockup-script-codec.d.ts +28 -0
- package/dist/src/codec/lockup-script-codec.js +80 -0
- package/dist/src/codec/long-codec.d.ts +9 -0
- package/dist/src/codec/long-codec.js +56 -0
- package/dist/src/codec/method-codec.d.ts +31 -0
- package/dist/src/codec/method-codec.js +78 -0
- package/dist/src/codec/option-codec.d.ts +15 -0
- package/dist/src/codec/option-codec.js +55 -0
- package/dist/src/codec/output-codec.d.ts +7 -0
- package/dist/src/codec/output-codec.js +26 -0
- package/dist/src/codec/script-codec.d.ts +16 -0
- package/dist/src/codec/script-codec.js +41 -0
- package/dist/src/codec/signature-codec.d.ts +14 -0
- package/dist/src/codec/signature-codec.js +19 -0
- package/dist/src/codec/signed-int-codec.d.ts +9 -0
- package/dist/src/codec/signed-int-codec.js +39 -0
- package/dist/src/codec/token-codec.d.ts +16 -0
- package/dist/src/codec/token-codec.js +46 -0
- package/dist/src/codec/transaction-codec.d.ts +27 -0
- package/dist/src/codec/transaction-codec.js +128 -0
- package/dist/src/codec/unlock-script-codec.d.ts +40 -0
- package/dist/src/codec/unlock-script-codec.js +170 -0
- package/dist/src/codec/unsigned-tx-codec.d.ts +30 -0
- package/dist/src/codec/unsigned-tx-codec.js +103 -0
- package/dist/src/contract/contract.d.ts +14 -8
- package/dist/src/contract/contract.js +205 -22
- package/dist/src/contract/ralph.d.ts +16 -0
- package/dist/src/contract/ralph.js +127 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +2 -1
- package/package.json +5 -4
- package/src/api/api-alephium.ts +7 -1
- package/src/api/types.ts +1 -1
- package/src/codec/array-codec.ts +63 -0
- package/src/codec/asset-output-codec.ts +149 -0
- package/src/codec/bigint-codec.ts +92 -0
- package/src/codec/bytestring-codec.ts +56 -0
- package/src/codec/codec.ts +31 -0
- package/src/codec/compact-int-codec.ts +316 -0
- package/src/codec/contract-codec.ts +95 -0
- package/src/codec/contract-output-codec.ts +95 -0
- package/src/codec/contract-output-ref-codec.ts +42 -0
- package/src/codec/either-codec.ts +74 -0
- package/src/codec/hash.ts +35 -0
- package/src/codec/index.ts +41 -0
- package/src/codec/input-codec.ts +81 -0
- package/src/codec/instr-codec.ts +479 -0
- package/src/codec/lockup-script-codec.ts +99 -0
- package/src/codec/long-codec.ts +59 -0
- package/src/codec/method-codec.ts +97 -0
- package/src/codec/option-codec.ts +60 -0
- package/src/codec/output-codec.ts +26 -0
- package/src/codec/script-codec.ts +45 -0
- package/src/codec/signature-codec.ts +40 -0
- package/src/codec/signed-int-codec.ts +37 -0
- package/src/codec/token-codec.ts +51 -0
- package/src/codec/transaction-codec.ts +147 -0
- package/src/codec/unlock-script-codec.ts +194 -0
- package/src/codec/unsigned-tx-codec.ts +124 -0
- package/src/contract/contract.ts +299 -23
- package/src/contract/ralph.ts +140 -2
- package/src/index.ts +1 -1
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unlockScriptCodec = exports.UnlockScriptCodec = exports.P2SHCodec = void 0;
|
|
4
|
+
/*
|
|
5
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
6
|
+
This file is part of the alephium project.
|
|
7
|
+
|
|
8
|
+
The library is free software: you can redistribute it and/or modify
|
|
9
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
(at your option) any later version.
|
|
12
|
+
|
|
13
|
+
The library is distributed in the hope that it will be useful,
|
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
GNU Lesser General Public License for more details.
|
|
17
|
+
|
|
18
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
19
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
const buffer_1 = require("buffer/");
|
|
22
|
+
const binary_parser_1 = require("binary-parser");
|
|
23
|
+
const array_codec_1 = require("./array-codec");
|
|
24
|
+
const compact_int_codec_1 = require("./compact-int-codec");
|
|
25
|
+
const script_codec_1 = require("./script-codec");
|
|
26
|
+
const bytestring_codec_1 = require("./bytestring-codec");
|
|
27
|
+
const lockup_script_codec_1 = require("./lockup-script-codec");
|
|
28
|
+
class P2PKHCodec {
|
|
29
|
+
constructor() {
|
|
30
|
+
this.parser = binary_parser_1.Parser.start().buffer('publicKey', { length: 33 });
|
|
31
|
+
}
|
|
32
|
+
encode(input) {
|
|
33
|
+
return input.publicKey;
|
|
34
|
+
}
|
|
35
|
+
decode(input) {
|
|
36
|
+
return this.parser.parse(input);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const p2pkhCodec = new P2PKHCodec();
|
|
40
|
+
class P2MPKHCodec {
|
|
41
|
+
constructor() {
|
|
42
|
+
this.parser = binary_parser_1.Parser.start().nest('publicKeys', {
|
|
43
|
+
type: array_codec_1.ArrayCodec.arrayParser(binary_parser_1.Parser.start()
|
|
44
|
+
.nest('publicKey', { type: p2pkhCodec.parser })
|
|
45
|
+
.nest('index', { type: compact_int_codec_1.compactUnsignedIntCodec.parser }))
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
encode(input) {
|
|
49
|
+
return buffer_1.Buffer.concat([
|
|
50
|
+
buffer_1.Buffer.from(compact_int_codec_1.compactUnsignedIntCodec.encode(input.publicKeys.length)),
|
|
51
|
+
...input.publicKeys.value.map((v) => {
|
|
52
|
+
return buffer_1.Buffer.concat([v.publicKey.publicKey, buffer_1.Buffer.from(compact_int_codec_1.compactUnsignedIntCodec.encode(v.index))]);
|
|
53
|
+
})
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
decode(input) {
|
|
57
|
+
return this.parser.parse(input);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const p2mpkhCodec = new P2MPKHCodec();
|
|
61
|
+
class ValCodec {
|
|
62
|
+
constructor() {
|
|
63
|
+
this.parser = binary_parser_1.Parser.start()
|
|
64
|
+
.int8('type')
|
|
65
|
+
.choice('val', {
|
|
66
|
+
tag: 'type',
|
|
67
|
+
choices: {
|
|
68
|
+
0x00: new binary_parser_1.Parser().uint8('value'),
|
|
69
|
+
0x01: compact_int_codec_1.compactSignedIntCodec.parser,
|
|
70
|
+
0x02: compact_int_codec_1.compactUnsignedIntCodec.parser,
|
|
71
|
+
0x03: bytestring_codec_1.byteStringCodec.parser,
|
|
72
|
+
0x04: lockup_script_codec_1.lockupScriptCodec.parser // Address
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
encode(input) {
|
|
77
|
+
const valType = input.type;
|
|
78
|
+
if (valType === 0x00) {
|
|
79
|
+
// Boolean
|
|
80
|
+
return buffer_1.Buffer.from([valType, input.val]);
|
|
81
|
+
}
|
|
82
|
+
else if (valType === 0x01) {
|
|
83
|
+
// I256
|
|
84
|
+
return buffer_1.Buffer.from([valType, ...compact_int_codec_1.compactUnsignedIntCodec.encode(input.val)]);
|
|
85
|
+
}
|
|
86
|
+
else if (valType === 0x02) {
|
|
87
|
+
// U256
|
|
88
|
+
return buffer_1.Buffer.from([valType, ...compact_int_codec_1.compactUnsignedIntCodec.encode(input.val)]);
|
|
89
|
+
}
|
|
90
|
+
else if (valType === 0x03) {
|
|
91
|
+
// ByteVec
|
|
92
|
+
return buffer_1.Buffer.from([valType, ...bytestring_codec_1.byteStringCodec.encode(input.val)]);
|
|
93
|
+
}
|
|
94
|
+
else if (valType === 0x04) {
|
|
95
|
+
// Address
|
|
96
|
+
return buffer_1.Buffer.from([valType, ...lockup_script_codec_1.lockupScriptCodec.encode(input.val)]);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
throw new Error(`ValCodec: unsupported val type: ${valType}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
decode(input) {
|
|
103
|
+
return this.parser.parse(input);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const valCodec = new ValCodec();
|
|
107
|
+
const valsCodec = new array_codec_1.ArrayCodec(valCodec);
|
|
108
|
+
class P2SHCodec {
|
|
109
|
+
constructor() {
|
|
110
|
+
this.parser = binary_parser_1.Parser.start()
|
|
111
|
+
.nest('script', {
|
|
112
|
+
type: script_codec_1.scriptCodec.parser
|
|
113
|
+
})
|
|
114
|
+
.nest('params', {
|
|
115
|
+
type: valsCodec.parser
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
encode(input) {
|
|
119
|
+
return buffer_1.Buffer.concat([script_codec_1.scriptCodec.encode(input.script), valsCodec.encode(input.params.value)]);
|
|
120
|
+
}
|
|
121
|
+
decode(input) {
|
|
122
|
+
return this.parser.parse(input);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.P2SHCodec = P2SHCodec;
|
|
126
|
+
const p2shCodec = new P2SHCodec();
|
|
127
|
+
class UnlockScriptCodec {
|
|
128
|
+
constructor() {
|
|
129
|
+
this.parser = binary_parser_1.Parser.start()
|
|
130
|
+
.uint8('scriptType')
|
|
131
|
+
.choice('script', {
|
|
132
|
+
tag: 'scriptType',
|
|
133
|
+
choices: {
|
|
134
|
+
0: p2pkhCodec.parser,
|
|
135
|
+
1: p2mpkhCodec.parser,
|
|
136
|
+
2: p2shCodec.parser,
|
|
137
|
+
3: binary_parser_1.Parser.start() // TODO: SameAsPrevious, FIXME
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
encode(input) {
|
|
142
|
+
const scriptType = input.scriptType;
|
|
143
|
+
const inputUnLockScript = input.script;
|
|
144
|
+
const inputUnLockScriptType = buffer_1.Buffer.from([scriptType]);
|
|
145
|
+
if (scriptType === 0) {
|
|
146
|
+
// P2PKH
|
|
147
|
+
return buffer_1.Buffer.concat([inputUnLockScriptType, p2pkhCodec.encode(inputUnLockScript)]);
|
|
148
|
+
}
|
|
149
|
+
else if (scriptType === 1) {
|
|
150
|
+
// P2MPKH
|
|
151
|
+
return buffer_1.Buffer.concat([inputUnLockScriptType, p2mpkhCodec.encode(inputUnLockScript)]);
|
|
152
|
+
}
|
|
153
|
+
else if (scriptType === 2) {
|
|
154
|
+
// P2SH
|
|
155
|
+
return buffer_1.Buffer.concat([inputUnLockScriptType, p2shCodec.encode(input.script)]);
|
|
156
|
+
}
|
|
157
|
+
else if (scriptType === 3) {
|
|
158
|
+
// SameAsPrevious
|
|
159
|
+
return inputUnLockScriptType;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
throw new Error(`TODO: encode unlock script: ${scriptType}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
decode(input) {
|
|
166
|
+
return this.parser.parse(input);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
exports.UnlockScriptCodec = UnlockScriptCodec;
|
|
170
|
+
exports.unlockScriptCodec = new UnlockScriptCodec();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Buffer } from 'buffer/';
|
|
2
|
+
import { Parser } from 'binary-parser';
|
|
3
|
+
import { UnsignedTx as ApiUnsignedTx } from '../api/api-alephium';
|
|
4
|
+
import { Script } from './script-codec';
|
|
5
|
+
import { Option } from './option-codec';
|
|
6
|
+
import { DecodedCompactInt } from './compact-int-codec';
|
|
7
|
+
import { Input } from './input-codec';
|
|
8
|
+
import { AssetOutput } from './asset-output-codec';
|
|
9
|
+
import { DecodedArray } from './array-codec';
|
|
10
|
+
import { Codec } from './codec';
|
|
11
|
+
export interface UnsignedTx {
|
|
12
|
+
version: number;
|
|
13
|
+
networkId: number;
|
|
14
|
+
statefulScript: Option<Script>;
|
|
15
|
+
gasAmount: DecodedCompactInt;
|
|
16
|
+
gasPrice: DecodedCompactInt;
|
|
17
|
+
inputs: DecodedArray<Input>;
|
|
18
|
+
fixedOutputs: DecodedArray<AssetOutput>;
|
|
19
|
+
}
|
|
20
|
+
export declare class UnsignedTxCodec implements Codec<UnsignedTx> {
|
|
21
|
+
parser: Parser;
|
|
22
|
+
encode(decodedUnsignedTx: UnsignedTx): Buffer;
|
|
23
|
+
decode(input: Buffer): UnsignedTx;
|
|
24
|
+
encodeApiUnsignedTx(input: ApiUnsignedTx): Buffer;
|
|
25
|
+
decodeApiUnsignedTx(input: Buffer): ApiUnsignedTx;
|
|
26
|
+
static txId(unsignedTx: UnsignedTx): string;
|
|
27
|
+
static toApiUnsignedTx(unsigned: UnsignedTx): ApiUnsignedTx;
|
|
28
|
+
static fromApiUnsignedTx(unsignedTx: ApiUnsignedTx): UnsignedTx;
|
|
29
|
+
}
|
|
30
|
+
export declare const unsignedTxCodec: UnsignedTxCodec;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unsignedTxCodec = exports.UnsignedTxCodec = void 0;
|
|
4
|
+
/*
|
|
5
|
+
Copyright 2018 - 2022 The Alephium Authors
|
|
6
|
+
This file is part of the alephium project.
|
|
7
|
+
|
|
8
|
+
The library is free software: you can redistribute it and/or modify
|
|
9
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
(at your option) any later version.
|
|
12
|
+
|
|
13
|
+
The library is distributed in the hope that it will be useful,
|
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
GNU Lesser General Public License for more details.
|
|
17
|
+
|
|
18
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
19
|
+
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
const buffer_1 = require("buffer/");
|
|
22
|
+
const binary_parser_1 = require("binary-parser");
|
|
23
|
+
const utils_1 = require("../utils");
|
|
24
|
+
const script_codec_1 = require("./script-codec");
|
|
25
|
+
const compact_int_codec_1 = require("./compact-int-codec");
|
|
26
|
+
const input_codec_1 = require("./input-codec");
|
|
27
|
+
const asset_output_codec_1 = require("./asset-output-codec");
|
|
28
|
+
const hash_1 = require("./hash");
|
|
29
|
+
class UnsignedTxCodec {
|
|
30
|
+
constructor() {
|
|
31
|
+
this.parser = new binary_parser_1.Parser()
|
|
32
|
+
.uint8('version')
|
|
33
|
+
.uint8('networkId')
|
|
34
|
+
.nest('statefulScript', {
|
|
35
|
+
type: script_codec_1.statefulScriptCodecOpt.parser
|
|
36
|
+
})
|
|
37
|
+
.nest('gasAmount', {
|
|
38
|
+
type: compact_int_codec_1.compactSignedIntCodec.parser
|
|
39
|
+
})
|
|
40
|
+
.nest('gasPrice', {
|
|
41
|
+
type: compact_int_codec_1.compactUnsignedIntCodec.parser
|
|
42
|
+
})
|
|
43
|
+
.nest('inputs', {
|
|
44
|
+
type: input_codec_1.inputsCodec.parser
|
|
45
|
+
})
|
|
46
|
+
.nest('fixedOutputs', {
|
|
47
|
+
type: asset_output_codec_1.assetOutputsCodec.parser
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
encode(decodedUnsignedTx) {
|
|
51
|
+
return buffer_1.Buffer.concat([
|
|
52
|
+
buffer_1.Buffer.from([decodedUnsignedTx.version, decodedUnsignedTx.networkId]),
|
|
53
|
+
script_codec_1.statefulScriptCodecOpt.encode(decodedUnsignedTx.statefulScript),
|
|
54
|
+
compact_int_codec_1.compactSignedIntCodec.encode(decodedUnsignedTx.gasAmount),
|
|
55
|
+
compact_int_codec_1.compactUnsignedIntCodec.encode(decodedUnsignedTx.gasPrice),
|
|
56
|
+
input_codec_1.inputsCodec.encode(decodedUnsignedTx.inputs.value),
|
|
57
|
+
asset_output_codec_1.assetOutputsCodec.encode(decodedUnsignedTx.fixedOutputs.value)
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
decode(input) {
|
|
61
|
+
return this.parser.parse(input);
|
|
62
|
+
}
|
|
63
|
+
encodeApiUnsignedTx(input) {
|
|
64
|
+
const decoded = UnsignedTxCodec.fromApiUnsignedTx(input);
|
|
65
|
+
return this.encode(decoded);
|
|
66
|
+
}
|
|
67
|
+
decodeApiUnsignedTx(input) {
|
|
68
|
+
const decoded = this.parser.parse(input);
|
|
69
|
+
return UnsignedTxCodec.toApiUnsignedTx(decoded);
|
|
70
|
+
}
|
|
71
|
+
static txId(unsignedTx) {
|
|
72
|
+
return (0, utils_1.binToHex)((0, hash_1.blakeHash)(exports.unsignedTxCodec.encode(unsignedTx)));
|
|
73
|
+
}
|
|
74
|
+
static toApiUnsignedTx(unsigned) {
|
|
75
|
+
const txId = UnsignedTxCodec.txId(unsigned);
|
|
76
|
+
const txIdBytes = (0, utils_1.hexToBinUnsafe)(txId);
|
|
77
|
+
const version = unsigned.version;
|
|
78
|
+
const networkId = unsigned.networkId;
|
|
79
|
+
const gasAmount = compact_int_codec_1.compactSignedIntCodec.toI32(unsigned.gasAmount);
|
|
80
|
+
const gasPrice = compact_int_codec_1.compactUnsignedIntCodec.toU256(unsigned.gasPrice).toString();
|
|
81
|
+
const inputs = input_codec_1.InputCodec.toAssetInputs(unsigned.inputs.value);
|
|
82
|
+
const fixedOutputs = asset_output_codec_1.AssetOutputCodec.toFixedAssetOutputs(txIdBytes, unsigned.fixedOutputs.value);
|
|
83
|
+
let scriptOpt = undefined;
|
|
84
|
+
if (unsigned.statefulScript.option === 1) {
|
|
85
|
+
scriptOpt = script_codec_1.scriptCodec.encode(unsigned.statefulScript.value).toString('hex');
|
|
86
|
+
}
|
|
87
|
+
return { txId, version, networkId, gasAmount, scriptOpt, gasPrice, inputs, fixedOutputs };
|
|
88
|
+
}
|
|
89
|
+
static fromApiUnsignedTx(unsignedTx) {
|
|
90
|
+
const version = unsignedTx.version;
|
|
91
|
+
const networkId = unsignedTx.networkId;
|
|
92
|
+
const gasAmount = compact_int_codec_1.compactSignedIntCodec.fromI32(unsignedTx.gasAmount);
|
|
93
|
+
const gasPrice = compact_int_codec_1.compactUnsignedIntCodec.fromU256(BigInt(unsignedTx.gasPrice));
|
|
94
|
+
const inputsValue = input_codec_1.InputCodec.fromAssetInputs(unsignedTx.inputs);
|
|
95
|
+
const inputs = input_codec_1.inputsCodec.fromArray(inputsValue);
|
|
96
|
+
const fixedOutputsValue = asset_output_codec_1.AssetOutputCodec.fromFixedAssetOutputs(unsignedTx.fixedOutputs);
|
|
97
|
+
const fixedOutputs = asset_output_codec_1.assetOutputsCodec.fromArray(fixedOutputsValue);
|
|
98
|
+
const statefulScript = script_codec_1.statefulScriptCodecOpt.fromBuffer(unsignedTx.scriptOpt ? buffer_1.Buffer.from(unsignedTx.scriptOpt, 'hex') : undefined);
|
|
99
|
+
return { version, networkId, gasAmount, gasPrice, inputs, fixedOutputs, statefulScript };
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.UnsignedTxCodec = UnsignedTxCodec;
|
|
103
|
+
exports.unsignedTxCodec = new UnsignedTxCodec();
|
|
@@ -3,6 +3,7 @@ import { SignDeployContractTxParams, SignDeployContractTxResult, SignExecuteScri
|
|
|
3
3
|
import { Optional } from '../utils';
|
|
4
4
|
import { EventSubscribeOptions, EventSubscription } from './events';
|
|
5
5
|
export type FieldsSig = node.FieldsSig;
|
|
6
|
+
export type MapsSig = node.MapsSig;
|
|
6
7
|
export type EventSig = node.EventSig;
|
|
7
8
|
export type FunctionSig = node.FunctionSig;
|
|
8
9
|
export type Fields = NamedVals;
|
|
@@ -130,10 +131,11 @@ export declare class Contract extends Artifact {
|
|
|
130
131
|
readonly constants: Constant[];
|
|
131
132
|
readonly enums: Enum[];
|
|
132
133
|
readonly structs: Struct[];
|
|
134
|
+
readonly mapsSig?: MapsSig;
|
|
133
135
|
readonly stdInterfaceId?: HexString;
|
|
134
136
|
readonly bytecodeDebug: string;
|
|
135
137
|
readonly codeHashDebug: string;
|
|
136
|
-
constructor(version: string, name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[], constants: Constant[], enums: Enum[], structs: Struct[], stdInterfaceId?: HexString);
|
|
138
|
+
constructor(version: string, name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[], constants: Constant[], enums: Enum[], structs: Struct[], mapsSig?: MapsSig, stdInterfaceId?: HexString);
|
|
137
139
|
static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string, structs?: Struct[]): Contract;
|
|
138
140
|
static fromCompileResult(result: node.CompileContractResult, structs?: Struct[]): Contract;
|
|
139
141
|
static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string, structs?: Struct[]): Promise<Contract>;
|
|
@@ -196,7 +198,8 @@ export interface ContractState<T extends Fields = Fields> {
|
|
|
196
198
|
fieldsSig: FieldsSig;
|
|
197
199
|
asset: Asset;
|
|
198
200
|
}
|
|
199
|
-
export
|
|
201
|
+
export type TestContractParamsWithoutMaps<F extends Fields = Fields, A extends Arguments = Arguments> = Omit<TestContractParams<F, A>, 'initialMaps'>;
|
|
202
|
+
export interface TestContractParams<F extends Fields = Fields, A extends Arguments = Arguments, M extends Record<string, Map<Val, Val>> = Record<string, Map<Val, Val>>> {
|
|
200
203
|
group?: number;
|
|
201
204
|
address?: string;
|
|
202
205
|
callerAddress?: string;
|
|
@@ -204,6 +207,7 @@ export interface TestContractParams<F extends Fields = Fields, A extends Argumen
|
|
|
204
207
|
blockTimeStamp?: number;
|
|
205
208
|
txId?: string;
|
|
206
209
|
initialFields: F;
|
|
210
|
+
initialMaps?: M;
|
|
207
211
|
initialAsset?: Asset;
|
|
208
212
|
testArgs: A;
|
|
209
213
|
existingContracts?: ContractState[];
|
|
@@ -218,11 +222,13 @@ export interface ContractEvent<T extends Fields = Fields> {
|
|
|
218
222
|
fields: T;
|
|
219
223
|
}
|
|
220
224
|
export type DebugMessage = node.DebugMessage;
|
|
221
|
-
export
|
|
225
|
+
export type TestContractResultWithoutMaps<R> = Omit<TestContractResult<R>, 'maps'>;
|
|
226
|
+
export interface TestContractResult<R, M extends Record<string, Map<Val, Val>> = Record<string, Map<Val, Val>>> {
|
|
222
227
|
contractId: string;
|
|
223
228
|
contractAddress: string;
|
|
224
229
|
returns: R;
|
|
225
230
|
gasUsed: number;
|
|
231
|
+
maps?: M;
|
|
226
232
|
contracts: ContractState[];
|
|
227
233
|
txOutputs: Output[];
|
|
228
234
|
events: ContractEvent[];
|
|
@@ -297,8 +303,8 @@ export interface CallContractResult<R> {
|
|
|
297
303
|
events: ContractEvent[];
|
|
298
304
|
debugMessages: DebugMessage[];
|
|
299
305
|
}
|
|
300
|
-
export declare const
|
|
301
|
-
export declare const
|
|
306
|
+
export declare const CreateContractEventAddresses: string[];
|
|
307
|
+
export declare const DestroyContractEventAddresses: string[];
|
|
302
308
|
export type ContractCreatedEventFields = {
|
|
303
309
|
address: Address;
|
|
304
310
|
parentAddress?: Address;
|
|
@@ -315,7 +321,7 @@ export declare function subscribeEventsFromContract<T extends Fields, M extends
|
|
|
315
321
|
export declare function addStdIdToFields<F extends Fields>(contract: Contract, fields: F): F | (F & {
|
|
316
322
|
__stdInterfaceId: HexString;
|
|
317
323
|
});
|
|
318
|
-
export declare function testMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R
|
|
324
|
+
export declare function testMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R, M extends Record<string, Map<Val, Val>> = Record<string, Map<Val, Val>>>(factory: ContractFactory<I, F>, methodName: string, params: Optional<TestContractParams<F, A, M>, 'testArgs' | 'initialFields'>): Promise<TestContractResult<R, M>>;
|
|
319
325
|
export declare abstract class ContractInstance {
|
|
320
326
|
readonly address: Address;
|
|
321
327
|
readonly contractId: string;
|
|
@@ -323,8 +329,8 @@ export declare abstract class ContractInstance {
|
|
|
323
329
|
constructor(address: Address);
|
|
324
330
|
}
|
|
325
331
|
export declare function fetchContractState<F extends Fields, I extends ContractInstance>(contract: ContractFactory<I, F>, instance: ContractInstance): Promise<ContractState<F>>;
|
|
326
|
-
export declare function subscribeContractCreatedEvent(options: EventSubscribeOptions<ContractCreatedEvent>, fromCount?: number): EventSubscription;
|
|
327
|
-
export declare function subscribeContractDestroyedEvent(options: EventSubscribeOptions<ContractDestroyedEvent>, fromCount?: number): EventSubscription;
|
|
332
|
+
export declare function subscribeContractCreatedEvent(options: EventSubscribeOptions<ContractCreatedEvent>, fromGroup: number, fromCount?: number): EventSubscription;
|
|
333
|
+
export declare function subscribeContractDestroyedEvent(options: EventSubscribeOptions<ContractDestroyedEvent>, fromGroup: number, fromCount?: number): EventSubscription;
|
|
328
334
|
export declare function decodeEvent<F extends Fields, M extends ContractEvent<F>>(contract: Contract, instance: ContractInstance, event: node.ContractEvent, targetEventIndex: number): M;
|
|
329
335
|
export declare function subscribeContractEvent<F extends Fields, M extends ContractEvent<F>>(contract: Contract, instance: ContractInstance, options: EventSubscribeOptions<M>, eventName: string, fromCount?: number): EventSubscription;
|
|
330
336
|
export declare function subscribeContractEvents(contract: Contract, instance: ContractInstance, options: EventSubscribeOptions<ContractEvent<any>>, fromCount?: number): EventSubscription;
|