@aptos-labs/ts-sdk 0.0.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/LICENSE +201 -0
- package/README.md +144 -0
- package/dist/browser/index.global.js +410 -0
- package/dist/browser/index.global.js.map +1 -0
- package/dist/cjs/index.d.ts +4965 -0
- package/dist/cjs/index.js +4762 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.d.ts +4965 -0
- package/dist/esm/index.mjs +4645 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/index.d.ts +1247 -0
- package/dist/types/index.js +151 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +79 -0
- package/src/api/account.ts +360 -0
- package/src/api/aptos.ts +103 -0
- package/src/api/aptosConfig.ts +77 -0
- package/src/api/coin.ts +39 -0
- package/src/api/digitalAsset.ts +192 -0
- package/src/api/event.ts +78 -0
- package/src/api/faucet.ts +30 -0
- package/src/api/fungibleAsset.ts +82 -0
- package/src/api/general.ts +188 -0
- package/src/api/index.ts +5 -0
- package/src/api/staking.ts +58 -0
- package/src/api/transaction.ts +135 -0
- package/src/api/transactionSubmission.ts +168 -0
- package/src/bcs/consts.ts +12 -0
- package/src/bcs/deserializer.ts +248 -0
- package/src/bcs/index.ts +9 -0
- package/src/bcs/serializable/entryFunctionBytes.ts +61 -0
- package/src/bcs/serializable/fixedBytes.ts +65 -0
- package/src/bcs/serializable/movePrimitives.ts +211 -0
- package/src/bcs/serializable/moveStructs.ts +462 -0
- package/src/bcs/serializer.ts +353 -0
- package/src/client/core.ts +106 -0
- package/src/client/get.ts +109 -0
- package/src/client/index.ts +7 -0
- package/src/client/post.ts +90 -0
- package/src/client/types.ts +58 -0
- package/src/core/account.ts +180 -0
- package/src/core/accountAddress.ts +407 -0
- package/src/core/authenticationKey.ts +102 -0
- package/src/core/common.ts +40 -0
- package/src/core/crypto/asymmetricCrypto.ts +77 -0
- package/src/core/crypto/ed25519.ts +224 -0
- package/src/core/crypto/index.ts +7 -0
- package/src/core/crypto/multiEd25519.ts +251 -0
- package/src/core/crypto/secp256k1.ts +227 -0
- package/src/core/hex.ts +177 -0
- package/src/core/index.ts +9 -0
- package/src/index.ts +12 -0
- package/src/internal/account.ts +484 -0
- package/src/internal/coin.ts +32 -0
- package/src/internal/digitalAsset.ts +302 -0
- package/src/internal/event.ts +88 -0
- package/src/internal/faucet.ts +41 -0
- package/src/internal/fungibleAsset.ts +114 -0
- package/src/internal/general.ts +160 -0
- package/src/internal/queries/TokenActivitiesFieldsFragment.graphql +17 -0
- package/src/internal/queries/currentTokenOwnershipFieldsFragment.graphql +45 -0
- package/src/internal/queries/getAccountCoinCount.graphql +7 -0
- package/src/internal/queries/getAccountCoinsData.graphql +32 -0
- package/src/internal/queries/getAccountCollectionsWithOwnedTokens.graphql +33 -0
- package/src/internal/queries/getAccountOwnedObjects.graphql +16 -0
- package/src/internal/queries/getAccountOwnedTokens.graphql +11 -0
- package/src/internal/queries/getAccountOwnedTokensByTokenData.graphql +11 -0
- package/src/internal/queries/getAccountOwnedTokensFromCollectionAddress.graphql +11 -0
- package/src/internal/queries/getAccountTokensCount.graphql +7 -0
- package/src/internal/queries/getAccountTransactionsCount.graphql +7 -0
- package/src/internal/queries/getChainTopUserTransactions.graphql +5 -0
- package/src/internal/queries/getCollectionData.graphql +20 -0
- package/src/internal/queries/getCurrentFungibleAssetBalances.graphql +17 -0
- package/src/internal/queries/getDelegatedStakingActivities.graphql +12 -0
- package/src/internal/queries/getEvents.graphql +12 -0
- package/src/internal/queries/getFungibleAssetActivities.graphql +20 -0
- package/src/internal/queries/getFungibleAssetMetadata.graphql +16 -0
- package/src/internal/queries/getNumberOfDelegatorsQuery.graphql +9 -0
- package/src/internal/queries/getProcessorStatus.graphql +7 -0
- package/src/internal/queries/getTokenActivity.graphql +11 -0
- package/src/internal/queries/getTokenCurrentOwner.graphql +11 -0
- package/src/internal/queries/getTokenData.graphql +38 -0
- package/src/internal/staking.ts +68 -0
- package/src/internal/transaction.ts +245 -0
- package/src/internal/transactionSubmission.ts +162 -0
- package/src/transactions/authenticator/account.ts +121 -0
- package/src/transactions/authenticator/transaction.ts +222 -0
- package/src/transactions/instances/chainId.ts +26 -0
- package/src/transactions/instances/identifier.ts +28 -0
- package/src/transactions/instances/index.ts +9 -0
- package/src/transactions/instances/moduleId.ts +53 -0
- package/src/transactions/instances/rawTransaction.ts +199 -0
- package/src/transactions/instances/signedTransaction.ts +43 -0
- package/src/transactions/instances/transactionArgument.ts +37 -0
- package/src/transactions/instances/transactionPayload.ts +407 -0
- package/src/transactions/transaction_builder/transaction_builder.ts +541 -0
- package/src/transactions/typeTag/typeTag.ts +487 -0
- package/src/transactions/types.ts +262 -0
- package/src/types/codegen.yaml +33 -0
- package/src/types/generated/operations.ts +623 -0
- package/src/types/generated/queries.ts +737 -0
- package/src/types/generated/types.ts +10387 -0
- package/src/types/index.ts +944 -0
- package/src/types/indexer.ts +93 -0
- package/src/utils/apiEndpoints.ts +36 -0
- package/src/utils/const.ts +51 -0
- package/src/utils/hdKey.ts +113 -0
- package/src/utils/helpers.ts +12 -0
- package/src/utils/memoize.ts +68 -0
- package/src/version.ts +9 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
5
|
+
|
|
6
|
+
import { Deserializer } from "../../bcs/deserializer";
|
|
7
|
+
import { Serializable, Serializer } from "../../bcs/serializer";
|
|
8
|
+
import { EntryFunctionBytes } from "../../bcs/serializable/entryFunctionBytes";
|
|
9
|
+
import { Bool, U128, U16, U256, U32, U64, U8 } from "../../bcs/serializable/movePrimitives";
|
|
10
|
+
import { MoveVector } from "../../bcs/serializable/moveStructs";
|
|
11
|
+
import { AccountAddress } from "../../core";
|
|
12
|
+
import { Identifier } from "./identifier";
|
|
13
|
+
import { ModuleId } from "./moduleId";
|
|
14
|
+
import type { EntryFunctionArgument, ScriptFunctionArgument, TransactionArgument } from "./transactionArgument";
|
|
15
|
+
import { MoveModuleId, ScriptTransactionArgumentVariants, TransactionPayloadVariants } from "../../types";
|
|
16
|
+
import { TypeTag } from "../typeTag/typeTag";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Deserialize a Script Transaction Argument
|
|
20
|
+
*/
|
|
21
|
+
export function deserializeFromScriptArgument(deserializer: Deserializer): TransactionArgument {
|
|
22
|
+
// index enum variant
|
|
23
|
+
const index = deserializer.deserializeUleb128AsU32();
|
|
24
|
+
switch (index) {
|
|
25
|
+
case ScriptTransactionArgumentVariants.U8:
|
|
26
|
+
return U8.deserialize(deserializer);
|
|
27
|
+
case ScriptTransactionArgumentVariants.U64:
|
|
28
|
+
return U64.deserialize(deserializer);
|
|
29
|
+
case ScriptTransactionArgumentVariants.U128:
|
|
30
|
+
return U128.deserialize(deserializer);
|
|
31
|
+
case ScriptTransactionArgumentVariants.Address:
|
|
32
|
+
return AccountAddress.deserialize(deserializer);
|
|
33
|
+
case ScriptTransactionArgumentVariants.U8Vector:
|
|
34
|
+
return MoveVector.deserialize(deserializer, U8);
|
|
35
|
+
case ScriptTransactionArgumentVariants.Bool:
|
|
36
|
+
return Bool.deserialize(deserializer);
|
|
37
|
+
case ScriptTransactionArgumentVariants.U16:
|
|
38
|
+
return U16.deserialize(deserializer);
|
|
39
|
+
case ScriptTransactionArgumentVariants.U32:
|
|
40
|
+
return U32.deserialize(deserializer);
|
|
41
|
+
case ScriptTransactionArgumentVariants.U256:
|
|
42
|
+
return U256.deserialize(deserializer);
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`Unknown variant index for ScriptTransactionArgument: ${index}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Representation of the supported Transaction Payload
|
|
50
|
+
* that can serialized and deserialized
|
|
51
|
+
*/
|
|
52
|
+
export abstract class TransactionPayload extends Serializable {
|
|
53
|
+
/**
|
|
54
|
+
* Serialize a Transaction Payload
|
|
55
|
+
*/
|
|
56
|
+
abstract serialize(serializer: Serializer): void;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Deserialize a Transaction Payload
|
|
60
|
+
*/
|
|
61
|
+
static deserialize(deserializer: Deserializer): TransactionPayload {
|
|
62
|
+
// index enum variant
|
|
63
|
+
const index = deserializer.deserializeUleb128AsU32();
|
|
64
|
+
switch (index) {
|
|
65
|
+
case TransactionPayloadVariants.Script:
|
|
66
|
+
return TransactionPayloadScript.load(deserializer);
|
|
67
|
+
case TransactionPayloadVariants.EntryFunction:
|
|
68
|
+
return TransactionPayloadEntryFunction.load(deserializer);
|
|
69
|
+
case TransactionPayloadVariants.Multisig:
|
|
70
|
+
return TransactionPayloadMultisig.load(deserializer);
|
|
71
|
+
default:
|
|
72
|
+
throw new Error(`Unknown variant index for TransactionPayload: ${index}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Representation of a Transaction Payload Script that can serialized and deserialized
|
|
79
|
+
*/
|
|
80
|
+
export class TransactionPayloadScript extends TransactionPayload {
|
|
81
|
+
public readonly script: Script;
|
|
82
|
+
|
|
83
|
+
constructor(script: Script) {
|
|
84
|
+
super();
|
|
85
|
+
this.script = script;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
serialize(serializer: Serializer): void {
|
|
89
|
+
serializer.serializeU32AsUleb128(TransactionPayloadVariants.Script);
|
|
90
|
+
this.script.serialize(serializer);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static load(deserializer: Deserializer): TransactionPayloadScript {
|
|
94
|
+
const script = Script.deserialize(deserializer);
|
|
95
|
+
return new TransactionPayloadScript(script);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Representation of a Transaction Payload Entry Function that can serialized and deserialized
|
|
101
|
+
*/
|
|
102
|
+
export class TransactionPayloadEntryFunction extends TransactionPayload {
|
|
103
|
+
public readonly entryFunction: EntryFunction;
|
|
104
|
+
|
|
105
|
+
constructor(entryFunction: EntryFunction) {
|
|
106
|
+
super();
|
|
107
|
+
this.entryFunction = entryFunction;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
serialize(serializer: Serializer): void {
|
|
111
|
+
serializer.serializeU32AsUleb128(TransactionPayloadVariants.EntryFunction);
|
|
112
|
+
this.entryFunction.serialize(serializer);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
static load(deserializer: Deserializer): TransactionPayloadEntryFunction {
|
|
116
|
+
const entryFunction = EntryFunction.deserialize(deserializer);
|
|
117
|
+
return new TransactionPayloadEntryFunction(entryFunction);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Representation of a Transaction Payload Multi-sig that can serialized and deserialized
|
|
123
|
+
*/
|
|
124
|
+
export class TransactionPayloadMultisig extends TransactionPayload {
|
|
125
|
+
public readonly multiSig: MultiSig;
|
|
126
|
+
|
|
127
|
+
constructor(multiSig: MultiSig) {
|
|
128
|
+
super();
|
|
129
|
+
this.multiSig = multiSig;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
serialize(serializer: Serializer): void {
|
|
133
|
+
serializer.serializeU32AsUleb128(TransactionPayloadVariants.Multisig);
|
|
134
|
+
this.multiSig.serialize(serializer);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static load(deserializer: Deserializer): TransactionPayloadMultisig {
|
|
138
|
+
const multiSig = MultiSig.deserialize(deserializer);
|
|
139
|
+
return new TransactionPayloadMultisig(multiSig);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Representation of a EntryFunction that can serialized and deserialized
|
|
145
|
+
*/
|
|
146
|
+
export class EntryFunction {
|
|
147
|
+
public readonly module_name: ModuleId;
|
|
148
|
+
|
|
149
|
+
public readonly function_name: Identifier;
|
|
150
|
+
|
|
151
|
+
public readonly type_args: Array<TypeTag>;
|
|
152
|
+
|
|
153
|
+
public readonly args: Array<EntryFunctionArgument>;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Contains the payload to run a function within a module.
|
|
157
|
+
* @param module_name Fully qualified module name in format "account_address::module_name" e.g. "0x1::coin"
|
|
158
|
+
* @param function_name The function name. e.g "transfer"
|
|
159
|
+
* @param type_args Type arguments that move function requires.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* A coin transfer function has one type argument "CoinType".
|
|
163
|
+
* ```
|
|
164
|
+
* public entry fun transfer<CoinType>(from: &signer, to: address, amount: u64)
|
|
165
|
+
* ```
|
|
166
|
+
* @param args arguments to the move function.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* A coin transfer function has three arguments "from", "to" and "amount".
|
|
170
|
+
* ```
|
|
171
|
+
* public entry fun transfer<CoinType>(from: &signer, to: address, amount: u64)
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
constructor(
|
|
175
|
+
module_name: ModuleId,
|
|
176
|
+
function_name: Identifier,
|
|
177
|
+
type_args: Array<TypeTag>,
|
|
178
|
+
args: Array<EntryFunctionArgument>,
|
|
179
|
+
) {
|
|
180
|
+
this.module_name = module_name;
|
|
181
|
+
this.function_name = function_name;
|
|
182
|
+
this.type_args = type_args;
|
|
183
|
+
this.args = args;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* A helper function to build a EntryFunction payload from raw primitive values
|
|
188
|
+
*
|
|
189
|
+
* @param module_id Fully qualified module name in format "AccountAddress::module_id" e.g. "0x1::coin"
|
|
190
|
+
* @param function_name Function name
|
|
191
|
+
* @param type_args Type arguments that move function requires.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* A coin transfer function has one type argument "CoinType".
|
|
195
|
+
* ```
|
|
196
|
+
* public(script) fun transfer<CoinType>(from: &signer, to: address, amount: u64,)
|
|
197
|
+
* ```
|
|
198
|
+
* @param args Arguments to the move function.
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* A coin transfer function has three arguments "from", "to" and "amount".
|
|
202
|
+
* ```
|
|
203
|
+
* public(script) fun transfer<CoinType>(from: &signer, to: address, amount: u64,)
|
|
204
|
+
* ```
|
|
205
|
+
* @returns EntryFunction
|
|
206
|
+
*/
|
|
207
|
+
static build(
|
|
208
|
+
module_id: MoveModuleId,
|
|
209
|
+
function_name: string,
|
|
210
|
+
type_args: Array<TypeTag>,
|
|
211
|
+
args: Array<EntryFunctionArgument>,
|
|
212
|
+
): EntryFunction {
|
|
213
|
+
return new EntryFunction(ModuleId.fromStr(module_id), new Identifier(function_name), type_args, args);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
serialize(serializer: Serializer): void {
|
|
217
|
+
this.module_name.serialize(serializer);
|
|
218
|
+
this.function_name.serialize(serializer);
|
|
219
|
+
serializer.serializeVector<TypeTag>(this.type_args);
|
|
220
|
+
serializer.serializeU32AsUleb128(this.args.length);
|
|
221
|
+
this.args.forEach((item: EntryFunctionArgument) => {
|
|
222
|
+
item.serializeForEntryFunction(serializer);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Deserializes an entry function payload with the arguments represented as EntryFunctionBytes instances.
|
|
228
|
+
* @see EntryFunctionBytes
|
|
229
|
+
*
|
|
230
|
+
* NOTE: When you deserialize an EntryFunction payload with this method, the entry function
|
|
231
|
+
* arguments are populated into the deserialized instance as type-agnostic, raw fixed bytes
|
|
232
|
+
* in the form of the EntryFunctionBytes class.
|
|
233
|
+
*
|
|
234
|
+
* In order to correctly deserialize these arguments as their actual type representations, you
|
|
235
|
+
* must know the types of the arguments beforehand and deserialize them yourself individually.
|
|
236
|
+
*
|
|
237
|
+
* One way you could achieve this is by using the ABIs for an entry function and deserializing each
|
|
238
|
+
* argument as its given, corresponding type.
|
|
239
|
+
*
|
|
240
|
+
* @param deserializer
|
|
241
|
+
* @returns A deserialized EntryFunction payload for a transaction.
|
|
242
|
+
*
|
|
243
|
+
*/
|
|
244
|
+
static deserialize(deserializer: Deserializer): EntryFunction {
|
|
245
|
+
const module_name = ModuleId.deserialize(deserializer);
|
|
246
|
+
const function_name = Identifier.deserialize(deserializer);
|
|
247
|
+
const type_args = deserializer.deserializeVector(TypeTag);
|
|
248
|
+
|
|
249
|
+
const length = deserializer.deserializeUleb128AsU32();
|
|
250
|
+
const args: Array<EntryFunctionArgument> = new Array<EntryFunctionBytes>();
|
|
251
|
+
|
|
252
|
+
for (let i = 0; i < length; i += 1) {
|
|
253
|
+
const fixedBytesLength = deserializer.deserializeUleb128AsU32();
|
|
254
|
+
const fixedBytes = EntryFunctionBytes.deserialize(deserializer, fixedBytesLength);
|
|
255
|
+
args.push(fixedBytes);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return new EntryFunction(module_name, function_name, type_args, args);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Representation of a Script that can serialized and deserialized
|
|
264
|
+
*/
|
|
265
|
+
export class Script {
|
|
266
|
+
/**
|
|
267
|
+
* The move module bytecode
|
|
268
|
+
*/
|
|
269
|
+
public readonly bytecode: Uint8Array;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* The type arguments that the bytecode function requires.
|
|
273
|
+
*/
|
|
274
|
+
public readonly type_args: Array<TypeTag>;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* The arguments that the bytecode function requires.
|
|
278
|
+
*/
|
|
279
|
+
public readonly args: Array<ScriptFunctionArgument>;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Scripts contain the Move bytecodes payload that can be submitted to Aptos chain for execution.
|
|
283
|
+
*
|
|
284
|
+
* @param bytecode The move module bytecode
|
|
285
|
+
* @param type_args The type arguments that the bytecode function requires.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* A coin transfer function has one type argument "CoinType".
|
|
289
|
+
* ```
|
|
290
|
+
* public(script) fun transfer<CoinType>(from: &signer, to: address, amount: u64,)
|
|
291
|
+
* ```
|
|
292
|
+
* @param args The arguments that the bytecode function requires.
|
|
293
|
+
*
|
|
294
|
+
* @example
|
|
295
|
+
* A coin transfer function has three arguments "from", "to" and "amount".
|
|
296
|
+
* ```
|
|
297
|
+
* public(script) fun transfer<CoinType>(from: &signer, to: address, amount: u64,)
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
constructor(bytecode: Uint8Array, type_args: Array<TypeTag>, args: Array<ScriptFunctionArgument>) {
|
|
301
|
+
this.bytecode = bytecode;
|
|
302
|
+
this.type_args = type_args;
|
|
303
|
+
this.args = args;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
serialize(serializer: Serializer): void {
|
|
307
|
+
serializer.serializeBytes(this.bytecode);
|
|
308
|
+
serializer.serializeVector<TypeTag>(this.type_args);
|
|
309
|
+
serializer.serializeU32AsUleb128(this.args.length);
|
|
310
|
+
this.args.forEach((item: ScriptFunctionArgument) => {
|
|
311
|
+
item.serializeForScriptFunction(serializer);
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
static deserialize(deserializer: Deserializer): Script {
|
|
316
|
+
const bytecode = deserializer.deserializeBytes();
|
|
317
|
+
const type_args = deserializer.deserializeVector(TypeTag);
|
|
318
|
+
const length = deserializer.deserializeUleb128AsU32();
|
|
319
|
+
const args = new Array<ScriptFunctionArgument>();
|
|
320
|
+
for (let i = 0; i < length; i += 1) {
|
|
321
|
+
// Note that we deserialize directly to the Move value, not its Script argument representation.
|
|
322
|
+
// We are abstracting away the Script argument representation because knowing about it is
|
|
323
|
+
// functionally useless.
|
|
324
|
+
const scriptArgument = deserializeFromScriptArgument(deserializer);
|
|
325
|
+
args.push(scriptArgument);
|
|
326
|
+
}
|
|
327
|
+
return new Script(bytecode, type_args, args);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Representation of a MultiSig that can serialized and deserialized
|
|
333
|
+
*/
|
|
334
|
+
export class MultiSig {
|
|
335
|
+
public readonly multisig_address: AccountAddress;
|
|
336
|
+
|
|
337
|
+
public readonly transaction_payload?: MultiSigTransactionPayload;
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Contains the payload to run a multi-sig account transaction.
|
|
341
|
+
*
|
|
342
|
+
* @param multisig_address The multi-sig account address the transaction will be executed as.
|
|
343
|
+
*
|
|
344
|
+
* @param transaction_payload The payload of the multi-sig transaction. This is optional when executing a multi-sig
|
|
345
|
+
* transaction whose payload is already stored on chain.
|
|
346
|
+
*/
|
|
347
|
+
constructor(multisig_address: AccountAddress, transaction_payload?: MultiSigTransactionPayload) {
|
|
348
|
+
this.multisig_address = multisig_address;
|
|
349
|
+
this.transaction_payload = transaction_payload;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
serialize(serializer: Serializer): void {
|
|
353
|
+
this.multisig_address.serialize(serializer);
|
|
354
|
+
// Options are encoded with an extra u8 field before the value - 0x0 is none and 0x1 is present.
|
|
355
|
+
// We use serializeBool below to create this prefix value.
|
|
356
|
+
if (this.transaction_payload === undefined) {
|
|
357
|
+
serializer.serializeBool(false);
|
|
358
|
+
} else {
|
|
359
|
+
serializer.serializeBool(true);
|
|
360
|
+
this.transaction_payload.serialize(serializer);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
static deserialize(deserializer: Deserializer): MultiSig {
|
|
365
|
+
const multisig_address = AccountAddress.deserialize(deserializer);
|
|
366
|
+
const payloadPresent = deserializer.deserializeBool();
|
|
367
|
+
let transaction_payload;
|
|
368
|
+
if (payloadPresent) {
|
|
369
|
+
transaction_payload = MultiSigTransactionPayload.deserialize(deserializer);
|
|
370
|
+
}
|
|
371
|
+
return new MultiSig(multisig_address, transaction_payload);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Representation of a MultiSig Transaction Payload that can serialized and deserialized
|
|
377
|
+
*/
|
|
378
|
+
export class MultiSigTransactionPayload {
|
|
379
|
+
public readonly transaction_payload: EntryFunction;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Contains the payload to run a multi-sig account transaction.
|
|
383
|
+
*
|
|
384
|
+
* @param transaction_payload The payload of the multi-sig transaction.
|
|
385
|
+
* This can only be EntryFunction for now but,
|
|
386
|
+
* Script might be supported in the future.
|
|
387
|
+
*/
|
|
388
|
+
constructor(transaction_payload: EntryFunction) {
|
|
389
|
+
this.transaction_payload = transaction_payload;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
serialize(serializer: Serializer): void {
|
|
393
|
+
/**
|
|
394
|
+
* We can support multiple types of inner transaction payload in the future.
|
|
395
|
+
* For now, it's only EntryFunction but if we support more types,
|
|
396
|
+
* we need to serialize with the right enum values here
|
|
397
|
+
*/
|
|
398
|
+
serializer.serializeU32AsUleb128(0);
|
|
399
|
+
this.transaction_payload.serialize(serializer);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
static deserialize(deserializer: Deserializer): MultiSigTransactionPayload {
|
|
403
|
+
// This is the enum value indicating which type of payload the multi-sig transaction contains.
|
|
404
|
+
deserializer.deserializeUleb128AsU32();
|
|
405
|
+
return new MultiSigTransactionPayload(EntryFunction.deserialize(deserializer));
|
|
406
|
+
}
|
|
407
|
+
}
|