@solana/transactions 2.0.0-experimental.10bfcd8 → 2.0.0-experimental.11dd48f
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 +1 -43
- package/dist/index.browser.cjs +336 -456
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +331 -455
- package/dist/index.browser.js.map +1 -1
- package/dist/index.native.js +331 -455
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +336 -456
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +333 -455
- package/dist/index.node.js.map +1 -1
- package/dist/types/accounts.d.ts +2 -2
- package/dist/types/accounts.d.ts.map +1 -0
- package/dist/types/blockhash.d.ts +5 -7
- package/dist/types/blockhash.d.ts.map +1 -0
- package/dist/types/compilable-transaction.d.ts +7 -0
- package/dist/types/compilable-transaction.d.ts.map +1 -0
- package/dist/types/compile-address-table-lookups.d.ts +3 -3
- package/dist/types/compile-address-table-lookups.d.ts.map +1 -0
- package/dist/types/compile-header.d.ts +1 -1
- package/dist/types/compile-header.d.ts.map +1 -0
- package/dist/types/compile-instructions.d.ts +1 -1
- package/dist/types/compile-instructions.d.ts.map +1 -0
- package/dist/types/compile-lifetime-token.d.ts +1 -1
- package/dist/types/compile-lifetime-token.d.ts.map +1 -0
- package/dist/types/compile-static-accounts.d.ts +3 -3
- package/dist/types/compile-static-accounts.d.ts.map +1 -0
- package/dist/types/compile-transaction.d.ts +6 -7
- package/dist/types/compile-transaction.d.ts.map +1 -0
- package/dist/types/create-transaction.d.ts +1 -1
- package/dist/types/create-transaction.d.ts.map +1 -0
- package/dist/types/decompile-transaction.d.ts +12 -6
- package/dist/types/decompile-transaction.d.ts.map +1 -0
- package/dist/types/durable-nonce.d.ts +5 -5
- package/dist/types/durable-nonce.d.ts.map +1 -0
- package/dist/types/fee-payer.d.ts +6 -6
- package/dist/types/fee-payer.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -9
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/instructions.d.ts +2 -2
- package/dist/types/instructions.d.ts.map +1 -0
- package/dist/types/message.d.ts +6 -10
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/serializers/address-table-lookup.d.ts +5 -5
- package/dist/types/serializers/address-table-lookup.d.ts.map +1 -0
- package/dist/types/serializers/header.d.ts +5 -5
- package/dist/types/serializers/header.d.ts.map +1 -0
- package/dist/types/serializers/index.d.ts +2 -1
- package/dist/types/serializers/index.d.ts.map +1 -0
- package/dist/types/serializers/instruction.d.ts +5 -5
- package/dist/types/serializers/instruction.d.ts.map +1 -0
- package/dist/types/serializers/message.d.ts +5 -5
- package/dist/types/serializers/message.d.ts.map +1 -0
- package/dist/types/serializers/transaction-version.d.ts +5 -5
- package/dist/types/serializers/transaction-version.d.ts.map +1 -0
- package/dist/types/serializers/transaction.d.ts +9 -8
- package/dist/types/serializers/transaction.d.ts.map +1 -0
- package/dist/types/signatures.d.ts +9 -14
- package/dist/types/signatures.d.ts.map +1 -0
- package/dist/types/types.d.ts +6 -13
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/unsigned-transaction.d.ts +1 -1
- package/dist/types/unsigned-transaction.d.ts.map +1 -0
- package/dist/types/wire-transaction.d.ts +1 -1
- package/dist/types/wire-transaction.d.ts.map +1 -0
- package/package.json +18 -17
- package/dist/index.development.js +0 -1841
- package/dist/index.development.js.map +0 -1
- package/dist/index.production.min.js +0 -29
package/dist/index.browser.cjs
CHANGED
|
@@ -1,33 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var codecsStrings = require('@solana/codecs-strings');
|
|
4
|
+
var addresses = require('@solana/addresses');
|
|
5
|
+
var functional = require('@solana/functional');
|
|
4
6
|
var codecsCore = require('@solana/codecs-core');
|
|
5
7
|
var codecsDataStructures = require('@solana/codecs-data-structures');
|
|
6
8
|
var codecsNumbers = require('@solana/codecs-numbers');
|
|
7
|
-
var
|
|
8
|
-
var functional = require('@solana/functional');
|
|
9
|
-
var codecsStrings = require('@solana/codecs-strings');
|
|
9
|
+
var errors = require('@solana/errors');
|
|
10
10
|
var keys = require('@solana/keys');
|
|
11
11
|
|
|
12
|
-
// ../
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
// src/unsigned-transaction.ts
|
|
16
|
-
function getUnsignedTransaction(transaction) {
|
|
17
|
-
if ("signatures" in transaction) {
|
|
18
|
-
const {
|
|
19
|
-
signatures: _,
|
|
20
|
-
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
21
|
-
...unsignedTransaction
|
|
22
|
-
} = transaction;
|
|
23
|
-
return unsignedTransaction;
|
|
24
|
-
} else {
|
|
25
|
-
return transaction;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// src/blockhash.ts
|
|
12
|
+
// ../rpc-types/dist/index.browser.js
|
|
13
|
+
var base58Encoder;
|
|
30
14
|
function assertIsBlockhash(putativeBlockhash) {
|
|
15
|
+
if (!base58Encoder)
|
|
16
|
+
base58Encoder = codecsStrings.getBase58Encoder();
|
|
31
17
|
try {
|
|
32
18
|
if (
|
|
33
19
|
// Lowest value (32 bytes of zeroes)
|
|
@@ -36,7 +22,7 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
36
22
|
) {
|
|
37
23
|
throw new Error("Expected input string to decode to a byte array of length 32.");
|
|
38
24
|
}
|
|
39
|
-
const bytes =
|
|
25
|
+
const bytes = base58Encoder.encode(putativeBlockhash);
|
|
40
26
|
const numBytes = bytes.byteLength;
|
|
41
27
|
if (numBytes !== 32) {
|
|
42
28
|
throw new Error(`Expected input string to decode to a byte array of length 32. Actual length: ${numBytes}`);
|
|
@@ -47,6 +33,38 @@ function assertIsBlockhash(putativeBlockhash) {
|
|
|
47
33
|
});
|
|
48
34
|
}
|
|
49
35
|
}
|
|
36
|
+
|
|
37
|
+
// src/unsigned-transaction.ts
|
|
38
|
+
function getUnsignedTransaction(transaction) {
|
|
39
|
+
if ("signatures" in transaction) {
|
|
40
|
+
const {
|
|
41
|
+
signatures: _,
|
|
42
|
+
// eslint-disable-line @typescript-eslint/no-unused-vars
|
|
43
|
+
...unsignedTransaction
|
|
44
|
+
} = transaction;
|
|
45
|
+
return unsignedTransaction;
|
|
46
|
+
} else {
|
|
47
|
+
return transaction;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/blockhash.ts
|
|
52
|
+
function isTransactionWithBlockhashLifetime(transaction) {
|
|
53
|
+
const lifetimeConstraintShapeMatches = "lifetimeConstraint" in transaction && typeof transaction.lifetimeConstraint.blockhash === "string" && typeof transaction.lifetimeConstraint.lastValidBlockHeight === "bigint";
|
|
54
|
+
if (!lifetimeConstraintShapeMatches)
|
|
55
|
+
return false;
|
|
56
|
+
try {
|
|
57
|
+
assertIsBlockhash(transaction.lifetimeConstraint.blockhash);
|
|
58
|
+
return true;
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function assertIsTransactionWithBlockhashLifetime(transaction) {
|
|
64
|
+
if (!isTransactionWithBlockhashLifetime(transaction)) {
|
|
65
|
+
throw new Error("Transaction does not have a blockhash lifetime");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
50
68
|
function setTransactionLifetimeUsingBlockhash(blockhashLifetimeConstraint, transaction) {
|
|
51
69
|
if ("lifetimeConstraint" in transaction && transaction.lifetimeConstraint.blockhash === blockhashLifetimeConstraint.blockhash && transaction.lifetimeConstraint.lastValidBlockHeight === blockhashLifetimeConstraint.lastValidBlockHeight) {
|
|
52
70
|
return transaction;
|
|
@@ -200,6 +218,151 @@ function prependTransactionInstruction(instruction, transaction) {
|
|
|
200
218
|
Object.freeze(out);
|
|
201
219
|
return out;
|
|
202
220
|
}
|
|
221
|
+
|
|
222
|
+
// src/decompile-transaction.ts
|
|
223
|
+
function getAccountMetas(message) {
|
|
224
|
+
const { header } = message;
|
|
225
|
+
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
226
|
+
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
227
|
+
const accountMetas = [];
|
|
228
|
+
let accountIndex = 0;
|
|
229
|
+
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
230
|
+
accountMetas.push({
|
|
231
|
+
address: message.staticAccounts[accountIndex],
|
|
232
|
+
role: AccountRole.WRITABLE_SIGNER
|
|
233
|
+
});
|
|
234
|
+
accountIndex++;
|
|
235
|
+
}
|
|
236
|
+
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
237
|
+
accountMetas.push({
|
|
238
|
+
address: message.staticAccounts[accountIndex],
|
|
239
|
+
role: AccountRole.READONLY_SIGNER
|
|
240
|
+
});
|
|
241
|
+
accountIndex++;
|
|
242
|
+
}
|
|
243
|
+
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
244
|
+
accountMetas.push({
|
|
245
|
+
address: message.staticAccounts[accountIndex],
|
|
246
|
+
role: AccountRole.WRITABLE
|
|
247
|
+
});
|
|
248
|
+
accountIndex++;
|
|
249
|
+
}
|
|
250
|
+
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
251
|
+
accountMetas.push({
|
|
252
|
+
address: message.staticAccounts[accountIndex],
|
|
253
|
+
role: AccountRole.READONLY
|
|
254
|
+
});
|
|
255
|
+
accountIndex++;
|
|
256
|
+
}
|
|
257
|
+
return accountMetas;
|
|
258
|
+
}
|
|
259
|
+
function getAddressLookupMetas(compiledAddressTableLookups, addressesByLookupTableAddress) {
|
|
260
|
+
const compiledAddressTableLookupAddresses = compiledAddressTableLookups.map((l) => l.lookupTableAddress);
|
|
261
|
+
const missing = compiledAddressTableLookupAddresses.filter((a) => addressesByLookupTableAddress[a] === void 0);
|
|
262
|
+
if (missing.length > 0) {
|
|
263
|
+
const missingAddresses = missing.join(", ");
|
|
264
|
+
throw new Error(`Addresses not provided for lookup tables: [${missingAddresses}]`);
|
|
265
|
+
}
|
|
266
|
+
const readOnlyMetas = [];
|
|
267
|
+
const writableMetas = [];
|
|
268
|
+
for (const lookup of compiledAddressTableLookups) {
|
|
269
|
+
const addresses = addressesByLookupTableAddress[lookup.lookupTableAddress];
|
|
270
|
+
const highestIndex = Math.max(...lookup.readableIndices, ...lookup.writableIndices);
|
|
271
|
+
if (highestIndex >= addresses.length) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`Cannot look up index ${highestIndex} in lookup table [${lookup.lookupTableAddress}]. The lookup table may have been extended since the addresses provided were retrieved.`
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
const readOnlyForLookup = lookup.readableIndices.map((r) => ({
|
|
277
|
+
address: addresses[r],
|
|
278
|
+
addressIndex: r,
|
|
279
|
+
lookupTableAddress: lookup.lookupTableAddress,
|
|
280
|
+
role: AccountRole.READONLY
|
|
281
|
+
}));
|
|
282
|
+
readOnlyMetas.push(...readOnlyForLookup);
|
|
283
|
+
const writableForLookup = lookup.writableIndices.map((w) => ({
|
|
284
|
+
address: addresses[w],
|
|
285
|
+
addressIndex: w,
|
|
286
|
+
lookupTableAddress: lookup.lookupTableAddress,
|
|
287
|
+
role: AccountRole.WRITABLE
|
|
288
|
+
}));
|
|
289
|
+
writableMetas.push(...writableForLookup);
|
|
290
|
+
}
|
|
291
|
+
return [...writableMetas, ...readOnlyMetas];
|
|
292
|
+
}
|
|
293
|
+
function convertInstruction(instruction, accountMetas) {
|
|
294
|
+
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
295
|
+
if (!programAddress) {
|
|
296
|
+
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
297
|
+
}
|
|
298
|
+
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
299
|
+
const { data } = instruction;
|
|
300
|
+
return {
|
|
301
|
+
programAddress,
|
|
302
|
+
...accounts && accounts.length ? { accounts } : {},
|
|
303
|
+
...data && data.length ? { data } : {}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
307
|
+
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
308
|
+
return {
|
|
309
|
+
blockhash: messageLifetimeToken,
|
|
310
|
+
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
311
|
+
// U64 MAX
|
|
312
|
+
};
|
|
313
|
+
} else {
|
|
314
|
+
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
315
|
+
addresses.assertIsAddress(nonceAccountAddress);
|
|
316
|
+
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
317
|
+
addresses.assertIsAddress(nonceAuthorityAddress);
|
|
318
|
+
return {
|
|
319
|
+
nonce: messageLifetimeToken,
|
|
320
|
+
nonceAccountAddress,
|
|
321
|
+
nonceAuthorityAddress
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function convertSignatures(compiledTransaction) {
|
|
326
|
+
const {
|
|
327
|
+
compiledMessage: { staticAccounts },
|
|
328
|
+
signatures
|
|
329
|
+
} = compiledTransaction;
|
|
330
|
+
return signatures.reduce((acc, sig, index) => {
|
|
331
|
+
const allZeros = sig.every((byte) => byte === 0);
|
|
332
|
+
if (allZeros)
|
|
333
|
+
return acc;
|
|
334
|
+
const address = staticAccounts[index];
|
|
335
|
+
return { ...acc, [address]: sig };
|
|
336
|
+
}, {});
|
|
337
|
+
}
|
|
338
|
+
function decompileTransaction(compiledTransaction, config) {
|
|
339
|
+
const { compiledMessage } = compiledTransaction;
|
|
340
|
+
const feePayer = compiledMessage.staticAccounts[0];
|
|
341
|
+
if (!feePayer)
|
|
342
|
+
throw new Error("No fee payer set in CompiledTransaction");
|
|
343
|
+
const accountMetas = getAccountMetas(compiledMessage);
|
|
344
|
+
const accountLookupMetas = "addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups !== void 0 && compiledMessage.addressTableLookups.length > 0 ? getAddressLookupMetas(compiledMessage.addressTableLookups, config?.addressesByLookupTableAddress ?? {}) : [];
|
|
345
|
+
const transactionMetas = [...accountMetas, ...accountLookupMetas];
|
|
346
|
+
const instructions = compiledMessage.instructions.map(
|
|
347
|
+
(compiledInstruction) => convertInstruction(compiledInstruction, transactionMetas)
|
|
348
|
+
);
|
|
349
|
+
const firstInstruction = instructions[0];
|
|
350
|
+
const lifetimeConstraint = getLifetimeConstraint(
|
|
351
|
+
compiledMessage.lifetimeToken,
|
|
352
|
+
firstInstruction,
|
|
353
|
+
config?.lastValidBlockHeight
|
|
354
|
+
);
|
|
355
|
+
const signatures = convertSignatures(compiledTransaction);
|
|
356
|
+
return functional.pipe(
|
|
357
|
+
createTransaction({ version: compiledMessage.version }),
|
|
358
|
+
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
359
|
+
(tx) => instructions.reduce((acc, instruction) => {
|
|
360
|
+
return appendTransactionInstruction(instruction, acc);
|
|
361
|
+
}, tx),
|
|
362
|
+
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
363
|
+
(tx) => Object.keys(signatures).length > 0 ? { ...tx, signatures } : tx
|
|
364
|
+
);
|
|
365
|
+
}
|
|
203
366
|
function upsert(addressMap, address, update) {
|
|
204
367
|
addressMap[address] = update(addressMap[address] ?? { role: AccountRole.READONLY });
|
|
205
368
|
}
|
|
@@ -252,7 +415,7 @@ function getAddressMapFromInstructions(feePayer, instructions) {
|
|
|
252
415
|
const shouldReplaceEntry = (
|
|
253
416
|
// Consider using the new LOOKUP_TABLE if its address is different...
|
|
254
417
|
entry.lookupTableAddress !== accountMeta.lookupTableAddress && // ...and sorts before the existing one.
|
|
255
|
-
(addressComparator
|
|
418
|
+
(addressComparator ||= addresses.getAddressComparator())(
|
|
256
419
|
accountMeta.lookupTableAddress,
|
|
257
420
|
entry.lookupTableAddress
|
|
258
421
|
) < 0
|
|
@@ -358,7 +521,7 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
358
521
|
if (leftIsWritable !== isWritableRole(rightEntry.role)) {
|
|
359
522
|
return leftIsWritable ? -1 : 1;
|
|
360
523
|
}
|
|
361
|
-
addressComparator
|
|
524
|
+
addressComparator ||= addresses.getAddressComparator();
|
|
362
525
|
if (leftEntry[TYPE] === 1 /* LOOKUP_TABLE */ && rightEntry[TYPE] === 1 /* LOOKUP_TABLE */ && leftEntry.lookupTableAddress !== rightEntry.lookupTableAddress) {
|
|
363
526
|
return addressComparator(leftEntry.lookupTableAddress, rightEntry.lookupTableAddress);
|
|
364
527
|
} else {
|
|
@@ -371,16 +534,15 @@ function getOrderedAccountsFromAddressMap(addressMap) {
|
|
|
371
534
|
return orderedAccounts;
|
|
372
535
|
}
|
|
373
536
|
function getCompiledAddressTableLookups(orderedAccounts) {
|
|
374
|
-
var _a;
|
|
375
537
|
const index = {};
|
|
376
538
|
for (const account of orderedAccounts) {
|
|
377
539
|
if (!("lookupTableAddress" in account)) {
|
|
378
540
|
continue;
|
|
379
541
|
}
|
|
380
|
-
const entry = index[
|
|
542
|
+
const entry = index[account.lookupTableAddress] ||= {
|
|
381
543
|
readableIndices: [],
|
|
382
544
|
writableIndices: []
|
|
383
|
-
}
|
|
545
|
+
};
|
|
384
546
|
if (account.role === AccountRole.WRITABLE) {
|
|
385
547
|
entry.writableIndices.push(account.addressIndex);
|
|
386
548
|
} else {
|
|
@@ -466,187 +628,31 @@ function compileMessage(transaction) {
|
|
|
466
628
|
version: transaction.version
|
|
467
629
|
};
|
|
468
630
|
}
|
|
469
|
-
|
|
470
|
-
// src/compile-transaction.ts
|
|
471
|
-
function getCompiledTransaction(transaction) {
|
|
472
|
-
const compiledMessage = compileMessage(transaction);
|
|
473
|
-
let signatures;
|
|
474
|
-
if ("signatures" in transaction) {
|
|
475
|
-
signatures = [];
|
|
476
|
-
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
477
|
-
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
478
|
-
}
|
|
479
|
-
} else {
|
|
480
|
-
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
481
|
-
}
|
|
482
|
-
return {
|
|
483
|
-
compiledMessage,
|
|
484
|
-
signatures
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
function getAccountMetas(message) {
|
|
488
|
-
const { header } = message;
|
|
489
|
-
const numWritableSignerAccounts = header.numSignerAccounts - header.numReadonlySignerAccounts;
|
|
490
|
-
const numWritableNonSignerAccounts = message.staticAccounts.length - header.numSignerAccounts - header.numReadonlyNonSignerAccounts;
|
|
491
|
-
const accountMetas = [];
|
|
492
|
-
let accountIndex = 0;
|
|
493
|
-
for (let i = 0; i < numWritableSignerAccounts; i++) {
|
|
494
|
-
accountMetas.push({
|
|
495
|
-
address: message.staticAccounts[accountIndex],
|
|
496
|
-
role: AccountRole.WRITABLE_SIGNER
|
|
497
|
-
});
|
|
498
|
-
accountIndex++;
|
|
499
|
-
}
|
|
500
|
-
for (let i = 0; i < header.numReadonlySignerAccounts; i++) {
|
|
501
|
-
accountMetas.push({
|
|
502
|
-
address: message.staticAccounts[accountIndex],
|
|
503
|
-
role: AccountRole.READONLY_SIGNER
|
|
504
|
-
});
|
|
505
|
-
accountIndex++;
|
|
506
|
-
}
|
|
507
|
-
for (let i = 0; i < numWritableNonSignerAccounts; i++) {
|
|
508
|
-
accountMetas.push({
|
|
509
|
-
address: message.staticAccounts[accountIndex],
|
|
510
|
-
role: AccountRole.WRITABLE
|
|
511
|
-
});
|
|
512
|
-
accountIndex++;
|
|
513
|
-
}
|
|
514
|
-
for (let i = 0; i < header.numReadonlyNonSignerAccounts; i++) {
|
|
515
|
-
accountMetas.push({
|
|
516
|
-
address: message.staticAccounts[accountIndex],
|
|
517
|
-
role: AccountRole.READONLY
|
|
518
|
-
});
|
|
519
|
-
accountIndex++;
|
|
520
|
-
}
|
|
521
|
-
return accountMetas;
|
|
522
|
-
}
|
|
523
|
-
function convertInstruction(instruction, accountMetas) {
|
|
524
|
-
const programAddress = accountMetas[instruction.programAddressIndex]?.address;
|
|
525
|
-
if (!programAddress) {
|
|
526
|
-
throw new Error(`Could not find program address at index ${instruction.programAddressIndex}`);
|
|
527
|
-
}
|
|
528
|
-
const accounts = instruction.accountIndices?.map((accountIndex) => accountMetas[accountIndex]);
|
|
529
|
-
const { data } = instruction;
|
|
530
|
-
return {
|
|
531
|
-
programAddress,
|
|
532
|
-
...accounts && accounts.length ? { accounts } : {},
|
|
533
|
-
...data && data.length ? { data } : {}
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
function getLifetimeConstraint(messageLifetimeToken, firstInstruction, lastValidBlockHeight) {
|
|
537
|
-
if (!firstInstruction || !isAdvanceNonceAccountInstruction(firstInstruction)) {
|
|
538
|
-
return {
|
|
539
|
-
blockhash: messageLifetimeToken,
|
|
540
|
-
lastValidBlockHeight: lastValidBlockHeight ?? 2n ** 64n - 1n
|
|
541
|
-
// U64 MAX
|
|
542
|
-
};
|
|
543
|
-
} else {
|
|
544
|
-
const nonceAccountAddress = firstInstruction.accounts[0].address;
|
|
545
|
-
addresses.assertIsAddress(nonceAccountAddress);
|
|
546
|
-
const nonceAuthorityAddress = firstInstruction.accounts[2].address;
|
|
547
|
-
addresses.assertIsAddress(nonceAuthorityAddress);
|
|
548
|
-
return {
|
|
549
|
-
nonce: messageLifetimeToken,
|
|
550
|
-
nonceAccountAddress,
|
|
551
|
-
nonceAuthorityAddress
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
function convertSignatures(compiledTransaction) {
|
|
556
|
-
const {
|
|
557
|
-
compiledMessage: { staticAccounts },
|
|
558
|
-
signatures
|
|
559
|
-
} = compiledTransaction;
|
|
560
|
-
return signatures.reduce((acc, sig, index) => {
|
|
561
|
-
const allZeros = sig.every((byte) => byte === 0);
|
|
562
|
-
if (allZeros)
|
|
563
|
-
return acc;
|
|
564
|
-
const address = staticAccounts[index];
|
|
565
|
-
return { ...acc, [address]: sig };
|
|
566
|
-
}, {});
|
|
567
|
-
}
|
|
568
|
-
function decompileTransaction(compiledTransaction, lastValidBlockHeight) {
|
|
569
|
-
const { compiledMessage } = compiledTransaction;
|
|
570
|
-
if ("addressTableLookups" in compiledMessage && compiledMessage.addressTableLookups.length > 0) {
|
|
571
|
-
throw new Error("Cannot convert transaction with addressTableLookups");
|
|
572
|
-
}
|
|
573
|
-
const feePayer = compiledMessage.staticAccounts[0];
|
|
574
|
-
if (!feePayer)
|
|
575
|
-
throw new Error("No fee payer set in CompiledTransaction");
|
|
576
|
-
const accountMetas = getAccountMetas(compiledMessage);
|
|
577
|
-
const instructions = compiledMessage.instructions.map(
|
|
578
|
-
(compiledInstruction) => convertInstruction(compiledInstruction, accountMetas)
|
|
579
|
-
);
|
|
580
|
-
const firstInstruction = instructions[0];
|
|
581
|
-
const lifetimeConstraint = getLifetimeConstraint(
|
|
582
|
-
compiledMessage.lifetimeToken,
|
|
583
|
-
firstInstruction,
|
|
584
|
-
lastValidBlockHeight
|
|
585
|
-
);
|
|
586
|
-
const signatures = convertSignatures(compiledTransaction);
|
|
587
|
-
return functional.pipe(
|
|
588
|
-
createTransaction({ version: compiledMessage.version }),
|
|
589
|
-
(tx) => setTransactionFeePayer(feePayer, tx),
|
|
590
|
-
(tx) => instructions.reduce((acc, instruction) => {
|
|
591
|
-
return appendTransactionInstruction(instruction, acc);
|
|
592
|
-
}, tx),
|
|
593
|
-
(tx) => "blockhash" in lifetimeConstraint ? setTransactionLifetimeUsingBlockhash(lifetimeConstraint, tx) : setTransactionLifetimeUsingDurableNonce(lifetimeConstraint, tx),
|
|
594
|
-
(tx) => compiledTransaction.signatures.length ? { ...tx, signatures } : tx
|
|
595
|
-
);
|
|
596
|
-
}
|
|
597
|
-
var lookupTableAddressDescription = __DEV__ ? "The address of the address lookup table account from which instruction addresses should be looked up" : "lookupTableAddress";
|
|
598
|
-
var writableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as writeable" : "writableIndices";
|
|
599
|
-
var readableIndicesDescription = __DEV__ ? "The indices of the accounts in the lookup table that should be loaded as read-only" : "readableIndices";
|
|
600
|
-
var addressTableLookupDescription = __DEV__ ? "A pointer to the address of an address lookup table, along with the readonly/writeable indices of the addresses that should be loaded from it" : "addressTableLookup";
|
|
601
631
|
var memoizedAddressTableLookupEncoder;
|
|
602
632
|
function getAddressTableLookupEncoder() {
|
|
603
633
|
if (!memoizedAddressTableLookupEncoder) {
|
|
604
|
-
memoizedAddressTableLookupEncoder = codecsDataStructures.getStructEncoder(
|
|
634
|
+
memoizedAddressTableLookupEncoder = codecsDataStructures.getStructEncoder([
|
|
635
|
+
["lookupTableAddress", addresses.getAddressEncoder()],
|
|
605
636
|
[
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
"writableIndices",
|
|
609
|
-
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
|
|
610
|
-
description: writableIndicesDescription,
|
|
611
|
-
size: codecsNumbers.getShortU16Encoder()
|
|
612
|
-
})
|
|
613
|
-
],
|
|
614
|
-
[
|
|
615
|
-
"readableIndices",
|
|
616
|
-
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), {
|
|
617
|
-
description: readableIndicesDescription,
|
|
618
|
-
size: codecsNumbers.getShortU16Encoder()
|
|
619
|
-
})
|
|
620
|
-
]
|
|
637
|
+
"writableIndices",
|
|
638
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), { size: codecsNumbers.getShortU16Encoder() })
|
|
621
639
|
],
|
|
622
|
-
|
|
623
|
-
|
|
640
|
+
[
|
|
641
|
+
"readableIndices",
|
|
642
|
+
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), { size: codecsNumbers.getShortU16Encoder() })
|
|
643
|
+
]
|
|
644
|
+
]);
|
|
624
645
|
}
|
|
625
646
|
return memoizedAddressTableLookupEncoder;
|
|
626
647
|
}
|
|
627
648
|
var memoizedAddressTableLookupDecoder;
|
|
628
649
|
function getAddressTableLookupDecoder() {
|
|
629
650
|
if (!memoizedAddressTableLookupDecoder) {
|
|
630
|
-
memoizedAddressTableLookupDecoder = codecsDataStructures.getStructDecoder(
|
|
631
|
-
[
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
|
|
636
|
-
description: writableIndicesDescription,
|
|
637
|
-
size: codecsNumbers.getShortU16Decoder()
|
|
638
|
-
})
|
|
639
|
-
],
|
|
640
|
-
[
|
|
641
|
-
"readableIndices",
|
|
642
|
-
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), {
|
|
643
|
-
description: readableIndicesDescription,
|
|
644
|
-
size: codecsNumbers.getShortU16Decoder()
|
|
645
|
-
})
|
|
646
|
-
]
|
|
647
|
-
],
|
|
648
|
-
{ description: addressTableLookupDescription }
|
|
649
|
-
);
|
|
651
|
+
memoizedAddressTableLookupDecoder = codecsDataStructures.getStructDecoder([
|
|
652
|
+
["lookupTableAddress", addresses.getAddressDecoder()],
|
|
653
|
+
["writableIndices", codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), { size: codecsNumbers.getShortU16Decoder() })],
|
|
654
|
+
["readableIndices", codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), { size: codecsNumbers.getShortU16Decoder() })]
|
|
655
|
+
]);
|
|
650
656
|
}
|
|
651
657
|
return memoizedAddressTableLookupDecoder;
|
|
652
658
|
}
|
|
@@ -656,72 +662,34 @@ function getMemoizedU8Encoder() {
|
|
|
656
662
|
memoizedU8Encoder = codecsNumbers.getU8Encoder();
|
|
657
663
|
return memoizedU8Encoder;
|
|
658
664
|
}
|
|
659
|
-
function getMemoizedU8EncoderDescription(description) {
|
|
660
|
-
const encoder = getMemoizedU8Encoder();
|
|
661
|
-
return {
|
|
662
|
-
...encoder,
|
|
663
|
-
description: description ?? encoder.description
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
665
|
var memoizedU8Decoder;
|
|
667
666
|
function getMemoizedU8Decoder() {
|
|
668
667
|
if (!memoizedU8Decoder)
|
|
669
668
|
memoizedU8Decoder = codecsNumbers.getU8Decoder();
|
|
670
669
|
return memoizedU8Decoder;
|
|
671
670
|
}
|
|
672
|
-
function getMemoizedU8DecoderDescription(description) {
|
|
673
|
-
const decoder = getMemoizedU8Decoder();
|
|
674
|
-
return {
|
|
675
|
-
...decoder,
|
|
676
|
-
description: description ?? decoder.description
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
var numSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction" : void 0;
|
|
680
|
-
var numReadonlySignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are required to sign this transaction, but may not be writable" : void 0;
|
|
681
|
-
var numReadonlyNonSignerAccountsDescription = __DEV__ ? "The expected number of addresses in the static address list belonging to accounts that are neither signers, nor writable" : void 0;
|
|
682
|
-
var messageHeaderDescription = __DEV__ ? "The transaction message header containing counts of the signer, readonly-signer, and readonly-nonsigner account addresses" : void 0;
|
|
683
671
|
function getMessageHeaderEncoder() {
|
|
684
|
-
return codecsDataStructures.getStructEncoder(
|
|
685
|
-
[
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
],
|
|
690
|
-
{
|
|
691
|
-
description: messageHeaderDescription
|
|
692
|
-
}
|
|
693
|
-
);
|
|
672
|
+
return codecsDataStructures.getStructEncoder([
|
|
673
|
+
["numSignerAccounts", getMemoizedU8Encoder()],
|
|
674
|
+
["numReadonlySignerAccounts", getMemoizedU8Encoder()],
|
|
675
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8Encoder()]
|
|
676
|
+
]);
|
|
694
677
|
}
|
|
695
678
|
function getMessageHeaderDecoder() {
|
|
696
|
-
return codecsDataStructures.getStructDecoder(
|
|
697
|
-
[
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
],
|
|
702
|
-
{
|
|
703
|
-
description: messageHeaderDescription
|
|
704
|
-
}
|
|
705
|
-
);
|
|
679
|
+
return codecsDataStructures.getStructDecoder([
|
|
680
|
+
["numSignerAccounts", getMemoizedU8Decoder()],
|
|
681
|
+
["numReadonlySignerAccounts", getMemoizedU8Decoder()],
|
|
682
|
+
["numReadonlyNonSignerAccounts", getMemoizedU8Decoder()]
|
|
683
|
+
]);
|
|
706
684
|
}
|
|
707
|
-
var programAddressIndexDescription = __DEV__ ? "The index of the program being called, according to the well-ordered accounts list for this transaction" : "programAddressIndex";
|
|
708
|
-
var accountIndexDescription = __DEV__ ? "The index of an account, according to the well-ordered accounts list for this transaction" : void 0;
|
|
709
|
-
var accountIndicesDescription = __DEV__ ? "An optional list of account indices, according to the well-ordered accounts list for this transaction, in the order in which the program being called expects them" : "accountIndices";
|
|
710
|
-
var dataDescription = __DEV__ ? "An optional buffer of data passed to the instruction" : "data";
|
|
711
685
|
var memoizedGetInstructionEncoder;
|
|
712
686
|
function getInstructionEncoder() {
|
|
713
687
|
if (!memoizedGetInstructionEncoder) {
|
|
714
688
|
memoizedGetInstructionEncoder = codecsCore.mapEncoder(
|
|
715
689
|
codecsDataStructures.getStructEncoder([
|
|
716
|
-
["programAddressIndex", codecsNumbers.getU8Encoder(
|
|
717
|
-
[
|
|
718
|
-
|
|
719
|
-
codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder({ description: accountIndexDescription }), {
|
|
720
|
-
description: accountIndicesDescription,
|
|
721
|
-
size: codecsNumbers.getShortU16Encoder()
|
|
722
|
-
})
|
|
723
|
-
],
|
|
724
|
-
["data", codecsDataStructures.getBytesEncoder({ description: dataDescription, size: codecsNumbers.getShortU16Encoder() })]
|
|
690
|
+
["programAddressIndex", codecsNumbers.getU8Encoder()],
|
|
691
|
+
["accountIndices", codecsDataStructures.getArrayEncoder(codecsNumbers.getU8Encoder(), { size: codecsNumbers.getShortU16Encoder() })],
|
|
692
|
+
["data", codecsDataStructures.getBytesEncoder({ size: codecsNumbers.getShortU16Encoder() })]
|
|
725
693
|
]),
|
|
726
694
|
// Convert an instruction to have all fields defined
|
|
727
695
|
(instruction) => {
|
|
@@ -743,15 +711,9 @@ function getInstructionDecoder() {
|
|
|
743
711
|
if (!memoizedGetInstructionDecoder) {
|
|
744
712
|
memoizedGetInstructionDecoder = codecsCore.mapDecoder(
|
|
745
713
|
codecsDataStructures.getStructDecoder([
|
|
746
|
-
["programAddressIndex", codecsNumbers.getU8Decoder(
|
|
747
|
-
[
|
|
748
|
-
|
|
749
|
-
codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder({ description: accountIndexDescription }), {
|
|
750
|
-
description: accountIndicesDescription,
|
|
751
|
-
size: codecsNumbers.getShortU16Decoder()
|
|
752
|
-
})
|
|
753
|
-
],
|
|
754
|
-
["data", codecsDataStructures.getBytesDecoder({ description: dataDescription, size: codecsNumbers.getShortU16Decoder() })]
|
|
714
|
+
["programAddressIndex", codecsNumbers.getU8Decoder()],
|
|
715
|
+
["accountIndices", codecsDataStructures.getArrayDecoder(codecsNumbers.getU8Decoder(), { size: codecsNumbers.getShortU16Decoder() })],
|
|
716
|
+
["data", codecsDataStructures.getBytesDecoder({ size: codecsNumbers.getShortU16Decoder() })]
|
|
755
717
|
]),
|
|
756
718
|
// Convert an instruction to exclude optional fields if they are empty
|
|
757
719
|
(instruction) => {
|
|
@@ -770,47 +732,38 @@ function getInstructionDecoder() {
|
|
|
770
732
|
return memoizedGetInstructionDecoder;
|
|
771
733
|
}
|
|
772
734
|
var VERSION_FLAG_MASK = 128;
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
if (value === "legacy") {
|
|
789
|
-
return new Uint8Array();
|
|
790
|
-
}
|
|
791
|
-
if (value < 0 || value > 127) {
|
|
792
|
-
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
|
|
793
|
-
}
|
|
794
|
-
return new Uint8Array([value | VERSION_FLAG_MASK]);
|
|
735
|
+
function getTransactionVersionEncoder() {
|
|
736
|
+
return codecsCore.createEncoder({
|
|
737
|
+
getSizeFromValue: (value) => value === "legacy" ? 0 : 1,
|
|
738
|
+
maxSize: 1,
|
|
739
|
+
write: (value, bytes, offset) => {
|
|
740
|
+
if (value === "legacy") {
|
|
741
|
+
return offset;
|
|
742
|
+
}
|
|
743
|
+
if (value < 0 || value > 127) {
|
|
744
|
+
throw new Error(`Transaction version must be in the range [0, 127]. \`${value}\` given.`);
|
|
745
|
+
}
|
|
746
|
+
bytes.set([value | VERSION_FLAG_MASK], offset);
|
|
747
|
+
return offset + 1;
|
|
748
|
+
}
|
|
749
|
+
});
|
|
795
750
|
}
|
|
796
751
|
function getTransactionVersionDecoder() {
|
|
797
|
-
return {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
752
|
+
return codecsCore.createDecoder({
|
|
753
|
+
maxSize: 1,
|
|
754
|
+
read: (bytes, offset) => {
|
|
755
|
+
const firstByte = bytes[offset];
|
|
756
|
+
if ((firstByte & VERSION_FLAG_MASK) === 0) {
|
|
757
|
+
return ["legacy", offset];
|
|
758
|
+
} else {
|
|
759
|
+
const version = firstByte ^ VERSION_FLAG_MASK;
|
|
760
|
+
return [version, offset + 1];
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
});
|
|
807
764
|
}
|
|
808
765
|
|
|
809
766
|
// src/serializers/message.ts
|
|
810
|
-
var staticAccountsDescription = __DEV__ ? "A compact-array of static account addresses belonging to this transaction" : "staticAccounts";
|
|
811
|
-
var lifetimeTokenDescription = __DEV__ ? "A 32-byte token that specifies the lifetime of this transaction (eg. a recent blockhash, or a durable nonce)" : "lifetimeToken";
|
|
812
|
-
var instructionsDescription = __DEV__ ? "A compact-array of instructions belonging to this transaction" : "instructions";
|
|
813
|
-
var addressTableLookupsDescription = __DEV__ ? "A compact array of address table lookups belonging to this transaction" : "addressTableLookups";
|
|
814
767
|
function getCompiledMessageLegacyEncoder() {
|
|
815
768
|
return codecsDataStructures.getStructEncoder(getPreludeStructEncoderTuple());
|
|
816
769
|
}
|
|
@@ -835,198 +788,117 @@ function getPreludeStructEncoderTuple() {
|
|
|
835
788
|
return [
|
|
836
789
|
["version", getTransactionVersionEncoder()],
|
|
837
790
|
["header", getMessageHeaderEncoder()],
|
|
838
|
-
[
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
description: staticAccountsDescription,
|
|
842
|
-
size: codecsNumbers.getShortU16Encoder()
|
|
843
|
-
})
|
|
844
|
-
],
|
|
845
|
-
[
|
|
846
|
-
"lifetimeToken",
|
|
847
|
-
codecsStrings.getStringEncoder({
|
|
848
|
-
description: lifetimeTokenDescription,
|
|
849
|
-
encoding: codecsStrings.getBase58Encoder(),
|
|
850
|
-
size: 32
|
|
851
|
-
})
|
|
852
|
-
],
|
|
853
|
-
[
|
|
854
|
-
"instructions",
|
|
855
|
-
codecsDataStructures.getArrayEncoder(getInstructionEncoder(), {
|
|
856
|
-
description: instructionsDescription,
|
|
857
|
-
size: codecsNumbers.getShortU16Encoder()
|
|
858
|
-
})
|
|
859
|
-
]
|
|
791
|
+
["staticAccounts", codecsDataStructures.getArrayEncoder(addresses.getAddressEncoder(), { size: codecsNumbers.getShortU16Encoder() })],
|
|
792
|
+
["lifetimeToken", codecsStrings.getStringEncoder({ encoding: codecsStrings.getBase58Encoder(), size: 32 })],
|
|
793
|
+
["instructions", codecsDataStructures.getArrayEncoder(getInstructionEncoder(), { size: codecsNumbers.getShortU16Encoder() })]
|
|
860
794
|
];
|
|
861
795
|
}
|
|
862
796
|
function getPreludeStructDecoderTuple() {
|
|
863
797
|
return [
|
|
864
798
|
["version", getTransactionVersionDecoder()],
|
|
865
799
|
["header", getMessageHeaderDecoder()],
|
|
866
|
-
[
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
description: staticAccountsDescription,
|
|
870
|
-
size: codecsNumbers.getShortU16Decoder()
|
|
871
|
-
})
|
|
872
|
-
],
|
|
873
|
-
[
|
|
874
|
-
"lifetimeToken",
|
|
875
|
-
codecsStrings.getStringDecoder({
|
|
876
|
-
description: lifetimeTokenDescription,
|
|
877
|
-
encoding: codecsStrings.getBase58Decoder(),
|
|
878
|
-
size: 32
|
|
879
|
-
})
|
|
880
|
-
],
|
|
881
|
-
[
|
|
882
|
-
"instructions",
|
|
883
|
-
codecsDataStructures.getArrayDecoder(getInstructionDecoder(), {
|
|
884
|
-
description: instructionsDescription,
|
|
885
|
-
size: codecsNumbers.getShortU16Decoder()
|
|
886
|
-
})
|
|
887
|
-
],
|
|
800
|
+
["staticAccounts", codecsDataStructures.getArrayDecoder(addresses.getAddressDecoder(), { size: codecsNumbers.getShortU16Decoder() })],
|
|
801
|
+
["lifetimeToken", codecsStrings.getStringDecoder({ encoding: codecsStrings.getBase58Decoder(), size: 32 })],
|
|
802
|
+
["instructions", codecsDataStructures.getArrayDecoder(getInstructionDecoder(), { size: codecsNumbers.getShortU16Decoder() })],
|
|
888
803
|
["addressTableLookups", getAddressTableLookupArrayDecoder()]
|
|
889
804
|
];
|
|
890
805
|
}
|
|
891
806
|
function getAddressTableLookupArrayEncoder() {
|
|
892
|
-
return codecsDataStructures.getArrayEncoder(getAddressTableLookupEncoder(), {
|
|
893
|
-
description: addressTableLookupsDescription,
|
|
894
|
-
size: codecsNumbers.getShortU16Encoder()
|
|
895
|
-
});
|
|
807
|
+
return codecsDataStructures.getArrayEncoder(getAddressTableLookupEncoder(), { size: codecsNumbers.getShortU16Encoder() });
|
|
896
808
|
}
|
|
897
809
|
function getAddressTableLookupArrayDecoder() {
|
|
898
|
-
return codecsDataStructures.getArrayDecoder(getAddressTableLookupDecoder(), {
|
|
899
|
-
description: addressTableLookupsDescription,
|
|
900
|
-
size: codecsNumbers.getShortU16Decoder()
|
|
901
|
-
});
|
|
810
|
+
return codecsDataStructures.getArrayDecoder(getAddressTableLookupDecoder(), { size: codecsNumbers.getShortU16Decoder() });
|
|
902
811
|
}
|
|
903
|
-
var messageDescription = __DEV__ ? "The wire format of a Solana transaction message" : "message";
|
|
904
812
|
function getCompiledMessageEncoder() {
|
|
905
|
-
return {
|
|
906
|
-
|
|
907
|
-
encode: (compiledMessage) => {
|
|
813
|
+
return codecsCore.createEncoder({
|
|
814
|
+
getSizeFromValue: (compiledMessage) => {
|
|
908
815
|
if (compiledMessage.version === "legacy") {
|
|
909
|
-
return getCompiledMessageLegacyEncoder().
|
|
816
|
+
return getCompiledMessageLegacyEncoder().getSizeFromValue(compiledMessage);
|
|
910
817
|
} else {
|
|
911
|
-
return getCompiledMessageVersionedEncoder().
|
|
818
|
+
return getCompiledMessageVersionedEncoder().getSizeFromValue(compiledMessage);
|
|
912
819
|
}
|
|
913
820
|
},
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
821
|
+
write: (compiledMessage, bytes, offset) => {
|
|
822
|
+
if (compiledMessage.version === "legacy") {
|
|
823
|
+
return getCompiledMessageLegacyEncoder().write(compiledMessage, bytes, offset);
|
|
824
|
+
} else {
|
|
825
|
+
return getCompiledMessageVersionedEncoder().write(compiledMessage, bytes, offset);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
});
|
|
917
829
|
}
|
|
918
830
|
function getCompiledMessageDecoder() {
|
|
919
|
-
return codecsCore.mapDecoder(
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
}),
|
|
923
|
-
({ addressTableLookups, ...restOfMessage }) => {
|
|
924
|
-
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
|
|
925
|
-
return restOfMessage;
|
|
926
|
-
}
|
|
927
|
-
return { ...restOfMessage, addressTableLookups };
|
|
831
|
+
return codecsCore.mapDecoder(codecsDataStructures.getStructDecoder(getPreludeStructDecoderTuple()), ({ addressTableLookups, ...restOfMessage }) => {
|
|
832
|
+
if (restOfMessage.version === "legacy" || !addressTableLookups?.length) {
|
|
833
|
+
return restOfMessage;
|
|
928
834
|
}
|
|
929
|
-
|
|
835
|
+
return { ...restOfMessage, addressTableLookups };
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
function getCompiledMessageCodec() {
|
|
839
|
+
return codecsCore.combineCodec(getCompiledMessageEncoder(), getCompiledMessageDecoder());
|
|
930
840
|
}
|
|
931
841
|
|
|
932
|
-
// src/
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
[
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
codecsDataStructures.getArrayEncoder(codecsDataStructures.getBytesEncoder({ size: 64 }), {
|
|
941
|
-
description: signaturesDescription,
|
|
942
|
-
size: codecsNumbers.getShortU16Encoder()
|
|
943
|
-
})
|
|
944
|
-
],
|
|
945
|
-
["compiledMessage", getCompiledMessageEncoder()]
|
|
946
|
-
],
|
|
947
|
-
{
|
|
948
|
-
description: transactionDescription
|
|
842
|
+
// src/compile-transaction.ts
|
|
843
|
+
function getCompiledTransaction(transaction) {
|
|
844
|
+
const compiledMessage = compileMessage(transaction);
|
|
845
|
+
let signatures;
|
|
846
|
+
if ("signatures" in transaction) {
|
|
847
|
+
signatures = [];
|
|
848
|
+
for (let ii = 0; ii < compiledMessage.header.numSignerAccounts; ii++) {
|
|
849
|
+
signatures[ii] = transaction.signatures[compiledMessage.staticAccounts[ii]] ?? new Uint8Array(Array(64).fill(0));
|
|
949
850
|
}
|
|
950
|
-
|
|
851
|
+
} else {
|
|
852
|
+
signatures = Array(compiledMessage.header.numSignerAccounts).fill(new Uint8Array(Array(64).fill(0)));
|
|
853
|
+
}
|
|
854
|
+
return {
|
|
855
|
+
compiledMessage,
|
|
856
|
+
signatures
|
|
857
|
+
};
|
|
951
858
|
}
|
|
952
|
-
|
|
953
|
-
|
|
859
|
+
|
|
860
|
+
// src/serializers/transaction.ts
|
|
861
|
+
function getCompiledTransactionEncoder() {
|
|
862
|
+
return codecsDataStructures.getStructEncoder([
|
|
863
|
+
["signatures", codecsDataStructures.getArrayEncoder(codecsDataStructures.getBytesEncoder({ size: 64 }), { size: codecsNumbers.getShortU16Encoder() })],
|
|
864
|
+
["compiledMessage", getCompiledMessageEncoder()]
|
|
865
|
+
]);
|
|
954
866
|
}
|
|
955
867
|
function getCompiledTransactionDecoder() {
|
|
956
|
-
return codecsDataStructures.getStructDecoder(
|
|
868
|
+
return codecsDataStructures.getStructDecoder([
|
|
957
869
|
[
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
size: codecsNumbers.getShortU16Decoder()
|
|
963
|
-
})
|
|
964
|
-
],
|
|
965
|
-
["compiledMessage", getCompiledMessageDecoder()]
|
|
870
|
+
"signatures",
|
|
871
|
+
codecsDataStructures.getArrayDecoder(codecsDataStructures.getBytesDecoder({ size: 64 }), {
|
|
872
|
+
size: codecsNumbers.getShortU16Decoder()
|
|
873
|
+
})
|
|
966
874
|
],
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
}
|
|
970
|
-
);
|
|
875
|
+
["compiledMessage", getCompiledMessageDecoder()]
|
|
876
|
+
]);
|
|
971
877
|
}
|
|
972
878
|
function getTransactionEncoder() {
|
|
973
879
|
return codecsCore.mapEncoder(getCompiledTransactionEncoder(), getCompiledTransaction);
|
|
974
880
|
}
|
|
975
|
-
function getTransactionDecoder(
|
|
881
|
+
function getTransactionDecoder(config) {
|
|
976
882
|
return codecsCore.mapDecoder(
|
|
977
883
|
getCompiledTransactionDecoder(),
|
|
978
|
-
(compiledTransaction) => decompileTransaction(compiledTransaction,
|
|
884
|
+
(compiledTransaction) => decompileTransaction(compiledTransaction, config)
|
|
979
885
|
);
|
|
980
886
|
}
|
|
981
|
-
function getTransactionCodec(
|
|
982
|
-
return codecsCore.combineCodec(getTransactionEncoder(), getTransactionDecoder(
|
|
983
|
-
}
|
|
984
|
-
function assertIsTransactionSignature(putativeTransactionSignature) {
|
|
985
|
-
try {
|
|
986
|
-
if (
|
|
987
|
-
// Lowest value (64 bytes of zeroes)
|
|
988
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
989
|
-
putativeTransactionSignature.length > 88
|
|
990
|
-
) {
|
|
991
|
-
throw new Error("Expected input string to decode to a byte array of length 64.");
|
|
992
|
-
}
|
|
993
|
-
const bytes = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
994
|
-
const numBytes = bytes.byteLength;
|
|
995
|
-
if (numBytes !== 64) {
|
|
996
|
-
throw new Error(`Expected input string to decode to a byte array of length 64. Actual length: ${numBytes}`);
|
|
997
|
-
}
|
|
998
|
-
} catch (e) {
|
|
999
|
-
throw new Error(`\`${putativeTransactionSignature}\` is not a transaction signature`, {
|
|
1000
|
-
cause: e
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
function isTransactionSignature(putativeTransactionSignature) {
|
|
1005
|
-
if (
|
|
1006
|
-
// Lowest value (64 bytes of zeroes)
|
|
1007
|
-
putativeTransactionSignature.length < 64 || // Highest value (64 bytes of 255)
|
|
1008
|
-
putativeTransactionSignature.length > 88
|
|
1009
|
-
) {
|
|
1010
|
-
return false;
|
|
1011
|
-
}
|
|
1012
|
-
const bytes = umiSerializers.base58.serialize(putativeTransactionSignature);
|
|
1013
|
-
const numBytes = bytes.byteLength;
|
|
1014
|
-
if (numBytes !== 64) {
|
|
1015
|
-
return false;
|
|
1016
|
-
}
|
|
1017
|
-
return true;
|
|
887
|
+
function getTransactionCodec(config) {
|
|
888
|
+
return codecsCore.combineCodec(getTransactionEncoder(), getTransactionDecoder(config));
|
|
1018
889
|
}
|
|
890
|
+
var base58Decoder;
|
|
1019
891
|
function getSignatureFromTransaction(transaction) {
|
|
892
|
+
if (!base58Decoder)
|
|
893
|
+
base58Decoder = codecsStrings.getBase58Decoder();
|
|
1020
894
|
const signatureBytes = transaction.signatures[transaction.feePayer];
|
|
1021
895
|
if (!signatureBytes) {
|
|
1022
|
-
throw new
|
|
1023
|
-
"Could not determine this transaction's signature. Make sure that the transaction has been signed by its fee payer."
|
|
1024
|
-
);
|
|
896
|
+
throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_SIGNATURE_NOT_COMPUTABLE);
|
|
1025
897
|
}
|
|
1026
|
-
const
|
|
1027
|
-
return
|
|
898
|
+
const transactionSignature = base58Decoder.decode(signatureBytes);
|
|
899
|
+
return transactionSignature;
|
|
1028
900
|
}
|
|
1029
|
-
async function
|
|
901
|
+
async function partiallySignTransaction(keyPairs, transaction) {
|
|
1030
902
|
const compiledMessage = compileMessage(transaction);
|
|
1031
903
|
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1032
904
|
const wireMessageBytes = getCompiledMessageEncoder().encode(compiledMessage);
|
|
@@ -1045,46 +917,54 @@ async function signTransaction(keyPairs, transaction) {
|
|
|
1045
917
|
Object.freeze(out);
|
|
1046
918
|
return out;
|
|
1047
919
|
}
|
|
1048
|
-
function
|
|
1049
|
-
|
|
1050
|
-
|
|
920
|
+
async function signTransaction(keyPairs, transaction) {
|
|
921
|
+
const out = await partiallySignTransaction(keyPairs, transaction);
|
|
922
|
+
assertTransactionIsFullySigned(out);
|
|
923
|
+
Object.freeze(out);
|
|
924
|
+
return out;
|
|
1051
925
|
}
|
|
1052
926
|
function assertTransactionIsFullySigned(transaction) {
|
|
1053
927
|
const signerAddressesFromInstructions = transaction.instructions.flatMap((i) => i.accounts?.filter((a) => isSignerRole(a.role)) ?? []).map((a) => a.address);
|
|
1054
928
|
const requiredSigners = /* @__PURE__ */ new Set([transaction.feePayer, ...signerAddressesFromInstructions]);
|
|
929
|
+
const missingSigs = [];
|
|
1055
930
|
requiredSigners.forEach((address) => {
|
|
1056
931
|
if (!transaction.signatures[address]) {
|
|
1057
|
-
|
|
932
|
+
missingSigs.push(address);
|
|
1058
933
|
}
|
|
1059
934
|
});
|
|
935
|
+
if (missingSigs.length > 0) {
|
|
936
|
+
throw new errors.SolanaError(errors.SOLANA_ERROR__TRANSACTION_MISSING_SIGNATURES, {
|
|
937
|
+
addresses: missingSigs
|
|
938
|
+
});
|
|
939
|
+
}
|
|
1060
940
|
}
|
|
1061
|
-
|
|
1062
|
-
// src/wire-transaction.ts
|
|
1063
941
|
function getBase64EncodedWireTransaction(transaction) {
|
|
1064
942
|
const wireTransactionBytes = getTransactionEncoder().encode(transaction);
|
|
1065
|
-
|
|
1066
|
-
return btoa(String.fromCharCode(...wireTransactionBytes));
|
|
1067
|
-
}
|
|
943
|
+
return codecsStrings.getBase64Decoder().decode(wireTransactionBytes);
|
|
1068
944
|
}
|
|
1069
945
|
|
|
1070
946
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
1071
|
-
exports.assertIsBlockhash = assertIsBlockhash;
|
|
1072
947
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
1073
|
-
exports.
|
|
948
|
+
exports.assertIsTransactionWithBlockhashLifetime = assertIsTransactionWithBlockhashLifetime;
|
|
1074
949
|
exports.assertTransactionIsFullySigned = assertTransactionIsFullySigned;
|
|
950
|
+
exports.compileMessage = compileMessage;
|
|
1075
951
|
exports.createTransaction = createTransaction;
|
|
952
|
+
exports.decompileTransaction = decompileTransaction;
|
|
1076
953
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
954
|
+
exports.getCompiledMessageCodec = getCompiledMessageCodec;
|
|
955
|
+
exports.getCompiledMessageDecoder = getCompiledMessageDecoder;
|
|
956
|
+
exports.getCompiledMessageEncoder = getCompiledMessageEncoder;
|
|
957
|
+
exports.getCompiledTransactionDecoder = getCompiledTransactionDecoder;
|
|
1077
958
|
exports.getSignatureFromTransaction = getSignatureFromTransaction;
|
|
1078
959
|
exports.getTransactionCodec = getTransactionCodec;
|
|
1079
960
|
exports.getTransactionDecoder = getTransactionDecoder;
|
|
1080
961
|
exports.getTransactionEncoder = getTransactionEncoder;
|
|
1081
962
|
exports.isAdvanceNonceAccountInstruction = isAdvanceNonceAccountInstruction;
|
|
1082
|
-
exports.
|
|
963
|
+
exports.partiallySignTransaction = partiallySignTransaction;
|
|
1083
964
|
exports.prependTransactionInstruction = prependTransactionInstruction;
|
|
1084
965
|
exports.setTransactionFeePayer = setTransactionFeePayer;
|
|
1085
966
|
exports.setTransactionLifetimeUsingBlockhash = setTransactionLifetimeUsingBlockhash;
|
|
1086
967
|
exports.setTransactionLifetimeUsingDurableNonce = setTransactionLifetimeUsingDurableNonce;
|
|
1087
968
|
exports.signTransaction = signTransaction;
|
|
1088
|
-
exports.transactionSignature = transactionSignature;
|
|
1089
969
|
//# sourceMappingURL=out.js.map
|
|
1090
970
|
//# sourceMappingURL=index.browser.cjs.map
|