@mysten/sui 1.44.0 → 1.45.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/CHANGELOG.md +6 -0
- package/dist/cjs/transactions/TransactionData.d.ts +8 -1
- package/dist/cjs/transactions/TransactionData.js +93 -11
- package/dist/cjs/transactions/TransactionData.js.map +2 -2
- package/dist/cjs/transactions/utils.d.ts +2 -1
- package/dist/cjs/transactions/utils.js +64 -1
- package/dist/cjs/transactions/utils.js.map +2 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/transactions/TransactionData.d.ts +8 -1
- package/dist/esm/transactions/TransactionData.js +94 -12
- package/dist/esm/transactions/TransactionData.js.map +2 -2
- package/dist/esm/transactions/utils.d.ts +2 -1
- package/dist/esm/transactions/utils.js +64 -1
- package/dist/esm/transactions/utils.js.map +2 -2
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/transactions/TransactionData.ts +137 -15
- package/src/transactions/utils.ts +70 -1
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,7 @@ import type { InferInput } from 'valibot';
|
|
|
2
2
|
import type { Argument, CallArg, Command, GasData, TransactionExpiration, TransactionData } from './data/internal.js';
|
|
3
3
|
import type { SerializedTransactionDataV1 } from './data/v1.js';
|
|
4
4
|
import type { SerializedTransactionDataV2Schema } from './data/v2.js';
|
|
5
|
+
import type { TransactionResult } from './Transaction.js';
|
|
5
6
|
export declare class TransactionDataBuilder implements TransactionData {
|
|
6
7
|
static fromKindBytes(bytes: Uint8Array): TransactionDataBuilder;
|
|
7
8
|
static fromBytes(bytes: Uint8Array): TransactionDataBuilder;
|
|
@@ -58,7 +59,13 @@ export declare class TransactionDataBuilder implements TransactionData {
|
|
|
58
59
|
getInputUses(index: number, fn: (arg: Argument, command: Command) => void): void;
|
|
59
60
|
mapCommandArguments(index: number, fn: (arg: Argument, command: Command, commandIndex: number) => Argument): void;
|
|
60
61
|
mapArguments(fn: (arg: Argument, command: Command, commandIndex: number) => Argument): void;
|
|
61
|
-
replaceCommand(index: number, replacement: Command | Command[], resultIndex?: number
|
|
62
|
+
replaceCommand(index: number, replacement: Command | Command[], resultIndex?: number | {
|
|
63
|
+
Result: number;
|
|
64
|
+
} | {
|
|
65
|
+
NestedResult: [number, number];
|
|
66
|
+
}): void;
|
|
67
|
+
replaceCommandWithTransaction(index: number, otherTransaction: TransactionData, result: TransactionResult): void;
|
|
68
|
+
insertTransaction(atCommandIndex: number, otherTransaction: TransactionData): void;
|
|
62
69
|
getDigest(): string;
|
|
63
70
|
snapshot(): TransactionData;
|
|
64
71
|
shallowClone(): TransactionDataBuilder;
|
|
@@ -28,6 +28,7 @@ var import_sui_types = require("../utils/sui-types.js");
|
|
|
28
28
|
var import_internal = require("./data/internal.js");
|
|
29
29
|
var import_v1 = require("./data/v1.js");
|
|
30
30
|
var import_hash = require("./hash.js");
|
|
31
|
+
var import_utils = require("./utils.js");
|
|
31
32
|
function prepareSuiAddress(address) {
|
|
32
33
|
return (0, import_sui_types.normalizeSuiAddress)(address).replace("0x", "");
|
|
33
34
|
}
|
|
@@ -229,26 +230,107 @@ class TransactionDataBuilder {
|
|
|
229
230
|
return;
|
|
230
231
|
}
|
|
231
232
|
const sizeDiff = replacement.length - 1;
|
|
232
|
-
this.commands.splice(index, 1, ...replacement);
|
|
233
|
-
|
|
233
|
+
this.commands.splice(index, 1, ...structuredClone(replacement));
|
|
234
|
+
this.mapArguments((arg, _command, commandIndex) => {
|
|
235
|
+
if (commandIndex < index + replacement.length) {
|
|
236
|
+
return arg;
|
|
237
|
+
}
|
|
238
|
+
if (typeof resultIndex !== "number") {
|
|
239
|
+
if (arg.$kind === "Result" && arg.Result === index || arg.$kind === "NestedResult" && arg.NestedResult[0] === index) {
|
|
240
|
+
if (!("NestedResult" in arg) || arg.NestedResult[1] === 0) {
|
|
241
|
+
return (0, import_valibot.parse)(import_internal.ArgumentSchema, structuredClone(resultIndex));
|
|
242
|
+
} else {
|
|
243
|
+
throw new Error(
|
|
244
|
+
`Cannot replace command ${index} with a specific result type: NestedResult[${index}, ${arg.NestedResult[1]}] references a nested element that cannot be mapped to the replacement result`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
switch (arg.$kind) {
|
|
250
|
+
case "Result":
|
|
251
|
+
if (arg.Result === index && typeof resultIndex === "number") {
|
|
252
|
+
arg.Result = resultIndex;
|
|
253
|
+
}
|
|
254
|
+
if (arg.Result > index) {
|
|
255
|
+
arg.Result += sizeDiff;
|
|
256
|
+
}
|
|
257
|
+
break;
|
|
258
|
+
case "NestedResult":
|
|
259
|
+
if (arg.NestedResult[0] === index && typeof resultIndex === "number") {
|
|
260
|
+
return {
|
|
261
|
+
$kind: "NestedResult",
|
|
262
|
+
NestedResult: [resultIndex, arg.NestedResult[1]]
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
if (arg.NestedResult[0] > index) {
|
|
266
|
+
arg.NestedResult[0] += sizeDiff;
|
|
267
|
+
}
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
return arg;
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
replaceCommandWithTransaction(index, otherTransaction, result) {
|
|
274
|
+
if (result.$kind !== "Result" && result.$kind !== "NestedResult") {
|
|
275
|
+
throw new Error("Result must be of kind Result or NestedResult");
|
|
276
|
+
}
|
|
277
|
+
this.insertTransaction(index, otherTransaction);
|
|
278
|
+
this.replaceCommand(
|
|
279
|
+
index + otherTransaction.commands.length,
|
|
280
|
+
[],
|
|
281
|
+
"Result" in result ? { NestedResult: [result.Result + index, 0] } : {
|
|
282
|
+
NestedResult: [
|
|
283
|
+
result.NestedResult[0] + index,
|
|
284
|
+
result.NestedResult[1]
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
insertTransaction(atCommandIndex, otherTransaction) {
|
|
290
|
+
const inputMapping = /* @__PURE__ */ new Map();
|
|
291
|
+
const commandMapping = /* @__PURE__ */ new Map();
|
|
292
|
+
for (let i = 0; i < otherTransaction.inputs.length; i++) {
|
|
293
|
+
const otherInput = otherTransaction.inputs[i];
|
|
294
|
+
const id = (0, import_utils.getIdFromCallArg)(otherInput);
|
|
295
|
+
let existingIndex = -1;
|
|
296
|
+
if (id !== void 0) {
|
|
297
|
+
existingIndex = this.inputs.findIndex((input) => (0, import_utils.getIdFromCallArg)(input) === id);
|
|
298
|
+
if (existingIndex !== -1 && this.inputs[existingIndex].Object?.SharedObject && otherInput.Object?.SharedObject) {
|
|
299
|
+
this.inputs[existingIndex].Object.SharedObject.mutable = this.inputs[existingIndex].Object.SharedObject.mutable || otherInput.Object.SharedObject.mutable;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (existingIndex !== -1) {
|
|
303
|
+
inputMapping.set(i, existingIndex);
|
|
304
|
+
} else {
|
|
305
|
+
const newIndex = this.inputs.length;
|
|
306
|
+
this.inputs.push(otherInput);
|
|
307
|
+
inputMapping.set(i, newIndex);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
for (let i = 0; i < otherTransaction.commands.length; i++) {
|
|
311
|
+
commandMapping.set(i, atCommandIndex + i);
|
|
312
|
+
}
|
|
313
|
+
const remappedCommands = [];
|
|
314
|
+
for (let i = 0; i < otherTransaction.commands.length; i++) {
|
|
315
|
+
const command = structuredClone(otherTransaction.commands[i]);
|
|
316
|
+
(0, import_utils.remapCommandArguments)(command, inputMapping, commandMapping);
|
|
317
|
+
remappedCommands.push(command);
|
|
318
|
+
}
|
|
319
|
+
this.commands.splice(atCommandIndex, 0, ...remappedCommands);
|
|
320
|
+
const sizeDiff = remappedCommands.length;
|
|
321
|
+
if (sizeDiff > 0) {
|
|
234
322
|
this.mapArguments((arg, _command, commandIndex) => {
|
|
235
|
-
if (commandIndex <
|
|
323
|
+
if (commandIndex >= atCommandIndex && commandIndex < atCommandIndex + remappedCommands.length) {
|
|
236
324
|
return arg;
|
|
237
325
|
}
|
|
238
326
|
switch (arg.$kind) {
|
|
239
327
|
case "Result":
|
|
240
|
-
if (arg.Result
|
|
241
|
-
arg.Result = resultIndex;
|
|
242
|
-
}
|
|
243
|
-
if (arg.Result > index) {
|
|
328
|
+
if (arg.Result >= atCommandIndex) {
|
|
244
329
|
arg.Result += sizeDiff;
|
|
245
330
|
}
|
|
246
331
|
break;
|
|
247
332
|
case "NestedResult":
|
|
248
|
-
if (arg.NestedResult[0]
|
|
249
|
-
arg.NestedResult[0] = resultIndex;
|
|
250
|
-
}
|
|
251
|
-
if (arg.NestedResult[0] > index) {
|
|
333
|
+
if (arg.NestedResult[0] >= atCommandIndex) {
|
|
252
334
|
arg.NestedResult[0] += sizeDiff;
|
|
253
335
|
}
|
|
254
336
|
break;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/transactions/TransactionData.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase58 } from '@mysten/bcs';\nimport type { InferInput } from 'valibot';\nimport { parse } from 'valibot';\n\nimport { bcs } from '../bcs/index.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\nimport type {\n\tArgument,\n\tCallArg,\n\tCommand,\n\tGasData,\n\tTransactionExpiration,\n\tTransactionData,\n} from './data/internal.js';\nimport { TransactionDataSchema } from './data/internal.js';\nimport { transactionDataFromV1 } from './data/v1.js';\nimport type { SerializedTransactionDataV1 } from './data/v1.js';\nimport type { SerializedTransactionDataV2Schema } from './data/v2.js';\nimport { hashTypedData } from './hash.js';\nfunction prepareSuiAddress(address: string) {\n\treturn normalizeSuiAddress(address).replace('0x', '');\n}\n\nexport class TransactionDataBuilder implements TransactionData {\n\tstatic fromKindBytes(bytes: Uint8Array) {\n\t\tconst kind = bcs.TransactionKind.parse(bytes);\n\n\t\tconst programmableTx = kind.ProgrammableTransaction;\n\t\tif (!programmableTx) {\n\t\t\tthrow new Error('Unable to deserialize from bytes.');\n\t\t}\n\n\t\treturn TransactionDataBuilder.restore({\n\t\t\tversion: 2,\n\t\t\tsender: null,\n\t\t\texpiration: null,\n\t\t\tgasData: {\n\t\t\t\tbudget: null,\n\t\t\t\towner: null,\n\t\t\t\tpayment: null,\n\t\t\t\tprice: null,\n\t\t\t},\n\t\t\tinputs: programmableTx.inputs,\n\t\t\tcommands: programmableTx.commands,\n\t\t});\n\t}\n\n\tstatic fromBytes(bytes: Uint8Array) {\n\t\tconst rawData = bcs.TransactionData.parse(bytes);\n\t\tconst data = rawData?.V1;\n\t\tconst programmableTx = data.kind.ProgrammableTransaction;\n\n\t\tif (!data || !programmableTx) {\n\t\t\tthrow new Error('Unable to deserialize from bytes.');\n\t\t}\n\n\t\treturn TransactionDataBuilder.restore({\n\t\t\tversion: 2,\n\t\t\tsender: data.sender,\n\t\t\texpiration: data.expiration,\n\t\t\tgasData: data.gasData,\n\t\t\tinputs: programmableTx.inputs,\n\t\t\tcommands: programmableTx.commands,\n\t\t});\n\t}\n\n\tstatic restore(\n\t\tdata:\n\t\t\t| InferInput<typeof SerializedTransactionDataV2Schema>\n\t\t\t| InferInput<typeof SerializedTransactionDataV1>,\n\t) {\n\t\tif (data.version === 2) {\n\t\t\treturn new TransactionDataBuilder(parse(TransactionDataSchema, data));\n\t\t} else {\n\t\t\treturn new TransactionDataBuilder(parse(TransactionDataSchema, transactionDataFromV1(data)));\n\t\t}\n\t}\n\n\t/**\n\t * Generate transaction digest.\n\t *\n\t * @param bytes BCS serialized transaction data\n\t * @returns transaction digest.\n\t */\n\tstatic getDigestFromBytes(bytes: Uint8Array) {\n\t\tconst hash = hashTypedData('TransactionData', bytes);\n\t\treturn toBase58(hash);\n\t}\n\n\t// @deprecated use gasData instead\n\tget gasConfig() {\n\t\treturn this.gasData;\n\t}\n\t// @deprecated use gasData instead\n\tset gasConfig(value) {\n\t\tthis.gasData = value;\n\t}\n\n\tversion = 2 as const;\n\tsender: string | null;\n\texpiration: TransactionExpiration | null;\n\tgasData: GasData;\n\tinputs: CallArg[];\n\tcommands: Command[];\n\n\tconstructor(clone?: TransactionData) {\n\t\tthis.sender = clone?.sender ?? null;\n\t\tthis.expiration = clone?.expiration ?? null;\n\t\tthis.inputs = clone?.inputs ?? [];\n\t\tthis.commands = clone?.commands ?? [];\n\t\tthis.gasData = clone?.gasData ?? {\n\t\t\tbudget: null,\n\t\t\tprice: null,\n\t\t\towner: null,\n\t\t\tpayment: null,\n\t\t};\n\t}\n\n\tbuild({\n\t\tmaxSizeBytes = Infinity,\n\t\toverrides,\n\t\tonlyTransactionKind,\n\t}: {\n\t\tmaxSizeBytes?: number;\n\t\toverrides?: {\n\t\t\texpiration?: TransactionExpiration;\n\t\t\tsender?: string;\n\t\t\t// @deprecated use gasData instead\n\t\t\tgasConfig?: Partial<GasData>;\n\t\t\tgasData?: Partial<GasData>;\n\t\t};\n\t\tonlyTransactionKind?: boolean;\n\t} = {}) {\n\t\t// TODO validate that inputs and intents are actually resolved\n\t\tconst inputs = this.inputs as (typeof bcs.CallArg.$inferInput)[];\n\t\tconst commands = this.commands as Extract<\n\t\t\tCommand<Exclude<Argument, { IntentResult: unknown } | { NestedIntentResult: unknown }>>,\n\t\t\t{ Upgrade: unknown }\n\t\t>[];\n\n\t\tconst kind = {\n\t\t\tProgrammableTransaction: {\n\t\t\t\tinputs,\n\t\t\t\tcommands,\n\t\t\t},\n\t\t};\n\n\t\tif (onlyTransactionKind) {\n\t\t\treturn bcs.TransactionKind.serialize(kind, { maxSize: maxSizeBytes }).toBytes();\n\t\t}\n\n\t\tconst expiration = overrides?.expiration ?? this.expiration;\n\t\tconst sender = overrides?.sender ?? this.sender;\n\t\tconst gasData = { ...this.gasData, ...overrides?.gasConfig, ...overrides?.gasData };\n\n\t\tif (!sender) {\n\t\t\tthrow new Error('Missing transaction sender');\n\t\t}\n\n\t\tif (!gasData.budget) {\n\t\t\tthrow new Error('Missing gas budget');\n\t\t}\n\n\t\tif (!gasData.payment) {\n\t\t\tthrow new Error('Missing gas payment');\n\t\t}\n\n\t\tif (!gasData.price) {\n\t\t\tthrow new Error('Missing gas price');\n\t\t}\n\n\t\tconst transactionData = {\n\t\t\tsender: prepareSuiAddress(sender),\n\t\t\texpiration: expiration ? expiration : { None: true },\n\t\t\tgasData: {\n\t\t\t\tpayment: gasData.payment,\n\t\t\t\towner: prepareSuiAddress(this.gasData.owner ?? sender),\n\t\t\t\tprice: BigInt(gasData.price),\n\t\t\t\tbudget: BigInt(gasData.budget),\n\t\t\t},\n\t\t\tkind: {\n\t\t\t\tProgrammableTransaction: {\n\t\t\t\t\tinputs,\n\t\t\t\t\tcommands,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\treturn bcs.TransactionData.serialize(\n\t\t\t{ V1: transactionData },\n\t\t\t{ maxSize: maxSizeBytes },\n\t\t).toBytes();\n\t}\n\n\taddInput<T extends 'object' | 'pure'>(type: T, arg: CallArg) {\n\t\tconst index = this.inputs.length;\n\t\tthis.inputs.push(arg);\n\t\treturn { Input: index, type, $kind: 'Input' as const };\n\t}\n\n\tgetInputUses(index: number, fn: (arg: Argument, command: Command) => void) {\n\t\tthis.mapArguments((arg, command) => {\n\t\t\tif (arg.$kind === 'Input' && arg.Input === index) {\n\t\t\t\tfn(arg, command);\n\t\t\t}\n\n\t\t\treturn arg;\n\t\t});\n\t}\n\n\tmapCommandArguments(\n\t\tindex: number,\n\t\tfn: (arg: Argument, command: Command, commandIndex: number) => Argument,\n\t) {\n\t\tconst command = this.commands[index];\n\n\t\tswitch (command.$kind) {\n\t\t\tcase 'MoveCall':\n\t\t\t\tcommand.MoveCall.arguments = command.MoveCall.arguments.map((arg) =>\n\t\t\t\t\tfn(arg, command, index),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'TransferObjects':\n\t\t\t\tcommand.TransferObjects.objects = command.TransferObjects.objects.map((arg) =>\n\t\t\t\t\tfn(arg, command, index),\n\t\t\t\t);\n\t\t\t\tcommand.TransferObjects.address = fn(command.TransferObjects.address, command, index);\n\t\t\t\tbreak;\n\t\t\tcase 'SplitCoins':\n\t\t\t\tcommand.SplitCoins.coin = fn(command.SplitCoins.coin, command, index);\n\t\t\t\tcommand.SplitCoins.amounts = command.SplitCoins.amounts.map((arg) =>\n\t\t\t\t\tfn(arg, command, index),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'MergeCoins':\n\t\t\t\tcommand.MergeCoins.destination = fn(command.MergeCoins.destination, command, index);\n\t\t\t\tcommand.MergeCoins.sources = command.MergeCoins.sources.map((arg) =>\n\t\t\t\t\tfn(arg, command, index),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'MakeMoveVec':\n\t\t\t\tcommand.MakeMoveVec.elements = command.MakeMoveVec.elements.map((arg) =>\n\t\t\t\t\tfn(arg, command, index),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'Upgrade':\n\t\t\t\tcommand.Upgrade.ticket = fn(command.Upgrade.ticket, command, index);\n\t\t\t\tbreak;\n\t\t\tcase '$Intent':\n\t\t\t\tconst inputs = command.$Intent.inputs;\n\t\t\t\tcommand.$Intent.inputs = {};\n\n\t\t\t\tfor (const [key, value] of Object.entries(inputs)) {\n\t\t\t\t\tcommand.$Intent.inputs[key] = Array.isArray(value)\n\t\t\t\t\t\t? value.map((arg) => fn(arg, command, index))\n\t\t\t\t\t\t: fn(value, command, index);\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\tcase 'Publish':\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unexpected transaction kind: ${(command as { $kind: unknown }).$kind}`);\n\t\t}\n\t}\n\n\tmapArguments(fn: (arg: Argument, command: Command, commandIndex: number) => Argument) {\n\t\tfor (const commandIndex of this.commands.keys()) {\n\t\t\tthis.mapCommandArguments(commandIndex, fn);\n\t\t}\n\t}\n\n\treplaceCommand(index: number, replacement: Command | Command[], resultIndex = index) {\n\t\tif (!Array.isArray(replacement)) {\n\t\t\tthis.commands[index] = replacement;\n\t\t\treturn;\n\t\t}\n\n\t\tconst sizeDiff = replacement.length - 1;\n\t\tthis.commands.splice(index, 1, ...replacement);\n\n\t\tif (sizeDiff !== 0) {\n\t\t\tthis.mapArguments((arg, _command, commandIndex) => {\n\t\t\t\tif (commandIndex < index + replacement.length) {\n\t\t\t\t\treturn arg;\n\t\t\t\t}\n\n\t\t\t\tswitch (arg.$kind) {\n\t\t\t\t\tcase 'Result':\n\t\t\t\t\t\tif (arg.Result === index) {\n\t\t\t\t\t\t\targ.Result = resultIndex;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (arg.Result > index) {\n\t\t\t\t\t\t\targ.Result += sizeDiff;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase 'NestedResult':\n\t\t\t\t\t\tif (arg.NestedResult[0] === index) {\n\t\t\t\t\t\t\targ.NestedResult[0] = resultIndex;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (arg.NestedResult[0] > index) {\n\t\t\t\t\t\t\targ.NestedResult[0] += sizeDiff;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\treturn arg;\n\t\t\t});\n\t\t}\n\t}\n\n\tgetDigest() {\n\t\tconst bytes = this.build({ onlyTransactionKind: false });\n\t\treturn TransactionDataBuilder.getDigestFromBytes(bytes);\n\t}\n\n\tsnapshot(): TransactionData {\n\t\treturn parse(TransactionDataSchema, this);\n\t}\n\n\tshallowClone() {\n\t\treturn new TransactionDataBuilder({\n\t\t\tversion: this.version,\n\t\t\tsender: this.sender,\n\t\t\texpiration: this.expiration,\n\t\t\tgasData: {\n\t\t\t\t...this.gasData,\n\t\t\t},\n\t\t\tinputs: [...this.inputs],\n\t\t\tcommands: [...this.commands],\n\t\t});\n\t}\n\n\tapplyResolvedData(resolved: TransactionData) {\n\t\tif (!this.sender) {\n\t\t\tthis.sender = resolved.sender ?? null;\n\t\t}\n\n\t\tif (!this.expiration) {\n\t\t\tthis.expiration = resolved.expiration ?? null;\n\t\t}\n\n\t\tif (!this.gasData.budget) {\n\t\t\tthis.gasData.budget = resolved.gasData.budget;\n\t\t}\n\n\t\tif (!this.gasData.owner) {\n\t\t\tthis.gasData.owner = resolved.gasData.owner ?? null;\n\t\t}\n\n\t\tif (!this.gasData.payment) {\n\t\t\tthis.gasData.payment = resolved.gasData.payment;\n\t\t}\n\n\t\tif (!this.gasData.price) {\n\t\t\tthis.gasData.price = resolved.gasData.price;\n\t\t}\n\n\t\tfor (let i = 0; i < this.inputs.length; i++) {\n\t\t\tconst input = this.inputs[i];\n\t\t\tconst resolvedInput = resolved.inputs[i];\n\n\t\t\tswitch (input.$kind) {\n\t\t\t\tcase 'UnresolvedPure':\n\t\t\t\t\tif (resolvedInput.$kind !== 'Pure') {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Expected input at index ${i} to resolve to a Pure argument, but got ${JSON.stringify(\n\t\t\t\t\t\t\t\tresolvedInput,\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tthis.inputs[i] = resolvedInput;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'UnresolvedObject':\n\t\t\t\t\tif (resolvedInput.$kind !== 'Object') {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Expected input at index ${i} to resolve to an Object argument, but got ${JSON.stringify(\n\t\t\t\t\t\t\t\tresolvedInput,\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tresolvedInput.Object.$kind === 'ImmOrOwnedObject' ||\n\t\t\t\t\t\tresolvedInput.Object.$kind === 'Receiving'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst original = input.UnresolvedObject;\n\t\t\t\t\t\tconst resolved =\n\t\t\t\t\t\t\tresolvedInput.Object.ImmOrOwnedObject ?? resolvedInput.Object.Receiving!;\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnormalizeSuiAddress(original.objectId) !== normalizeSuiAddress(resolved.objectId) ||\n\t\t\t\t\t\t\t(original.version != null && original.version !== resolved.version) ||\n\t\t\t\t\t\t\t(original.digest != null && original.digest !== resolved.digest) ||\n\t\t\t\t\t\t\t// Objects with shared object properties should not resolve to owned objects\n\t\t\t\t\t\t\toriginal.mutable != null ||\n\t\t\t\t\t\t\toriginal.initialSharedVersion != null\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Input at index ${i} did not match unresolved object. ${JSON.stringify(original)} is not compatible with ${JSON.stringify(resolved)}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (resolvedInput.Object.$kind === 'SharedObject') {\n\t\t\t\t\t\tconst original = input.UnresolvedObject;\n\t\t\t\t\t\tconst resolved = resolvedInput.Object.SharedObject;\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnormalizeSuiAddress(original.objectId) !== normalizeSuiAddress(resolved.objectId) ||\n\t\t\t\t\t\t\t(original.initialSharedVersion != null &&\n\t\t\t\t\t\t\t\toriginal.initialSharedVersion !== resolved.initialSharedVersion) ||\n\t\t\t\t\t\t\t(original.mutable != null && original.mutable !== resolved.mutable) ||\n\t\t\t\t\t\t\t// Objects with owned object properties should not resolve to shared objects\n\t\t\t\t\t\t\toriginal.version != null ||\n\t\t\t\t\t\t\toriginal.digest != null\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Input at index ${i} did not match unresolved object. ${JSON.stringify(original)} is not compatible with ${JSON.stringify(resolved)}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Input at index ${i} resolved to an unexpected Object kind: ${JSON.stringify(\n\t\t\t\t\t\t\t\tresolvedInput.Object,\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.inputs[i] = resolvedInput;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAyB;AAEzB,qBAAsB;AAEtB,IAAAA,cAAoB;AACpB,uBAAoC;AASpC,
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { toBase58 } from '@mysten/bcs';\nimport type { InferInput } from 'valibot';\nimport { parse } from 'valibot';\n\nimport { bcs } from '../bcs/index.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\nimport type {\n\tArgument,\n\tCallArg,\n\tCommand,\n\tGasData,\n\tTransactionExpiration,\n\tTransactionData,\n} from './data/internal.js';\nimport { ArgumentSchema, TransactionDataSchema } from './data/internal.js';\nimport { transactionDataFromV1 } from './data/v1.js';\nimport type { SerializedTransactionDataV1 } from './data/v1.js';\nimport type { SerializedTransactionDataV2Schema } from './data/v2.js';\nimport { hashTypedData } from './hash.js';\nimport { getIdFromCallArg, remapCommandArguments } from './utils.js';\nimport type { TransactionResult } from './Transaction.js';\nfunction prepareSuiAddress(address: string) {\n\treturn normalizeSuiAddress(address).replace('0x', '');\n}\n\nexport class TransactionDataBuilder implements TransactionData {\n\tstatic fromKindBytes(bytes: Uint8Array) {\n\t\tconst kind = bcs.TransactionKind.parse(bytes);\n\n\t\tconst programmableTx = kind.ProgrammableTransaction;\n\t\tif (!programmableTx) {\n\t\t\tthrow new Error('Unable to deserialize from bytes.');\n\t\t}\n\n\t\treturn TransactionDataBuilder.restore({\n\t\t\tversion: 2,\n\t\t\tsender: null,\n\t\t\texpiration: null,\n\t\t\tgasData: {\n\t\t\t\tbudget: null,\n\t\t\t\towner: null,\n\t\t\t\tpayment: null,\n\t\t\t\tprice: null,\n\t\t\t},\n\t\t\tinputs: programmableTx.inputs,\n\t\t\tcommands: programmableTx.commands,\n\t\t});\n\t}\n\n\tstatic fromBytes(bytes: Uint8Array) {\n\t\tconst rawData = bcs.TransactionData.parse(bytes);\n\t\tconst data = rawData?.V1;\n\t\tconst programmableTx = data.kind.ProgrammableTransaction;\n\n\t\tif (!data || !programmableTx) {\n\t\t\tthrow new Error('Unable to deserialize from bytes.');\n\t\t}\n\n\t\treturn TransactionDataBuilder.restore({\n\t\t\tversion: 2,\n\t\t\tsender: data.sender,\n\t\t\texpiration: data.expiration,\n\t\t\tgasData: data.gasData,\n\t\t\tinputs: programmableTx.inputs,\n\t\t\tcommands: programmableTx.commands,\n\t\t});\n\t}\n\n\tstatic restore(\n\t\tdata:\n\t\t\t| InferInput<typeof SerializedTransactionDataV2Schema>\n\t\t\t| InferInput<typeof SerializedTransactionDataV1>,\n\t) {\n\t\tif (data.version === 2) {\n\t\t\treturn new TransactionDataBuilder(parse(TransactionDataSchema, data));\n\t\t} else {\n\t\t\treturn new TransactionDataBuilder(parse(TransactionDataSchema, transactionDataFromV1(data)));\n\t\t}\n\t}\n\n\t/**\n\t * Generate transaction digest.\n\t *\n\t * @param bytes BCS serialized transaction data\n\t * @returns transaction digest.\n\t */\n\tstatic getDigestFromBytes(bytes: Uint8Array) {\n\t\tconst hash = hashTypedData('TransactionData', bytes);\n\t\treturn toBase58(hash);\n\t}\n\n\t// @deprecated use gasData instead\n\tget gasConfig() {\n\t\treturn this.gasData;\n\t}\n\t// @deprecated use gasData instead\n\tset gasConfig(value) {\n\t\tthis.gasData = value;\n\t}\n\n\tversion = 2 as const;\n\tsender: string | null;\n\texpiration: TransactionExpiration | null;\n\tgasData: GasData;\n\tinputs: CallArg[];\n\tcommands: Command[];\n\n\tconstructor(clone?: TransactionData) {\n\t\tthis.sender = clone?.sender ?? null;\n\t\tthis.expiration = clone?.expiration ?? null;\n\t\tthis.inputs = clone?.inputs ?? [];\n\t\tthis.commands = clone?.commands ?? [];\n\t\tthis.gasData = clone?.gasData ?? {\n\t\t\tbudget: null,\n\t\t\tprice: null,\n\t\t\towner: null,\n\t\t\tpayment: null,\n\t\t};\n\t}\n\n\tbuild({\n\t\tmaxSizeBytes = Infinity,\n\t\toverrides,\n\t\tonlyTransactionKind,\n\t}: {\n\t\tmaxSizeBytes?: number;\n\t\toverrides?: {\n\t\t\texpiration?: TransactionExpiration;\n\t\t\tsender?: string;\n\t\t\t// @deprecated use gasData instead\n\t\t\tgasConfig?: Partial<GasData>;\n\t\t\tgasData?: Partial<GasData>;\n\t\t};\n\t\tonlyTransactionKind?: boolean;\n\t} = {}) {\n\t\t// TODO validate that inputs and intents are actually resolved\n\t\tconst inputs = this.inputs as (typeof bcs.CallArg.$inferInput)[];\n\t\tconst commands = this.commands as Extract<\n\t\t\tCommand<Exclude<Argument, { IntentResult: unknown } | { NestedIntentResult: unknown }>>,\n\t\t\t{ Upgrade: unknown }\n\t\t>[];\n\n\t\tconst kind = {\n\t\t\tProgrammableTransaction: {\n\t\t\t\tinputs,\n\t\t\t\tcommands,\n\t\t\t},\n\t\t};\n\n\t\tif (onlyTransactionKind) {\n\t\t\treturn bcs.TransactionKind.serialize(kind, { maxSize: maxSizeBytes }).toBytes();\n\t\t}\n\n\t\tconst expiration = overrides?.expiration ?? this.expiration;\n\t\tconst sender = overrides?.sender ?? this.sender;\n\t\tconst gasData = { ...this.gasData, ...overrides?.gasConfig, ...overrides?.gasData };\n\n\t\tif (!sender) {\n\t\t\tthrow new Error('Missing transaction sender');\n\t\t}\n\n\t\tif (!gasData.budget) {\n\t\t\tthrow new Error('Missing gas budget');\n\t\t}\n\n\t\tif (!gasData.payment) {\n\t\t\tthrow new Error('Missing gas payment');\n\t\t}\n\n\t\tif (!gasData.price) {\n\t\t\tthrow new Error('Missing gas price');\n\t\t}\n\n\t\tconst transactionData = {\n\t\t\tsender: prepareSuiAddress(sender),\n\t\t\texpiration: expiration ? expiration : { None: true },\n\t\t\tgasData: {\n\t\t\t\tpayment: gasData.payment,\n\t\t\t\towner: prepareSuiAddress(this.gasData.owner ?? sender),\n\t\t\t\tprice: BigInt(gasData.price),\n\t\t\t\tbudget: BigInt(gasData.budget),\n\t\t\t},\n\t\t\tkind: {\n\t\t\t\tProgrammableTransaction: {\n\t\t\t\t\tinputs,\n\t\t\t\t\tcommands,\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\treturn bcs.TransactionData.serialize(\n\t\t\t{ V1: transactionData },\n\t\t\t{ maxSize: maxSizeBytes },\n\t\t).toBytes();\n\t}\n\n\taddInput<T extends 'object' | 'pure'>(type: T, arg: CallArg) {\n\t\tconst index = this.inputs.length;\n\t\tthis.inputs.push(arg);\n\t\treturn { Input: index, type, $kind: 'Input' as const };\n\t}\n\n\tgetInputUses(index: number, fn: (arg: Argument, command: Command) => void) {\n\t\tthis.mapArguments((arg, command) => {\n\t\t\tif (arg.$kind === 'Input' && arg.Input === index) {\n\t\t\t\tfn(arg, command);\n\t\t\t}\n\n\t\t\treturn arg;\n\t\t});\n\t}\n\n\tmapCommandArguments(\n\t\tindex: number,\n\t\tfn: (arg: Argument, command: Command, commandIndex: number) => Argument,\n\t) {\n\t\tconst command = this.commands[index];\n\n\t\tswitch (command.$kind) {\n\t\t\tcase 'MoveCall':\n\t\t\t\tcommand.MoveCall.arguments = command.MoveCall.arguments.map((arg) =>\n\t\t\t\t\tfn(arg, command, index),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'TransferObjects':\n\t\t\t\tcommand.TransferObjects.objects = command.TransferObjects.objects.map((arg) =>\n\t\t\t\t\tfn(arg, command, index),\n\t\t\t\t);\n\t\t\t\tcommand.TransferObjects.address = fn(command.TransferObjects.address, command, index);\n\t\t\t\tbreak;\n\t\t\tcase 'SplitCoins':\n\t\t\t\tcommand.SplitCoins.coin = fn(command.SplitCoins.coin, command, index);\n\t\t\t\tcommand.SplitCoins.amounts = command.SplitCoins.amounts.map((arg) =>\n\t\t\t\t\tfn(arg, command, index),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'MergeCoins':\n\t\t\t\tcommand.MergeCoins.destination = fn(command.MergeCoins.destination, command, index);\n\t\t\t\tcommand.MergeCoins.sources = command.MergeCoins.sources.map((arg) =>\n\t\t\t\t\tfn(arg, command, index),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'MakeMoveVec':\n\t\t\t\tcommand.MakeMoveVec.elements = command.MakeMoveVec.elements.map((arg) =>\n\t\t\t\t\tfn(arg, command, index),\n\t\t\t\t);\n\t\t\t\tbreak;\n\t\t\tcase 'Upgrade':\n\t\t\t\tcommand.Upgrade.ticket = fn(command.Upgrade.ticket, command, index);\n\t\t\t\tbreak;\n\t\t\tcase '$Intent':\n\t\t\t\tconst inputs = command.$Intent.inputs;\n\t\t\t\tcommand.$Intent.inputs = {};\n\n\t\t\t\tfor (const [key, value] of Object.entries(inputs)) {\n\t\t\t\t\tcommand.$Intent.inputs[key] = Array.isArray(value)\n\t\t\t\t\t\t? value.map((arg) => fn(arg, command, index))\n\t\t\t\t\t\t: fn(value, command, index);\n\t\t\t\t}\n\n\t\t\t\tbreak;\n\t\t\tcase 'Publish':\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unexpected transaction kind: ${(command as { $kind: unknown }).$kind}`);\n\t\t}\n\t}\n\n\tmapArguments(fn: (arg: Argument, command: Command, commandIndex: number) => Argument) {\n\t\tfor (const commandIndex of this.commands.keys()) {\n\t\t\tthis.mapCommandArguments(commandIndex, fn);\n\t\t}\n\t}\n\n\treplaceCommand(\n\t\tindex: number,\n\t\treplacement: Command | Command[],\n\t\tresultIndex: number | { Result: number } | { NestedResult: [number, number] } = index,\n\t) {\n\t\tif (!Array.isArray(replacement)) {\n\t\t\tthis.commands[index] = replacement;\n\t\t\treturn;\n\t\t}\n\n\t\tconst sizeDiff = replacement.length - 1;\n\n\t\tthis.commands.splice(index, 1, ...structuredClone(replacement));\n\n\t\tthis.mapArguments((arg, _command, commandIndex) => {\n\t\t\tif (commandIndex < index + replacement.length) {\n\t\t\t\treturn arg;\n\t\t\t}\n\n\t\t\tif (typeof resultIndex !== 'number') {\n\t\t\t\tif (\n\t\t\t\t\t(arg.$kind === 'Result' && arg.Result === index) ||\n\t\t\t\t\t(arg.$kind === 'NestedResult' && arg.NestedResult[0] === index)\n\t\t\t\t) {\n\t\t\t\t\tif (!('NestedResult' in arg) || arg.NestedResult[1] === 0) {\n\t\t\t\t\t\treturn parse(ArgumentSchema, structuredClone(resultIndex));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Cannot replace command ${index} with a specific result type: NestedResult[${index}, ${arg.NestedResult[1]}] references a nested element that cannot be mapped to the replacement result`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Handle adjustment of other references\n\t\t\tswitch (arg.$kind) {\n\t\t\t\tcase 'Result':\n\t\t\t\t\tif (arg.Result === index && typeof resultIndex === 'number') {\n\t\t\t\t\t\targ.Result = resultIndex;\n\t\t\t\t\t}\n\t\t\t\t\tif (arg.Result > index) {\n\t\t\t\t\t\targ.Result += sizeDiff;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\n\t\t\t\tcase 'NestedResult':\n\t\t\t\t\tif (arg.NestedResult[0] === index && typeof resultIndex === 'number') {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t$kind: 'NestedResult',\n\t\t\t\t\t\t\tNestedResult: [resultIndex, arg.NestedResult[1]],\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tif (arg.NestedResult[0] > index) {\n\t\t\t\t\t\targ.NestedResult[0] += sizeDiff;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\treturn arg;\n\t\t});\n\t}\n\n\treplaceCommandWithTransaction(\n\t\tindex: number,\n\t\totherTransaction: TransactionData,\n\t\tresult: TransactionResult,\n\t) {\n\t\tif (result.$kind !== 'Result' && result.$kind !== 'NestedResult') {\n\t\t\tthrow new Error('Result must be of kind Result or NestedResult');\n\t\t}\n\n\t\tthis.insertTransaction(index, otherTransaction);\n\n\t\tthis.replaceCommand(\n\t\t\tindex + otherTransaction.commands.length,\n\t\t\t[],\n\t\t\t'Result' in result\n\t\t\t\t? { NestedResult: [result.Result + index, 0] }\n\t\t\t\t: {\n\t\t\t\t\t\tNestedResult: [\n\t\t\t\t\t\t\t(result as { NestedResult: [number, number] }).NestedResult[0] + index,\n\t\t\t\t\t\t\t(result as { NestedResult: [number, number] }).NestedResult[1],\n\t\t\t\t\t\t] as [number, number],\n\t\t\t\t\t},\n\t\t);\n\t}\n\n\tinsertTransaction(atCommandIndex: number, otherTransaction: TransactionData) {\n\t\tconst inputMapping = new Map<number, number>();\n\t\tconst commandMapping = new Map<number, number>();\n\n\t\tfor (let i = 0; i < otherTransaction.inputs.length; i++) {\n\t\t\tconst otherInput = otherTransaction.inputs[i];\n\t\t\tconst id = getIdFromCallArg(otherInput);\n\n\t\t\tlet existingIndex = -1;\n\t\t\tif (id !== undefined) {\n\t\t\t\texistingIndex = this.inputs.findIndex((input) => getIdFromCallArg(input) === id);\n\n\t\t\t\tif (\n\t\t\t\t\texistingIndex !== -1 &&\n\t\t\t\t\tthis.inputs[existingIndex].Object?.SharedObject &&\n\t\t\t\t\totherInput.Object?.SharedObject\n\t\t\t\t) {\n\t\t\t\t\tthis.inputs[existingIndex].Object!.SharedObject!.mutable =\n\t\t\t\t\t\tthis.inputs[existingIndex].Object!.SharedObject!.mutable ||\n\t\t\t\t\t\totherInput.Object.SharedObject.mutable;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (existingIndex !== -1) {\n\t\t\t\tinputMapping.set(i, existingIndex);\n\t\t\t} else {\n\t\t\t\tconst newIndex = this.inputs.length;\n\t\t\t\tthis.inputs.push(otherInput);\n\t\t\t\tinputMapping.set(i, newIndex);\n\t\t\t}\n\t\t}\n\n\t\tfor (let i = 0; i < otherTransaction.commands.length; i++) {\n\t\t\tcommandMapping.set(i, atCommandIndex + i);\n\t\t}\n\n\t\tconst remappedCommands: Command[] = [];\n\t\tfor (let i = 0; i < otherTransaction.commands.length; i++) {\n\t\t\tconst command = structuredClone(otherTransaction.commands[i]);\n\n\t\t\tremapCommandArguments(command, inputMapping, commandMapping);\n\n\t\t\tremappedCommands.push(command);\n\t\t}\n\n\t\tthis.commands.splice(atCommandIndex, 0, ...remappedCommands);\n\n\t\tconst sizeDiff = remappedCommands.length;\n\t\tif (sizeDiff > 0) {\n\t\t\tthis.mapArguments((arg, _command, commandIndex) => {\n\t\t\t\tif (\n\t\t\t\t\tcommandIndex >= atCommandIndex &&\n\t\t\t\t\tcommandIndex < atCommandIndex + remappedCommands.length\n\t\t\t\t) {\n\t\t\t\t\treturn arg;\n\t\t\t\t}\n\n\t\t\t\tswitch (arg.$kind) {\n\t\t\t\t\tcase 'Result':\n\t\t\t\t\t\tif (arg.Result >= atCommandIndex) {\n\t\t\t\t\t\t\targ.Result += sizeDiff;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\tcase 'NestedResult':\n\t\t\t\t\t\tif (arg.NestedResult[0] >= atCommandIndex) {\n\t\t\t\t\t\t\targ.NestedResult[0] += sizeDiff;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\treturn arg;\n\t\t\t});\n\t\t}\n\t}\n\n\tgetDigest() {\n\t\tconst bytes = this.build({ onlyTransactionKind: false });\n\t\treturn TransactionDataBuilder.getDigestFromBytes(bytes);\n\t}\n\n\tsnapshot(): TransactionData {\n\t\treturn parse(TransactionDataSchema, this);\n\t}\n\n\tshallowClone() {\n\t\treturn new TransactionDataBuilder({\n\t\t\tversion: this.version,\n\t\t\tsender: this.sender,\n\t\t\texpiration: this.expiration,\n\t\t\tgasData: {\n\t\t\t\t...this.gasData,\n\t\t\t},\n\t\t\tinputs: [...this.inputs],\n\t\t\tcommands: [...this.commands],\n\t\t});\n\t}\n\n\tapplyResolvedData(resolved: TransactionData) {\n\t\tif (!this.sender) {\n\t\t\tthis.sender = resolved.sender ?? null;\n\t\t}\n\n\t\tif (!this.expiration) {\n\t\t\tthis.expiration = resolved.expiration ?? null;\n\t\t}\n\n\t\tif (!this.gasData.budget) {\n\t\t\tthis.gasData.budget = resolved.gasData.budget;\n\t\t}\n\n\t\tif (!this.gasData.owner) {\n\t\t\tthis.gasData.owner = resolved.gasData.owner ?? null;\n\t\t}\n\n\t\tif (!this.gasData.payment) {\n\t\t\tthis.gasData.payment = resolved.gasData.payment;\n\t\t}\n\n\t\tif (!this.gasData.price) {\n\t\t\tthis.gasData.price = resolved.gasData.price;\n\t\t}\n\n\t\tfor (let i = 0; i < this.inputs.length; i++) {\n\t\t\tconst input = this.inputs[i];\n\t\t\tconst resolvedInput = resolved.inputs[i];\n\n\t\t\tswitch (input.$kind) {\n\t\t\t\tcase 'UnresolvedPure':\n\t\t\t\t\tif (resolvedInput.$kind !== 'Pure') {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Expected input at index ${i} to resolve to a Pure argument, but got ${JSON.stringify(\n\t\t\t\t\t\t\t\tresolvedInput,\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tthis.inputs[i] = resolvedInput;\n\t\t\t\t\tbreak;\n\t\t\t\tcase 'UnresolvedObject':\n\t\t\t\t\tif (resolvedInput.$kind !== 'Object') {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Expected input at index ${i} to resolve to an Object argument, but got ${JSON.stringify(\n\t\t\t\t\t\t\t\tresolvedInput,\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tresolvedInput.Object.$kind === 'ImmOrOwnedObject' ||\n\t\t\t\t\t\tresolvedInput.Object.$kind === 'Receiving'\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst original = input.UnresolvedObject;\n\t\t\t\t\t\tconst resolved =\n\t\t\t\t\t\t\tresolvedInput.Object.ImmOrOwnedObject ?? resolvedInput.Object.Receiving!;\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnormalizeSuiAddress(original.objectId) !== normalizeSuiAddress(resolved.objectId) ||\n\t\t\t\t\t\t\t(original.version != null && original.version !== resolved.version) ||\n\t\t\t\t\t\t\t(original.digest != null && original.digest !== resolved.digest) ||\n\t\t\t\t\t\t\t// Objects with shared object properties should not resolve to owned objects\n\t\t\t\t\t\t\toriginal.mutable != null ||\n\t\t\t\t\t\t\toriginal.initialSharedVersion != null\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Input at index ${i} did not match unresolved object. ${JSON.stringify(original)} is not compatible with ${JSON.stringify(resolved)}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (resolvedInput.Object.$kind === 'SharedObject') {\n\t\t\t\t\t\tconst original = input.UnresolvedObject;\n\t\t\t\t\t\tconst resolved = resolvedInput.Object.SharedObject;\n\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tnormalizeSuiAddress(original.objectId) !== normalizeSuiAddress(resolved.objectId) ||\n\t\t\t\t\t\t\t(original.initialSharedVersion != null &&\n\t\t\t\t\t\t\t\toriginal.initialSharedVersion !== resolved.initialSharedVersion) ||\n\t\t\t\t\t\t\t(original.mutable != null && original.mutable !== resolved.mutable) ||\n\t\t\t\t\t\t\t// Objects with owned object properties should not resolve to shared objects\n\t\t\t\t\t\t\toriginal.version != null ||\n\t\t\t\t\t\t\toriginal.digest != null\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t\t`Input at index ${i} did not match unresolved object. ${JSON.stringify(original)} is not compatible with ${JSON.stringify(resolved)}`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`Input at index ${i} resolved to an unexpected Object kind: ${JSON.stringify(\n\t\t\t\t\t\t\t\tresolvedInput.Object,\n\t\t\t\t\t\t\t)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.inputs[i] = resolvedInput;\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAAyB;AAEzB,qBAAsB;AAEtB,IAAAA,cAAoB;AACpB,uBAAoC;AASpC,sBAAsD;AACtD,gBAAsC;AAGtC,kBAA8B;AAC9B,mBAAwD;AAExD,SAAS,kBAAkB,SAAiB;AAC3C,aAAO,sCAAoB,OAAO,EAAE,QAAQ,MAAM,EAAE;AACrD;AAEO,MAAM,uBAAkD;AAAA,EAkF9D,YAAY,OAAyB;AAPrC,mBAAU;AAQT,SAAK,SAAS,OAAO,UAAU;AAC/B,SAAK,aAAa,OAAO,cAAc;AACvC,SAAK,SAAS,OAAO,UAAU,CAAC;AAChC,SAAK,WAAW,OAAO,YAAY,CAAC;AACpC,SAAK,UAAU,OAAO,WAAW;AAAA,MAChC,QAAQ;AAAA,MACR,OAAO;AAAA,MACP,OAAO;AAAA,MACP,SAAS;AAAA,IACV;AAAA,EACD;AAAA,EA5FA,OAAO,cAAc,OAAmB;AACvC,UAAM,OAAO,gBAAI,gBAAgB,MAAM,KAAK;AAE5C,UAAM,iBAAiB,K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AAoB,SAAS,QAAQ,UAAM,sCAAoBA,UAAS,QAAQ,KAC/E,SAAS,wBAAwB,QACjC,SAAS,yBAAyBA,UAAS,wBAC3C,SAAS,WAAW,QAAQ,SAAS,YAAYA,UAAS;AAAA,YAE3D,SAAS,WAAW,QACpB,SAAS,UAAU,MAClB;AACD,oBAAM,IAAI;AAAA,gBACT,kBAAkB,CAAC,qCAAqC,KAAK,UAAU,QAAQ,CAAC,2BAA2B,KAAK,UAAUA,SAAQ,CAAC;AAAA,cACpI;AAAA,YACD;AAAA,UACD,OAAO;AACN,kBAAM,IAAI;AAAA,cACT,kBAAkB,CAAC,2CAA2C,KAAK;AAAA,gBAClE,cAAc;AAAA,cACf,CAAC;AAAA,YACF;AAAA,UACD;AAEA,eAAK,OAAO,CAAC,IAAI;AACjB;AAAA,MACF;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["import_bcs", "resolved"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SuiMoveNormalizedType } from '../client/index.js';
|
|
2
|
-
import type { Argument, CallArg } from './data/internal.js';
|
|
2
|
+
import type { Argument, CallArg, Command } from './data/internal.js';
|
|
3
3
|
export declare function extractMutableReference(normalizedType: SuiMoveNormalizedType): SuiMoveNormalizedType | undefined;
|
|
4
4
|
export declare function extractReference(normalizedType: SuiMoveNormalizedType): SuiMoveNormalizedType | undefined;
|
|
5
5
|
export declare function extractStructTag(normalizedType: SuiMoveNormalizedType): Extract<SuiMoveNormalizedType, {
|
|
@@ -7,3 +7,4 @@ export declare function extractStructTag(normalizedType: SuiMoveNormalizedType):
|
|
|
7
7
|
}> | undefined;
|
|
8
8
|
export declare function getIdFromCallArg(arg: string | CallArg): string | undefined;
|
|
9
9
|
export declare function isArgument(value: unknown): value is Argument;
|
|
10
|
+
export declare function remapCommandArguments(command: Command, inputMapping: Map<number, number>, commandMapping: Map<number, number>): void;
|
|
@@ -22,7 +22,8 @@ __export(utils_exports, {
|
|
|
22
22
|
extractReference: () => extractReference,
|
|
23
23
|
extractStructTag: () => extractStructTag,
|
|
24
24
|
getIdFromCallArg: () => getIdFromCallArg,
|
|
25
|
-
isArgument: () => isArgument
|
|
25
|
+
isArgument: () => isArgument,
|
|
26
|
+
remapCommandArguments: () => remapCommandArguments
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(utils_exports);
|
|
28
29
|
var import_valibot = require("valibot");
|
|
@@ -69,4 +70,66 @@ function getIdFromCallArg(arg) {
|
|
|
69
70
|
function isArgument(value) {
|
|
70
71
|
return (0, import_valibot.is)(import_internal.ArgumentSchema, value);
|
|
71
72
|
}
|
|
73
|
+
function remapCommandArguments(command, inputMapping, commandMapping) {
|
|
74
|
+
const remapArg = (arg) => {
|
|
75
|
+
switch (arg.$kind) {
|
|
76
|
+
case "Input": {
|
|
77
|
+
const newInputIndex = inputMapping.get(arg.Input);
|
|
78
|
+
if (newInputIndex === void 0) {
|
|
79
|
+
throw new Error(`Input ${arg.Input} not found in input mapping`);
|
|
80
|
+
}
|
|
81
|
+
return { ...arg, Input: newInputIndex };
|
|
82
|
+
}
|
|
83
|
+
case "Result": {
|
|
84
|
+
const newCommandIndex = commandMapping.get(arg.Result);
|
|
85
|
+
if (newCommandIndex !== void 0) {
|
|
86
|
+
return { ...arg, Result: newCommandIndex };
|
|
87
|
+
}
|
|
88
|
+
return arg;
|
|
89
|
+
}
|
|
90
|
+
case "NestedResult": {
|
|
91
|
+
const newCommandIndex = commandMapping.get(arg.NestedResult[0]);
|
|
92
|
+
if (newCommandIndex !== void 0) {
|
|
93
|
+
return { ...arg, NestedResult: [newCommandIndex, arg.NestedResult[1]] };
|
|
94
|
+
}
|
|
95
|
+
return arg;
|
|
96
|
+
}
|
|
97
|
+
default:
|
|
98
|
+
return arg;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
switch (command.$kind) {
|
|
102
|
+
case "MoveCall":
|
|
103
|
+
command.MoveCall.arguments = command.MoveCall.arguments.map(remapArg);
|
|
104
|
+
break;
|
|
105
|
+
case "TransferObjects":
|
|
106
|
+
command.TransferObjects.objects = command.TransferObjects.objects.map(remapArg);
|
|
107
|
+
command.TransferObjects.address = remapArg(command.TransferObjects.address);
|
|
108
|
+
break;
|
|
109
|
+
case "SplitCoins":
|
|
110
|
+
command.SplitCoins.coin = remapArg(command.SplitCoins.coin);
|
|
111
|
+
command.SplitCoins.amounts = command.SplitCoins.amounts.map(remapArg);
|
|
112
|
+
break;
|
|
113
|
+
case "MergeCoins":
|
|
114
|
+
command.MergeCoins.destination = remapArg(command.MergeCoins.destination);
|
|
115
|
+
command.MergeCoins.sources = command.MergeCoins.sources.map(remapArg);
|
|
116
|
+
break;
|
|
117
|
+
case "MakeMoveVec":
|
|
118
|
+
command.MakeMoveVec.elements = command.MakeMoveVec.elements.map(remapArg);
|
|
119
|
+
break;
|
|
120
|
+
case "Upgrade":
|
|
121
|
+
command.Upgrade.ticket = remapArg(command.Upgrade.ticket);
|
|
122
|
+
break;
|
|
123
|
+
case "$Intent": {
|
|
124
|
+
const inputs = command.$Intent.inputs;
|
|
125
|
+
command.$Intent.inputs = {};
|
|
126
|
+
for (const [key, value] of Object.entries(inputs)) {
|
|
127
|
+
command.$Intent.inputs[key] = Array.isArray(value) ? value.map(remapArg) : remapArg(value);
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case "Publish":
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
72
135
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/transactions/utils.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { is } from 'valibot';\n\nimport type { SuiMoveNormalizedType } from '../client/index.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\nimport { ArgumentSchema } from './data/internal.js';\nimport type { Argument, CallArg } from './data/internal.js';\n\nexport function extractMutableReference(\n\tnormalizedType: SuiMoveNormalizedType,\n): SuiMoveNormalizedType | undefined {\n\treturn typeof normalizedType === 'object' && 'MutableReference' in normalizedType\n\t\t? normalizedType.MutableReference\n\t\t: undefined;\n}\n\nexport function extractReference(\n\tnormalizedType: SuiMoveNormalizedType,\n): SuiMoveNormalizedType | undefined {\n\treturn typeof normalizedType === 'object' && 'Reference' in normalizedType\n\t\t? normalizedType.Reference\n\t\t: undefined;\n}\n\nexport function extractStructTag(\n\tnormalizedType: SuiMoveNormalizedType,\n): Extract<SuiMoveNormalizedType, { Struct: unknown }> | undefined {\n\tif (typeof normalizedType === 'object' && 'Struct' in normalizedType) {\n\t\treturn normalizedType;\n\t}\n\n\tconst ref = extractReference(normalizedType);\n\tconst mutRef = extractMutableReference(normalizedType);\n\n\tif (typeof ref === 'object' && 'Struct' in ref) {\n\t\treturn ref;\n\t}\n\n\tif (typeof mutRef === 'object' && 'Struct' in mutRef) {\n\t\treturn mutRef;\n\t}\n\treturn undefined;\n}\n\nexport function getIdFromCallArg(arg: string | CallArg) {\n\tif (typeof arg === 'string') {\n\t\treturn normalizeSuiAddress(arg);\n\t}\n\n\tif (arg.Object) {\n\t\tif (arg.Object.ImmOrOwnedObject) {\n\t\t\treturn normalizeSuiAddress(arg.Object.ImmOrOwnedObject.objectId);\n\t\t}\n\n\t\tif (arg.Object.Receiving) {\n\t\t\treturn normalizeSuiAddress(arg.Object.Receiving.objectId);\n\t\t}\n\n\t\treturn normalizeSuiAddress(arg.Object.SharedObject.objectId);\n\t}\n\n\tif (arg.UnresolvedObject) {\n\t\treturn normalizeSuiAddress(arg.UnresolvedObject.objectId);\n\t}\n\n\treturn undefined;\n}\n\nexport function isArgument(value: unknown): value is Argument {\n\treturn is(ArgumentSchema, value);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAmB;AAGnB,uBAAoC;AACpC,sBAA+B;AAGxB,SAAS,wBACf,gBACoC;AACpC,SAAO,OAAO,mBAAmB,YAAY,sBAAsB,iBAChE,eAAe,mBACf;AACJ;AAEO,SAAS,iBACf,gBACoC;AACpC,SAAO,OAAO,mBAAmB,YAAY,eAAe,iBACzD,eAAe,YACf;AACJ;AAEO,SAAS,iBACf,gBACkE;AAClE,MAAI,OAAO,mBAAmB,YAAY,YAAY,gBAAgB;AACrE,WAAO;AAAA,EACR;AAEA,QAAM,MAAM,iBAAiB,cAAc;AAC3C,QAAM,SAAS,wBAAwB,cAAc;AAErD,MAAI,OAAO,QAAQ,YAAY,YAAY,KAAK;AAC/C,WAAO;AAAA,EACR;AAEA,MAAI,OAAO,WAAW,YAAY,YAAY,QAAQ;AACrD,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAEO,SAAS,iBAAiB,KAAuB;AACvD,MAAI,OAAO,QAAQ,UAAU;AAC5B,eAAO,sCAAoB,GAAG;AAAA,EAC/B;AAEA,MAAI,IAAI,QAAQ;AACf,QAAI,IAAI,OAAO,kBAAkB;AAChC,iBAAO,sCAAoB,IAAI,OAAO,iBAAiB,QAAQ;AAAA,IAChE;AAEA,QAAI,IAAI,OAAO,WAAW;AACzB,iBAAO,sCAAoB,IAAI,OAAO,UAAU,QAAQ;AAAA,IACzD;AAEA,eAAO,sCAAoB,IAAI,OAAO,aAAa,QAAQ;AAAA,EAC5D;AAEA,MAAI,IAAI,kBAAkB;AACzB,eAAO,sCAAoB,IAAI,iBAAiB,QAAQ;AAAA,EACzD;AAEA,SAAO;AACR;AAEO,SAAS,WAAW,OAAmC;AAC7D,aAAO,mBAAG,gCAAgB,KAAK;AAChC;",
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { is } from 'valibot';\n\nimport type { SuiMoveNormalizedType } from '../client/index.js';\nimport { normalizeSuiAddress } from '../utils/sui-types.js';\nimport { ArgumentSchema } from './data/internal.js';\nimport type { Argument, CallArg, Command } from './data/internal.js';\n\nexport function extractMutableReference(\n\tnormalizedType: SuiMoveNormalizedType,\n): SuiMoveNormalizedType | undefined {\n\treturn typeof normalizedType === 'object' && 'MutableReference' in normalizedType\n\t\t? normalizedType.MutableReference\n\t\t: undefined;\n}\n\nexport function extractReference(\n\tnormalizedType: SuiMoveNormalizedType,\n): SuiMoveNormalizedType | undefined {\n\treturn typeof normalizedType === 'object' && 'Reference' in normalizedType\n\t\t? normalizedType.Reference\n\t\t: undefined;\n}\n\nexport function extractStructTag(\n\tnormalizedType: SuiMoveNormalizedType,\n): Extract<SuiMoveNormalizedType, { Struct: unknown }> | undefined {\n\tif (typeof normalizedType === 'object' && 'Struct' in normalizedType) {\n\t\treturn normalizedType;\n\t}\n\n\tconst ref = extractReference(normalizedType);\n\tconst mutRef = extractMutableReference(normalizedType);\n\n\tif (typeof ref === 'object' && 'Struct' in ref) {\n\t\treturn ref;\n\t}\n\n\tif (typeof mutRef === 'object' && 'Struct' in mutRef) {\n\t\treturn mutRef;\n\t}\n\treturn undefined;\n}\n\nexport function getIdFromCallArg(arg: string | CallArg) {\n\tif (typeof arg === 'string') {\n\t\treturn normalizeSuiAddress(arg);\n\t}\n\n\tif (arg.Object) {\n\t\tif (arg.Object.ImmOrOwnedObject) {\n\t\t\treturn normalizeSuiAddress(arg.Object.ImmOrOwnedObject.objectId);\n\t\t}\n\n\t\tif (arg.Object.Receiving) {\n\t\t\treturn normalizeSuiAddress(arg.Object.Receiving.objectId);\n\t\t}\n\n\t\treturn normalizeSuiAddress(arg.Object.SharedObject.objectId);\n\t}\n\n\tif (arg.UnresolvedObject) {\n\t\treturn normalizeSuiAddress(arg.UnresolvedObject.objectId);\n\t}\n\n\treturn undefined;\n}\n\nexport function isArgument(value: unknown): value is Argument {\n\treturn is(ArgumentSchema, value);\n}\n\nexport function remapCommandArguments(\n\tcommand: Command,\n\tinputMapping: Map<number, number>,\n\tcommandMapping: Map<number, number>,\n) {\n\tconst remapArg = (arg: Argument): Argument => {\n\t\tswitch (arg.$kind) {\n\t\t\tcase 'Input': {\n\t\t\t\tconst newInputIndex = inputMapping.get(arg.Input);\n\t\t\t\tif (newInputIndex === undefined) {\n\t\t\t\t\tthrow new Error(`Input ${arg.Input} not found in input mapping`);\n\t\t\t\t}\n\t\t\t\treturn { ...arg, Input: newInputIndex };\n\t\t\t}\n\t\t\tcase 'Result': {\n\t\t\t\tconst newCommandIndex = commandMapping.get(arg.Result);\n\t\t\t\tif (newCommandIndex !== undefined) {\n\t\t\t\t\treturn { ...arg, Result: newCommandIndex };\n\t\t\t\t}\n\t\t\t\treturn arg;\n\t\t\t}\n\t\t\tcase 'NestedResult': {\n\t\t\t\tconst newCommandIndex = commandMapping.get(arg.NestedResult[0]);\n\t\t\t\tif (newCommandIndex !== undefined) {\n\t\t\t\t\treturn { ...arg, NestedResult: [newCommandIndex, arg.NestedResult[1]] };\n\t\t\t\t}\n\t\t\t\treturn arg;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn arg;\n\t\t}\n\t};\n\n\tswitch (command.$kind) {\n\t\tcase 'MoveCall':\n\t\t\tcommand.MoveCall.arguments = command.MoveCall.arguments.map(remapArg);\n\t\t\tbreak;\n\t\tcase 'TransferObjects':\n\t\t\tcommand.TransferObjects.objects = command.TransferObjects.objects.map(remapArg);\n\t\t\tcommand.TransferObjects.address = remapArg(command.TransferObjects.address);\n\t\t\tbreak;\n\t\tcase 'SplitCoins':\n\t\t\tcommand.SplitCoins.coin = remapArg(command.SplitCoins.coin);\n\t\t\tcommand.SplitCoins.amounts = command.SplitCoins.amounts.map(remapArg);\n\t\t\tbreak;\n\t\tcase 'MergeCoins':\n\t\t\tcommand.MergeCoins.destination = remapArg(command.MergeCoins.destination);\n\t\t\tcommand.MergeCoins.sources = command.MergeCoins.sources.map(remapArg);\n\t\t\tbreak;\n\t\tcase 'MakeMoveVec':\n\t\t\tcommand.MakeMoveVec.elements = command.MakeMoveVec.elements.map(remapArg);\n\t\t\tbreak;\n\t\tcase 'Upgrade':\n\t\t\tcommand.Upgrade.ticket = remapArg(command.Upgrade.ticket);\n\t\t\tbreak;\n\t\tcase '$Intent': {\n\t\t\tconst inputs = command.$Intent.inputs;\n\t\t\tcommand.$Intent.inputs = {};\n\n\t\t\tfor (const [key, value] of Object.entries(inputs)) {\n\t\t\t\tcommand.$Intent.inputs[key] = Array.isArray(value) ? value.map(remapArg) : remapArg(value);\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcase 'Publish':\n\t\t\tbreak;\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAmB;AAGnB,uBAAoC;AACpC,sBAA+B;AAGxB,SAAS,wBACf,gBACoC;AACpC,SAAO,OAAO,mBAAmB,YAAY,sBAAsB,iBAChE,eAAe,mBACf;AACJ;AAEO,SAAS,iBACf,gBACoC;AACpC,SAAO,OAAO,mBAAmB,YAAY,eAAe,iBACzD,eAAe,YACf;AACJ;AAEO,SAAS,iBACf,gBACkE;AAClE,MAAI,OAAO,mBAAmB,YAAY,YAAY,gBAAgB;AACrE,WAAO;AAAA,EACR;AAEA,QAAM,MAAM,iBAAiB,cAAc;AAC3C,QAAM,SAAS,wBAAwB,cAAc;AAErD,MAAI,OAAO,QAAQ,YAAY,YAAY,KAAK;AAC/C,WAAO;AAAA,EACR;AAEA,MAAI,OAAO,WAAW,YAAY,YAAY,QAAQ;AACrD,WAAO;AAAA,EACR;AACA,SAAO;AACR;AAEO,SAAS,iBAAiB,KAAuB;AACvD,MAAI,OAAO,QAAQ,UAAU;AAC5B,eAAO,sCAAoB,GAAG;AAAA,EAC/B;AAEA,MAAI,IAAI,QAAQ;AACf,QAAI,IAAI,OAAO,kBAAkB;AAChC,iBAAO,sCAAoB,IAAI,OAAO,iBAAiB,QAA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BAAgB,QAAQ,IAAI,QAAQ;AAC9E,cAAQ,gBAAgB,UAAU,SAAS,QAAQ,gBAAgB,OAAO;AAC1E;AAAA,IACD,KAAK;AACJ,cAAQ,WAAW,OAAO,SAAS,QAAQ,WAAW,IAAI;AAC1D,cAAQ,WAAW,UAAU,QAAQ,WAAW,QAAQ,IAAI,QAAQ;AACpE;AAAA,IACD,KAAK;AACJ,cAAQ,WAAW,cAAc,SAAS,QAAQ,WAAW,WAAW;AACxE,cAAQ,WAAW,UAAU,QAAQ,WAAW,QAAQ,IAAI,QAAQ;AACpE;AAAA,IACD,KAAK;AACJ,cAAQ,YAAY,WAAW,QAAQ,YAAY,SAAS,IAAI,QAAQ;AACxE;AAAA,IACD,KAAK;AACJ,cAAQ,QAAQ,SAAS,SAAS,QAAQ,QAAQ,MAAM;AACxD;AAAA,IACD,KAAK,WAAW;AACf,YAAM,SAAS,QAAQ,QAAQ;AAC/B,cAAQ,QAAQ,SAAS,CAAC;AAE1B,iBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,MAAM,GAAG;AAClD,gBAAQ,QAAQ,OAAO,GAAG,IAAI,MAAM,QAAQ,KAAK,IAAI,MAAM,IAAI,QAAQ,IAAI,SAAS,KAAK;AAAA,MAC1F;AACA;AAAA,IACD;AAAA,IACA,KAAK;AACJ;AAAA,EACF;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const PACKAGE_VERSION = "1.
|
|
1
|
+
export declare const PACKAGE_VERSION = "1.45.0";
|
|
2
2
|
export declare const TARGETED_RPC_VERSION = "1.61.0";
|
package/dist/cjs/version.js
CHANGED
|
@@ -22,6 +22,6 @@ __export(version_exports, {
|
|
|
22
22
|
TARGETED_RPC_VERSION: () => TARGETED_RPC_VERSION
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(version_exports);
|
|
25
|
-
const PACKAGE_VERSION = "1.
|
|
25
|
+
const PACKAGE_VERSION = "1.45.0";
|
|
26
26
|
const TARGETED_RPC_VERSION = "1.61.0";
|
|
27
27
|
//# sourceMappingURL=version.js.map
|
package/dist/cjs/version.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/version.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '1.
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '1.45.0';\nexport const TARGETED_RPC_VERSION = '1.61.0';\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,MAAM,kBAAkB;AACxB,MAAM,uBAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,7 @@ import type { InferInput } from 'valibot';
|
|
|
2
2
|
import type { Argument, CallArg, Command, GasData, TransactionExpiration, TransactionData } from './data/internal.js';
|
|
3
3
|
import type { SerializedTransactionDataV1 } from './data/v1.js';
|
|
4
4
|
import type { SerializedTransactionDataV2Schema } from './data/v2.js';
|
|
5
|
+
import type { TransactionResult } from './Transaction.js';
|
|
5
6
|
export declare class TransactionDataBuilder implements TransactionData {
|
|
6
7
|
static fromKindBytes(bytes: Uint8Array): TransactionDataBuilder;
|
|
7
8
|
static fromBytes(bytes: Uint8Array): TransactionDataBuilder;
|
|
@@ -58,7 +59,13 @@ export declare class TransactionDataBuilder implements TransactionData {
|
|
|
58
59
|
getInputUses(index: number, fn: (arg: Argument, command: Command) => void): void;
|
|
59
60
|
mapCommandArguments(index: number, fn: (arg: Argument, command: Command, commandIndex: number) => Argument): void;
|
|
60
61
|
mapArguments(fn: (arg: Argument, command: Command, commandIndex: number) => Argument): void;
|
|
61
|
-
replaceCommand(index: number, replacement: Command | Command[], resultIndex?: number
|
|
62
|
+
replaceCommand(index: number, replacement: Command | Command[], resultIndex?: number | {
|
|
63
|
+
Result: number;
|
|
64
|
+
} | {
|
|
65
|
+
NestedResult: [number, number];
|
|
66
|
+
}): void;
|
|
67
|
+
replaceCommandWithTransaction(index: number, otherTransaction: TransactionData, result: TransactionResult): void;
|
|
68
|
+
insertTransaction(atCommandIndex: number, otherTransaction: TransactionData): void;
|
|
62
69
|
getDigest(): string;
|
|
63
70
|
snapshot(): TransactionData;
|
|
64
71
|
shallowClone(): TransactionDataBuilder;
|
|
@@ -2,9 +2,10 @@ import { toBase58 } from "@mysten/bcs";
|
|
|
2
2
|
import { parse } from "valibot";
|
|
3
3
|
import { bcs } from "../bcs/index.js";
|
|
4
4
|
import { normalizeSuiAddress } from "../utils/sui-types.js";
|
|
5
|
-
import { TransactionDataSchema } from "./data/internal.js";
|
|
5
|
+
import { ArgumentSchema, TransactionDataSchema } from "./data/internal.js";
|
|
6
6
|
import { transactionDataFromV1 } from "./data/v1.js";
|
|
7
7
|
import { hashTypedData } from "./hash.js";
|
|
8
|
+
import { getIdFromCallArg, remapCommandArguments } from "./utils.js";
|
|
8
9
|
function prepareSuiAddress(address) {
|
|
9
10
|
return normalizeSuiAddress(address).replace("0x", "");
|
|
10
11
|
}
|
|
@@ -206,26 +207,107 @@ class TransactionDataBuilder {
|
|
|
206
207
|
return;
|
|
207
208
|
}
|
|
208
209
|
const sizeDiff = replacement.length - 1;
|
|
209
|
-
this.commands.splice(index, 1, ...replacement);
|
|
210
|
-
|
|
210
|
+
this.commands.splice(index, 1, ...structuredClone(replacement));
|
|
211
|
+
this.mapArguments((arg, _command, commandIndex) => {
|
|
212
|
+
if (commandIndex < index + replacement.length) {
|
|
213
|
+
return arg;
|
|
214
|
+
}
|
|
215
|
+
if (typeof resultIndex !== "number") {
|
|
216
|
+
if (arg.$kind === "Result" && arg.Result === index || arg.$kind === "NestedResult" && arg.NestedResult[0] === index) {
|
|
217
|
+
if (!("NestedResult" in arg) || arg.NestedResult[1] === 0) {
|
|
218
|
+
return parse(ArgumentSchema, structuredClone(resultIndex));
|
|
219
|
+
} else {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`Cannot replace command ${index} with a specific result type: NestedResult[${index}, ${arg.NestedResult[1]}] references a nested element that cannot be mapped to the replacement result`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
switch (arg.$kind) {
|
|
227
|
+
case "Result":
|
|
228
|
+
if (arg.Result === index && typeof resultIndex === "number") {
|
|
229
|
+
arg.Result = resultIndex;
|
|
230
|
+
}
|
|
231
|
+
if (arg.Result > index) {
|
|
232
|
+
arg.Result += sizeDiff;
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
case "NestedResult":
|
|
236
|
+
if (arg.NestedResult[0] === index && typeof resultIndex === "number") {
|
|
237
|
+
return {
|
|
238
|
+
$kind: "NestedResult",
|
|
239
|
+
NestedResult: [resultIndex, arg.NestedResult[1]]
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (arg.NestedResult[0] > index) {
|
|
243
|
+
arg.NestedResult[0] += sizeDiff;
|
|
244
|
+
}
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
return arg;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
replaceCommandWithTransaction(index, otherTransaction, result) {
|
|
251
|
+
if (result.$kind !== "Result" && result.$kind !== "NestedResult") {
|
|
252
|
+
throw new Error("Result must be of kind Result or NestedResult");
|
|
253
|
+
}
|
|
254
|
+
this.insertTransaction(index, otherTransaction);
|
|
255
|
+
this.replaceCommand(
|
|
256
|
+
index + otherTransaction.commands.length,
|
|
257
|
+
[],
|
|
258
|
+
"Result" in result ? { NestedResult: [result.Result + index, 0] } : {
|
|
259
|
+
NestedResult: [
|
|
260
|
+
result.NestedResult[0] + index,
|
|
261
|
+
result.NestedResult[1]
|
|
262
|
+
]
|
|
263
|
+
}
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
insertTransaction(atCommandIndex, otherTransaction) {
|
|
267
|
+
const inputMapping = /* @__PURE__ */ new Map();
|
|
268
|
+
const commandMapping = /* @__PURE__ */ new Map();
|
|
269
|
+
for (let i = 0; i < otherTransaction.inputs.length; i++) {
|
|
270
|
+
const otherInput = otherTransaction.inputs[i];
|
|
271
|
+
const id = getIdFromCallArg(otherInput);
|
|
272
|
+
let existingIndex = -1;
|
|
273
|
+
if (id !== void 0) {
|
|
274
|
+
existingIndex = this.inputs.findIndex((input) => getIdFromCallArg(input) === id);
|
|
275
|
+
if (existingIndex !== -1 && this.inputs[existingIndex].Object?.SharedObject && otherInput.Object?.SharedObject) {
|
|
276
|
+
this.inputs[existingIndex].Object.SharedObject.mutable = this.inputs[existingIndex].Object.SharedObject.mutable || otherInput.Object.SharedObject.mutable;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (existingIndex !== -1) {
|
|
280
|
+
inputMapping.set(i, existingIndex);
|
|
281
|
+
} else {
|
|
282
|
+
const newIndex = this.inputs.length;
|
|
283
|
+
this.inputs.push(otherInput);
|
|
284
|
+
inputMapping.set(i, newIndex);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
for (let i = 0; i < otherTransaction.commands.length; i++) {
|
|
288
|
+
commandMapping.set(i, atCommandIndex + i);
|
|
289
|
+
}
|
|
290
|
+
const remappedCommands = [];
|
|
291
|
+
for (let i = 0; i < otherTransaction.commands.length; i++) {
|
|
292
|
+
const command = structuredClone(otherTransaction.commands[i]);
|
|
293
|
+
remapCommandArguments(command, inputMapping, commandMapping);
|
|
294
|
+
remappedCommands.push(command);
|
|
295
|
+
}
|
|
296
|
+
this.commands.splice(atCommandIndex, 0, ...remappedCommands);
|
|
297
|
+
const sizeDiff = remappedCommands.length;
|
|
298
|
+
if (sizeDiff > 0) {
|
|
211
299
|
this.mapArguments((arg, _command, commandIndex) => {
|
|
212
|
-
if (commandIndex <
|
|
300
|
+
if (commandIndex >= atCommandIndex && commandIndex < atCommandIndex + remappedCommands.length) {
|
|
213
301
|
return arg;
|
|
214
302
|
}
|
|
215
303
|
switch (arg.$kind) {
|
|
216
304
|
case "Result":
|
|
217
|
-
if (arg.Result
|
|
218
|
-
arg.Result = resultIndex;
|
|
219
|
-
}
|
|
220
|
-
if (arg.Result > index) {
|
|
305
|
+
if (arg.Result >= atCommandIndex) {
|
|
221
306
|
arg.Result += sizeDiff;
|
|
222
307
|
}
|
|
223
308
|
break;
|
|
224
309
|
case "NestedResult":
|
|
225
|
-
if (arg.NestedResult[0]
|
|
226
|
-
arg.NestedResult[0] = resultIndex;
|
|
227
|
-
}
|
|
228
|
-
if (arg.NestedResult[0] > index) {
|
|
310
|
+
if (arg.NestedResult[0] >= atCommandIndex) {
|
|
229
311
|
arg.NestedResult[0] += sizeDiff;
|
|
230
312
|
}
|
|
231
313
|
break;
|