@aptos-labs/ts-sdk 0.0.1 → 0.0.3
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/README.md +32 -24
- package/dist/browser/index.global.js +25 -25
- package/dist/browser/index.global.js.map +1 -1
- package/dist/cjs/index.d.ts +809 -184
- package/dist/cjs/index.js +1458 -616
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +809 -184
- package/dist/esm/index.mjs +1388 -614
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +72 -25
- package/dist/types/index.js +28 -3
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/account.ts +2 -2
- package/src/api/coin.ts +5 -5
- package/src/api/digitalAsset.ts +5 -5
- package/src/api/event.ts +2 -2
- package/src/api/faucet.ts +7 -3
- package/src/api/transactionSubmission.ts +24 -24
- package/src/bcs/serializable/fixedBytes.ts +1 -1
- package/src/bcs/serializable/moveStructs.ts +16 -36
- package/src/core/account.ts +12 -8
- package/src/core/accountAddress.ts +4 -2
- package/src/core/authenticationKey.ts +24 -2
- package/src/core/crypto/anyPublicKey.ts +14 -18
- package/src/core/crypto/ed25519.ts +6 -0
- package/src/core/crypto/index.ts +1 -0
- package/src/core/crypto/multiKey.ts +122 -0
- package/src/core/crypto/secp256k1.ts +2 -0
- package/src/index.ts +1 -2
- package/src/internal/account.ts +5 -5
- package/src/internal/coin.ts +8 -8
- package/src/internal/digitalAsset.ts +7 -7
- package/src/internal/event.ts +2 -2
- package/src/internal/faucet.ts +9 -5
- package/src/internal/transactionSubmission.ts +40 -15
- package/src/transactions/authenticator/account.ts +39 -0
- package/src/transactions/authenticator/index.ts +5 -0
- package/src/transactions/authenticator/transaction.ts +6 -6
- package/src/transactions/index.ts +9 -0
- package/src/transactions/instances/index.ts +1 -0
- package/src/transactions/instances/transactionPayload.ts +13 -8
- package/src/transactions/transactionBuilder/helpers.ts +99 -0
- package/src/transactions/transactionBuilder/index.ts +6 -0
- package/src/transactions/transactionBuilder/remoteAbi.ts +339 -0
- package/src/transactions/{transaction_builder/transaction_builder.ts → transactionBuilder/transactionBuilder.ts} +149 -68
- package/src/transactions/typeTag/index.ts +385 -0
- package/src/transactions/typeTag/parser.ts +21 -8
- package/src/transactions/types.ts +87 -46
- package/src/types/index.ts +18 -16
- package/src/transactions/typeTag/typeTag.ts +0 -487
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
|
+
/* eslint-disable class-methods-use-this */
|
|
6
|
+
/* eslint-disable max-classes-per-file */
|
|
7
|
+
import { Deserializer } from "../../bcs/deserializer";
|
|
8
|
+
import { Serializable, Serializer } from "../../bcs/serializer";
|
|
9
|
+
import { AccountAddress } from "../../core";
|
|
10
|
+
import { Identifier } from "../instances/identifier";
|
|
11
|
+
import { TypeTagVariants } from "../../types";
|
|
12
|
+
|
|
13
|
+
export abstract class TypeTag extends Serializable {
|
|
14
|
+
abstract serialize(serializer: Serializer): void;
|
|
15
|
+
|
|
16
|
+
static deserialize(deserializer: Deserializer): TypeTag {
|
|
17
|
+
const index = deserializer.deserializeUleb128AsU32();
|
|
18
|
+
switch (index) {
|
|
19
|
+
case TypeTagVariants.Bool:
|
|
20
|
+
return TypeTagBool.load(deserializer);
|
|
21
|
+
case TypeTagVariants.U8:
|
|
22
|
+
return TypeTagU8.load(deserializer);
|
|
23
|
+
case TypeTagVariants.U64:
|
|
24
|
+
return TypeTagU64.load(deserializer);
|
|
25
|
+
case TypeTagVariants.U128:
|
|
26
|
+
return TypeTagU128.load(deserializer);
|
|
27
|
+
case TypeTagVariants.Address:
|
|
28
|
+
return TypeTagAddress.load(deserializer);
|
|
29
|
+
case TypeTagVariants.Signer:
|
|
30
|
+
return TypeTagSigner.load(deserializer);
|
|
31
|
+
case TypeTagVariants.Vector:
|
|
32
|
+
return TypeTagVector.load(deserializer);
|
|
33
|
+
case TypeTagVariants.Struct:
|
|
34
|
+
return TypeTagStruct.load(deserializer);
|
|
35
|
+
case TypeTagVariants.U16:
|
|
36
|
+
return TypeTagU16.load(deserializer);
|
|
37
|
+
case TypeTagVariants.U32:
|
|
38
|
+
return TypeTagU32.load(deserializer);
|
|
39
|
+
case TypeTagVariants.U256:
|
|
40
|
+
return TypeTagU256.load(deserializer);
|
|
41
|
+
case TypeTagVariants.Generic:
|
|
42
|
+
// This is only used for ABI representation, and cannot actually be used as a type.
|
|
43
|
+
return TypeTagGeneric.load(deserializer);
|
|
44
|
+
default:
|
|
45
|
+
throw new Error(`Unknown variant index for TypeTag: ${index}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
abstract toString(): string;
|
|
50
|
+
|
|
51
|
+
isBool(): this is TypeTagBool {
|
|
52
|
+
return this instanceof TypeTagBool;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
isAddress(): this is TypeTagAddress {
|
|
56
|
+
return this instanceof TypeTagAddress;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
isGeneric(): this is TypeTagGeneric {
|
|
60
|
+
return this instanceof TypeTagGeneric;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
isSigner(): this is TypeTagSigner {
|
|
64
|
+
return this instanceof TypeTagSigner;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
isVector(): this is TypeTagVector {
|
|
68
|
+
return this instanceof TypeTagVector;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
isStruct(): this is TypeTagStruct {
|
|
72
|
+
return this instanceof TypeTagStruct;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
isU8(): this is TypeTagU8 {
|
|
76
|
+
return this instanceof TypeTagU8;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
isU16(): this is TypeTagU16 {
|
|
80
|
+
return this instanceof TypeTagU16;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
isU32(): this is TypeTagU32 {
|
|
84
|
+
return this instanceof TypeTagU32;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
isU64(): this is TypeTagU64 {
|
|
88
|
+
return this instanceof TypeTagU64;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
isU128(): this is TypeTagU128 {
|
|
92
|
+
return this instanceof TypeTagU128;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
isU256(): this is TypeTagU256 {
|
|
96
|
+
return this instanceof TypeTagU256;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export class TypeTagBool extends TypeTag {
|
|
101
|
+
toString(): string {
|
|
102
|
+
return "bool";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
serialize(serializer: Serializer): void {
|
|
106
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.Bool);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static load(_deserializer: Deserializer): TypeTagBool {
|
|
110
|
+
return new TypeTagBool();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export class TypeTagU8 extends TypeTag {
|
|
115
|
+
toString(): string {
|
|
116
|
+
return "u8";
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
serialize(serializer: Serializer): void {
|
|
120
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.U8);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static load(_deserializer: Deserializer): TypeTagU8 {
|
|
124
|
+
return new TypeTagU8();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export class TypeTagU16 extends TypeTag {
|
|
129
|
+
toString(): string {
|
|
130
|
+
return "u16";
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
serialize(serializer: Serializer): void {
|
|
134
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.U16);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static load(_deserializer: Deserializer): TypeTagU16 {
|
|
138
|
+
return new TypeTagU16();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export class TypeTagU32 extends TypeTag {
|
|
143
|
+
toString(): string {
|
|
144
|
+
return "u32";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
serialize(serializer: Serializer): void {
|
|
148
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.U32);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static load(_deserializer: Deserializer): TypeTagU32 {
|
|
152
|
+
return new TypeTagU32();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export class TypeTagU64 extends TypeTag {
|
|
157
|
+
toString(): string {
|
|
158
|
+
return "u64";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
serialize(serializer: Serializer): void {
|
|
162
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.U64);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
static load(_deserializer: Deserializer): TypeTagU64 {
|
|
166
|
+
return new TypeTagU64();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export class TypeTagU128 extends TypeTag {
|
|
171
|
+
toString(): string {
|
|
172
|
+
return "u128";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
serialize(serializer: Serializer): void {
|
|
176
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.U128);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
static load(_deserializer: Deserializer): TypeTagU128 {
|
|
180
|
+
return new TypeTagU128();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export class TypeTagU256 extends TypeTag {
|
|
185
|
+
toString(): string {
|
|
186
|
+
return "u256";
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
serialize(serializer: Serializer): void {
|
|
190
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.U256);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
static load(_deserializer: Deserializer): TypeTagU256 {
|
|
194
|
+
return new TypeTagU256();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export class TypeTagAddress extends TypeTag {
|
|
199
|
+
toString(): string {
|
|
200
|
+
return "address";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
serialize(serializer: Serializer): void {
|
|
204
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.Address);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
static load(_deserializer: Deserializer): TypeTagAddress {
|
|
208
|
+
return new TypeTagAddress();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export class TypeTagSigner extends TypeTag {
|
|
213
|
+
toString(): string {
|
|
214
|
+
return "signer";
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
serialize(serializer: Serializer): void {
|
|
218
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.Signer);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
static load(_deserializer: Deserializer): TypeTagSigner {
|
|
222
|
+
return new TypeTagSigner();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export class TypeTagReference extends TypeTag {
|
|
227
|
+
toString(): `&${string}` {
|
|
228
|
+
return `&${this.value.toString()}`;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
constructor(public readonly value: TypeTag) {
|
|
232
|
+
super();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
serialize(serializer: Serializer): void {
|
|
236
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.Reference);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
static load(deserializer: Deserializer): TypeTagReference {
|
|
240
|
+
const value = TypeTag.deserialize(deserializer);
|
|
241
|
+
return new TypeTagReference(value);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Generics are used for type parameters in entry functions. However,
|
|
247
|
+
* they are not actually serialized into a real type, so they cannot be
|
|
248
|
+
* used as a type directly.
|
|
249
|
+
*/
|
|
250
|
+
export class TypeTagGeneric extends TypeTag {
|
|
251
|
+
toString(): `T${number}` {
|
|
252
|
+
return `T${this.value}`;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
constructor(public readonly value: number) {
|
|
256
|
+
super();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
serialize(serializer: Serializer): void {
|
|
260
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.Generic);
|
|
261
|
+
serializer.serializeU32(this.value);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
static load(deserializer: Deserializer): TypeTagGeneric {
|
|
265
|
+
const value = deserializer.deserializeU32();
|
|
266
|
+
return new TypeTagGeneric(value);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export class TypeTagVector extends TypeTag {
|
|
271
|
+
toString(): `vector<${string}>` {
|
|
272
|
+
return `vector<${this.value.toString()}>`;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
constructor(public readonly value: TypeTag) {
|
|
276
|
+
super();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
serialize(serializer: Serializer): void {
|
|
280
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.Vector);
|
|
281
|
+
this.value.serialize(serializer);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
static load(deserializer: Deserializer): TypeTagVector {
|
|
285
|
+
const value = TypeTag.deserialize(deserializer);
|
|
286
|
+
return new TypeTagVector(value);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export class TypeTagStruct extends TypeTag {
|
|
291
|
+
toString(): `0x${string}::${string}::${string}` {
|
|
292
|
+
// Collect type args and add it if there are any
|
|
293
|
+
let typePredicate = "";
|
|
294
|
+
if (this.value.type_args.length > 0) {
|
|
295
|
+
typePredicate = `<${this.value.type_args.map((typeArg) => typeArg.toString()).join(", ")}>`;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return `${this.value.address.toString()}::${this.value.module_name.identifier}::${
|
|
299
|
+
this.value.name.identifier
|
|
300
|
+
}${typePredicate}`;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
constructor(public readonly value: StructTag) {
|
|
304
|
+
super();
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
serialize(serializer: Serializer): void {
|
|
308
|
+
serializer.serializeU32AsUleb128(TypeTagVariants.Struct);
|
|
309
|
+
this.value.serialize(serializer);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
static load(deserializer: Deserializer): TypeTagStruct {
|
|
313
|
+
const value = StructTag.deserialize(deserializer);
|
|
314
|
+
return new TypeTagStruct(value);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
isTypeTag(address: AccountAddress, moduleName: string, structName: string): boolean {
|
|
318
|
+
return (
|
|
319
|
+
this.value.module_name.identifier === moduleName &&
|
|
320
|
+
this.value.name.identifier === structName &&
|
|
321
|
+
this.value.address.equals(address)
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
isString(): boolean {
|
|
326
|
+
return this.isTypeTag(AccountAddress.ONE, "string", "String");
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
isOption(): boolean {
|
|
330
|
+
return this.isTypeTag(AccountAddress.ONE, "option", "Option");
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
isObject(): boolean {
|
|
334
|
+
return this.isTypeTag(AccountAddress.ONE, "object", "Object");
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export class StructTag extends Serializable {
|
|
339
|
+
public readonly address: AccountAddress;
|
|
340
|
+
|
|
341
|
+
public readonly module_name: Identifier;
|
|
342
|
+
|
|
343
|
+
public readonly name: Identifier;
|
|
344
|
+
|
|
345
|
+
public readonly type_args: Array<TypeTag>;
|
|
346
|
+
|
|
347
|
+
constructor(address: AccountAddress, module_name: Identifier, name: Identifier, type_args: Array<TypeTag>) {
|
|
348
|
+
super();
|
|
349
|
+
this.address = address;
|
|
350
|
+
this.module_name = module_name;
|
|
351
|
+
this.name = name;
|
|
352
|
+
this.type_args = type_args;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
serialize(serializer: Serializer): void {
|
|
356
|
+
serializer.serialize(this.address);
|
|
357
|
+
serializer.serialize(this.module_name);
|
|
358
|
+
serializer.serialize(this.name);
|
|
359
|
+
serializer.serializeVector(this.type_args);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
static deserialize(deserializer: Deserializer): StructTag {
|
|
363
|
+
const address = AccountAddress.deserialize(deserializer);
|
|
364
|
+
const moduleName = Identifier.deserialize(deserializer);
|
|
365
|
+
const name = Identifier.deserialize(deserializer);
|
|
366
|
+
const typeArgs = deserializer.deserializeVector(TypeTag);
|
|
367
|
+
return new StructTag(address, moduleName, name, typeArgs);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export function aptosCoinStructTag(): StructTag {
|
|
372
|
+
return new StructTag(AccountAddress.ONE, new Identifier("aptos_coin"), new Identifier("AptosCoin"), []);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function stringStructTag(): StructTag {
|
|
376
|
+
return new StructTag(AccountAddress.ONE, new Identifier("string"), new Identifier("String"), []);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export function optionStructTag(typeArg: TypeTag): StructTag {
|
|
380
|
+
return new StructTag(AccountAddress.ONE, new Identifier("option"), new Identifier("Option"), [typeArg]);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
export function objectStructTag(typeArg: TypeTag): StructTag {
|
|
384
|
+
return new StructTag(AccountAddress.ONE, new Identifier("object"), new Identifier("Object"), [typeArg]);
|
|
385
|
+
}
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
TypeTag,
|
|
7
7
|
TypeTagAddress,
|
|
8
8
|
TypeTagBool,
|
|
9
|
+
TypeTagGeneric,
|
|
10
|
+
TypeTagReference,
|
|
9
11
|
TypeTagSigner,
|
|
10
12
|
TypeTagStruct,
|
|
11
13
|
TypeTagU128,
|
|
@@ -15,9 +17,9 @@ import {
|
|
|
15
17
|
TypeTagU64,
|
|
16
18
|
TypeTagU8,
|
|
17
19
|
TypeTagVector,
|
|
18
|
-
} from "
|
|
20
|
+
} from ".";
|
|
19
21
|
import { AccountAddress } from "../../core";
|
|
20
|
-
import { Identifier } from "../instances";
|
|
22
|
+
import { Identifier } from "../instances/identifier";
|
|
21
23
|
|
|
22
24
|
function isValidIdentifier(str: string) {
|
|
23
25
|
return !!str.match(/^[_a-zA-Z0-9]+$/);
|
|
@@ -78,7 +80,9 @@ export class TypeTagParserError extends Error {
|
|
|
78
80
|
* 3. Nested generics of different depths e.g. 0x1::pair::Pair<0x1::coin::Coin<0x1234::coin::MyCoin>, u8>
|
|
79
81
|
* 4. Generics for types in ABIs are filled in with placeholders e.g T1, T2, T3
|
|
80
82
|
*/
|
|
81
|
-
export function parseTypeTag(typeStr: string) {
|
|
83
|
+
export function parseTypeTag(typeStr: string, options?: { allowGenerics?: boolean }) {
|
|
84
|
+
const allowGenerics = options?.allowGenerics ?? false;
|
|
85
|
+
|
|
82
86
|
const saved: Array<TypeTagState> = [];
|
|
83
87
|
// This represents the internal types for a type tag e.g. '0x1::coin::Coin<innerTypes>'
|
|
84
88
|
let innerTypes: Array<TypeTag> = [];
|
|
@@ -109,7 +113,7 @@ export function parseTypeTag(typeStr: string) {
|
|
|
109
113
|
} else if (char === ">") {
|
|
110
114
|
// Process last type, if there is no type string, then don't parse it
|
|
111
115
|
if (currentStr !== "") {
|
|
112
|
-
const newType = parseTypeTagInner(currentStr, innerTypes);
|
|
116
|
+
const newType = parseTypeTagInner(currentStr, innerTypes, allowGenerics);
|
|
113
117
|
curTypes.push(newType);
|
|
114
118
|
}
|
|
115
119
|
|
|
@@ -134,7 +138,7 @@ export function parseTypeTag(typeStr: string) {
|
|
|
134
138
|
// Comma means we need to start parsing a new tag, push the previous one to the curTypes
|
|
135
139
|
// Process last type, if there is no type string, then don't parse it
|
|
136
140
|
if (currentStr.length !== 0) {
|
|
137
|
-
const newType = parseTypeTagInner(currentStr, innerTypes);
|
|
141
|
+
const newType = parseTypeTagInner(currentStr, innerTypes, allowGenerics);
|
|
138
142
|
|
|
139
143
|
// parse type tag and push it on the types
|
|
140
144
|
innerTypes = [];
|
|
@@ -146,7 +150,7 @@ export function parseTypeTag(typeStr: string) {
|
|
|
146
150
|
// This means we should save what we have and everything else should skip until the next
|
|
147
151
|
let parsedTypeTag = false;
|
|
148
152
|
if (currentStr.length !== 0) {
|
|
149
|
-
const newType = parseTypeTagInner(currentStr, innerTypes);
|
|
153
|
+
const newType = parseTypeTagInner(currentStr, innerTypes, allowGenerics);
|
|
150
154
|
|
|
151
155
|
// parse type tag and push it on the types
|
|
152
156
|
innerTypes = [];
|
|
@@ -183,7 +187,7 @@ export function parseTypeTag(typeStr: string) {
|
|
|
183
187
|
// This prevents 'u8, u8' as an input
|
|
184
188
|
switch (curTypes.length) {
|
|
185
189
|
case 0:
|
|
186
|
-
return parseTypeTagInner(currentStr, innerTypes);
|
|
190
|
+
return parseTypeTagInner(currentStr, innerTypes, allowGenerics);
|
|
187
191
|
case 1:
|
|
188
192
|
if (currentStr === "") {
|
|
189
193
|
return curTypes[0];
|
|
@@ -199,9 +203,14 @@ export function parseTypeTag(typeStr: string) {
|
|
|
199
203
|
* @param str
|
|
200
204
|
* @param types
|
|
201
205
|
*/
|
|
202
|
-
function parseTypeTagInner(str: string, types: Array<TypeTag
|
|
206
|
+
function parseTypeTagInner(str: string, types: Array<TypeTag>, allowGenerics: boolean): TypeTag {
|
|
207
|
+
// TODO: Parse references to any item not just signer
|
|
203
208
|
switch (str) {
|
|
204
209
|
case "&signer":
|
|
210
|
+
if (types.length > 0) {
|
|
211
|
+
throw new TypeTagParserError(str, TypeTagParserErrorType.UnexpectedPrimitiveTypeArguments);
|
|
212
|
+
}
|
|
213
|
+
return new TypeTagReference(new TypeTagSigner());
|
|
205
214
|
case "signer":
|
|
206
215
|
if (types.length > 0) {
|
|
207
216
|
throw new TypeTagParserError(str, TypeTagParserErrorType.UnexpectedPrimitiveTypeArguments);
|
|
@@ -253,6 +262,10 @@ function parseTypeTagInner(str: string, types: Array<TypeTag>): TypeTag {
|
|
|
253
262
|
}
|
|
254
263
|
return new TypeTagVector(types[0]);
|
|
255
264
|
default:
|
|
265
|
+
if (allowGenerics && str.match(/^T[0-9]+$/)) {
|
|
266
|
+
return new TypeTagGeneric(Number(str.split("T")[1]));
|
|
267
|
+
}
|
|
268
|
+
|
|
256
269
|
// If the value doesn't contain a colon, then we'll assume it isn't trying to be a struct
|
|
257
270
|
if (!str.match(/.*:.*/)) {
|
|
258
271
|
throw new TypeTagParserError(str, TypeTagParserErrorType.InvalidTypeTag);
|