@solana/web3.js 1.56.1 → 1.58.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/lib/index.browser.cjs.js +498 -13
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +497 -14
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +498 -13
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3060 -2948
- package/lib/index.esm.js +497 -14
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +498 -13
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +498 -13
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -1
- package/src/connection.ts +112 -2
- package/src/message/account-keys.ts +79 -0
- package/src/message/compiled-keys.ts +165 -0
- package/src/message/index.ts +2 -0
- package/src/message/legacy.ts +34 -2
- package/src/message/v0.ts +137 -0
- package/src/publickey.ts +12 -0
- package/src/transaction/index.ts +1 -0
- package/src/transaction/message.ts +147 -0
package/lib/index.esm.js
CHANGED
|
@@ -115,12 +115,14 @@ const PUBLIC_KEY_LENGTH = 32;
|
|
|
115
115
|
|
|
116
116
|
function isPublicKeyData(value) {
|
|
117
117
|
return value._bn !== undefined;
|
|
118
|
-
}
|
|
118
|
+
} // local counter used by PublicKey.unique()
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
let uniquePublicKeyCounter = 1;
|
|
119
122
|
/**
|
|
120
123
|
* A public key
|
|
121
124
|
*/
|
|
122
125
|
|
|
123
|
-
|
|
124
126
|
class PublicKey extends Struct {
|
|
125
127
|
/** @internal */
|
|
126
128
|
|
|
@@ -153,6 +155,16 @@ class PublicKey extends Struct {
|
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Returns a unique PublicKey for tests and benchmarks using acounter
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
static unique() {
|
|
164
|
+
const key = new PublicKey(uniquePublicKeyCounter);
|
|
165
|
+
uniquePublicKeyCounter += 1;
|
|
166
|
+
return new PublicKey(key.toBuffer());
|
|
167
|
+
}
|
|
156
168
|
/**
|
|
157
169
|
* Default public key value. (All zeros)
|
|
158
170
|
*/
|
|
@@ -409,6 +421,71 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
|
409
421
|
value: 'TransactionExpiredTimeoutError'
|
|
410
422
|
});
|
|
411
423
|
|
|
424
|
+
class MessageAccountKeys {
|
|
425
|
+
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
426
|
+
this.staticAccountKeys = void 0;
|
|
427
|
+
this.accountKeysFromLookups = void 0;
|
|
428
|
+
this.staticAccountKeys = staticAccountKeys;
|
|
429
|
+
this.accountKeysFromLookups = accountKeysFromLookups;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
keySegments() {
|
|
433
|
+
const keySegments = [this.staticAccountKeys];
|
|
434
|
+
|
|
435
|
+
if (this.accountKeysFromLookups) {
|
|
436
|
+
keySegments.push(this.accountKeysFromLookups.writable);
|
|
437
|
+
keySegments.push(this.accountKeysFromLookups.readonly);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
return keySegments;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
get(index) {
|
|
444
|
+
for (const keySegment of this.keySegments()) {
|
|
445
|
+
if (index < keySegment.length) {
|
|
446
|
+
return keySegment[index];
|
|
447
|
+
} else {
|
|
448
|
+
index -= keySegment.length;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
get length() {
|
|
456
|
+
return this.keySegments().flat().length;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
compileInstructions(instructions) {
|
|
460
|
+
// Bail early if any account indexes would overflow a u8
|
|
461
|
+
const U8_MAX = 255;
|
|
462
|
+
|
|
463
|
+
if (this.length > U8_MAX + 1) {
|
|
464
|
+
throw new Error('Account index overflow encountered during compilation');
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const keyIndexMap = new Map();
|
|
468
|
+
this.keySegments().flat().forEach((key, index) => {
|
|
469
|
+
keyIndexMap.set(key.toBase58(), index);
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
const findKeyIndex = key => {
|
|
473
|
+
const keyIndex = keyIndexMap.get(key.toBase58());
|
|
474
|
+
if (keyIndex === undefined) throw new Error('Encountered an unknown instruction account key during compilation');
|
|
475
|
+
return keyIndex;
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
return instructions.map(instruction => {
|
|
479
|
+
return {
|
|
480
|
+
programIdIndex: findKeyIndex(instruction.programId),
|
|
481
|
+
accountKeyIndexes: instruction.keys.map(meta => findKeyIndex(meta.pubkey)),
|
|
482
|
+
data: instruction.data
|
|
483
|
+
};
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
}
|
|
488
|
+
|
|
412
489
|
/**
|
|
413
490
|
* Layout for a public key
|
|
414
491
|
*/
|
|
@@ -534,6 +611,129 @@ function encodeLength(bytes, len) {
|
|
|
534
611
|
}
|
|
535
612
|
}
|
|
536
613
|
|
|
614
|
+
function assert (condition, message) {
|
|
615
|
+
if (!condition) {
|
|
616
|
+
throw new Error(message || 'Assertion failed');
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
class CompiledKeys {
|
|
621
|
+
constructor(payer, keyMetaMap) {
|
|
622
|
+
this.payer = void 0;
|
|
623
|
+
this.keyMetaMap = void 0;
|
|
624
|
+
this.payer = payer;
|
|
625
|
+
this.keyMetaMap = keyMetaMap;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
static compile(instructions, payer) {
|
|
629
|
+
const keyMetaMap = new Map();
|
|
630
|
+
|
|
631
|
+
const getOrInsertDefault = pubkey => {
|
|
632
|
+
const address = pubkey.toBase58();
|
|
633
|
+
let keyMeta = keyMetaMap.get(address);
|
|
634
|
+
|
|
635
|
+
if (keyMeta === undefined) {
|
|
636
|
+
keyMeta = {
|
|
637
|
+
isSigner: false,
|
|
638
|
+
isWritable: false,
|
|
639
|
+
isInvoked: false
|
|
640
|
+
};
|
|
641
|
+
keyMetaMap.set(address, keyMeta);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
return keyMeta;
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
const payerKeyMeta = getOrInsertDefault(payer);
|
|
648
|
+
payerKeyMeta.isSigner = true;
|
|
649
|
+
payerKeyMeta.isWritable = true;
|
|
650
|
+
|
|
651
|
+
for (const ix of instructions) {
|
|
652
|
+
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
653
|
+
|
|
654
|
+
for (const accountMeta of ix.keys) {
|
|
655
|
+
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
656
|
+
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
657
|
+
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
return new CompiledKeys(payer, keyMetaMap);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
getMessageComponents() {
|
|
665
|
+
const mapEntries = [...this.keyMetaMap.entries()];
|
|
666
|
+
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
667
|
+
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
668
|
+
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
669
|
+
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
670
|
+
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
671
|
+
const header = {
|
|
672
|
+
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
673
|
+
numReadonlySignedAccounts: readonlySigners.length,
|
|
674
|
+
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
675
|
+
}; // sanity checks
|
|
676
|
+
|
|
677
|
+
{
|
|
678
|
+
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
679
|
+
const [payerAddress] = writableSigners[0];
|
|
680
|
+
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
681
|
+
}
|
|
682
|
+
const staticAccountKeys = [...writableSigners.map(([address]) => new PublicKey(address)), ...readonlySigners.map(([address]) => new PublicKey(address)), ...writableNonSigners.map(([address]) => new PublicKey(address)), ...readonlyNonSigners.map(([address]) => new PublicKey(address))];
|
|
683
|
+
return [header, staticAccountKeys];
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
extractTableLookup(lookupTable) {
|
|
687
|
+
const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
|
|
688
|
+
const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
|
|
689
|
+
|
|
690
|
+
if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
return [{
|
|
695
|
+
accountKey: lookupTable.key,
|
|
696
|
+
writableIndexes,
|
|
697
|
+
readonlyIndexes
|
|
698
|
+
}, {
|
|
699
|
+
writable: drainedWritableKeys,
|
|
700
|
+
readonly: drainedReadonlyKeys
|
|
701
|
+
}];
|
|
702
|
+
}
|
|
703
|
+
/** @internal */
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
|
|
707
|
+
const lookupTableIndexes = new Array();
|
|
708
|
+
const drainedKeys = new Array();
|
|
709
|
+
|
|
710
|
+
for (const [address, keyMeta] of this.keyMetaMap.entries()) {
|
|
711
|
+
if (keyMetaFilter(keyMeta)) {
|
|
712
|
+
const key = new PublicKey(address);
|
|
713
|
+
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
714
|
+
|
|
715
|
+
if (lookupTableIndex >= 0) {
|
|
716
|
+
assert(lookupTableIndex < 256, 'Max lookup table index exceeded');
|
|
717
|
+
lookupTableIndexes.push(lookupTableIndex);
|
|
718
|
+
drainedKeys.push(key);
|
|
719
|
+
this.keyMetaMap.delete(address);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
return [lookupTableIndexes, drainedKeys];
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* An instruction to execute by a program
|
|
731
|
+
*
|
|
732
|
+
* @property {number} programIdIndex
|
|
733
|
+
* @property {number[]} accounts
|
|
734
|
+
* @property {string} data
|
|
735
|
+
*/
|
|
736
|
+
|
|
537
737
|
/**
|
|
538
738
|
* List of instructions to be processed atomically
|
|
539
739
|
*/
|
|
@@ -571,6 +771,27 @@ class Message {
|
|
|
571
771
|
return [];
|
|
572
772
|
}
|
|
573
773
|
|
|
774
|
+
getAccountKeys() {
|
|
775
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
static compile(args) {
|
|
779
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
780
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
781
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
782
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
783
|
+
programIdIndex: ix.programIdIndex,
|
|
784
|
+
accounts: ix.accountKeyIndexes,
|
|
785
|
+
data: bs58.encode(ix.data)
|
|
786
|
+
}));
|
|
787
|
+
return new Message({
|
|
788
|
+
header,
|
|
789
|
+
accountKeys: staticAccountKeys,
|
|
790
|
+
recentBlockhash: args.recentBlockhash,
|
|
791
|
+
instructions
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
|
|
574
795
|
isAccountSigner(index) {
|
|
575
796
|
return index < this.header.numRequiredSignatures;
|
|
576
797
|
}
|
|
@@ -660,7 +881,7 @@ class Message {
|
|
|
660
881
|
for (let i = 0; i < accountCount; i++) {
|
|
661
882
|
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
662
883
|
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
663
|
-
accountKeys.push(
|
|
884
|
+
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
664
885
|
}
|
|
665
886
|
|
|
666
887
|
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
@@ -699,12 +920,6 @@ class Message {
|
|
|
699
920
|
|
|
700
921
|
}
|
|
701
922
|
|
|
702
|
-
function assert (condition, message) {
|
|
703
|
-
if (!condition) {
|
|
704
|
-
throw new Error(message || 'Assertion failed');
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
|
|
708
923
|
/**
|
|
709
924
|
* Message constructor arguments
|
|
710
925
|
*/
|
|
@@ -727,6 +942,102 @@ class MessageV0 {
|
|
|
727
942
|
return 0;
|
|
728
943
|
}
|
|
729
944
|
|
|
945
|
+
get numAccountKeysFromLookups() {
|
|
946
|
+
let count = 0;
|
|
947
|
+
|
|
948
|
+
for (const lookup of this.addressTableLookups) {
|
|
949
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
return count;
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
getAccountKeys(args) {
|
|
956
|
+
let accountKeysFromLookups;
|
|
957
|
+
|
|
958
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
959
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
960
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
964
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
965
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
966
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
967
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
974
|
+
const accountKeysFromLookups = {
|
|
975
|
+
writable: [],
|
|
976
|
+
readonly: []
|
|
977
|
+
};
|
|
978
|
+
|
|
979
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
980
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
981
|
+
|
|
982
|
+
if (!tableAccount) {
|
|
983
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
for (const index of tableLookup.writableIndexes) {
|
|
987
|
+
if (index < tableAccount.state.addresses.length) {
|
|
988
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
989
|
+
} else {
|
|
990
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
995
|
+
if (index < tableAccount.state.addresses.length) {
|
|
996
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
997
|
+
} else {
|
|
998
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
return accountKeysFromLookups;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
static compile(args) {
|
|
1007
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
1008
|
+
const addressTableLookups = new Array();
|
|
1009
|
+
const accountKeysFromLookups = {
|
|
1010
|
+
writable: new Array(),
|
|
1011
|
+
readonly: new Array()
|
|
1012
|
+
};
|
|
1013
|
+
const lookupTableAccounts = args.addressLookupTableAccounts || [];
|
|
1014
|
+
|
|
1015
|
+
for (const lookupTable of lookupTableAccounts) {
|
|
1016
|
+
const extractResult = compiledKeys.extractTableLookup(lookupTable);
|
|
1017
|
+
|
|
1018
|
+
if (extractResult !== undefined) {
|
|
1019
|
+
const [addressTableLookup, {
|
|
1020
|
+
writable,
|
|
1021
|
+
readonly
|
|
1022
|
+
}] = extractResult;
|
|
1023
|
+
addressTableLookups.push(addressTableLookup);
|
|
1024
|
+
accountKeysFromLookups.writable.push(...writable);
|
|
1025
|
+
accountKeysFromLookups.readonly.push(...readonly);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
1030
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys, accountKeysFromLookups);
|
|
1031
|
+
const compiledInstructions = accountKeys.compileInstructions(args.instructions);
|
|
1032
|
+
return new MessageV0({
|
|
1033
|
+
header,
|
|
1034
|
+
staticAccountKeys,
|
|
1035
|
+
recentBlockhash: args.recentBlockhash,
|
|
1036
|
+
compiledInstructions,
|
|
1037
|
+
addressTableLookups
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
|
|
730
1041
|
serialize() {
|
|
731
1042
|
const encodedStaticAccountKeysLength = Array();
|
|
732
1043
|
encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
|
|
@@ -1621,6 +1932,114 @@ class Transaction {
|
|
|
1621
1932
|
|
|
1622
1933
|
}
|
|
1623
1934
|
|
|
1935
|
+
class TransactionMessage {
|
|
1936
|
+
constructor(args) {
|
|
1937
|
+
this.accountKeys = void 0;
|
|
1938
|
+
this.instructions = void 0;
|
|
1939
|
+
this.recentBlockhash = void 0;
|
|
1940
|
+
this.accountKeys = args.accountKeys;
|
|
1941
|
+
this.instructions = args.instructions;
|
|
1942
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
static decompile(message, args) {
|
|
1946
|
+
const {
|
|
1947
|
+
header,
|
|
1948
|
+
compiledInstructions,
|
|
1949
|
+
recentBlockhash
|
|
1950
|
+
} = message;
|
|
1951
|
+
const {
|
|
1952
|
+
numRequiredSignatures,
|
|
1953
|
+
numReadonlySignedAccounts,
|
|
1954
|
+
numReadonlyUnsignedAccounts
|
|
1955
|
+
} = header;
|
|
1956
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
1957
|
+
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
1958
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1959
|
+
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1960
|
+
const accountKeys = message.getAccountKeys(args);
|
|
1961
|
+
const instructions = [];
|
|
1962
|
+
|
|
1963
|
+
for (const compiledIx of compiledInstructions) {
|
|
1964
|
+
const keys = [];
|
|
1965
|
+
|
|
1966
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
1967
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
1968
|
+
|
|
1969
|
+
if (pubkey === undefined) {
|
|
1970
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
1974
|
+
let isWritable;
|
|
1975
|
+
|
|
1976
|
+
if (isSigner) {
|
|
1977
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
1978
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
1979
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
1980
|
+
} else {
|
|
1981
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
1982
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
keys.push({
|
|
1986
|
+
pubkey,
|
|
1987
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
1988
|
+
isWritable
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
1993
|
+
|
|
1994
|
+
if (programId === undefined) {
|
|
1995
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
instructions.push(new TransactionInstruction({
|
|
1999
|
+
programId,
|
|
2000
|
+
data: toBuffer(compiledIx.data),
|
|
2001
|
+
keys
|
|
2002
|
+
}));
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
return new TransactionMessage({
|
|
2006
|
+
accountKeys,
|
|
2007
|
+
instructions,
|
|
2008
|
+
recentBlockhash
|
|
2009
|
+
});
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
compileToLegacyMessage() {
|
|
2013
|
+
const payerKey = this.accountKeys.get(0);
|
|
2014
|
+
|
|
2015
|
+
if (payerKey === undefined) {
|
|
2016
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
return Message.compile({
|
|
2020
|
+
payerKey,
|
|
2021
|
+
recentBlockhash: this.recentBlockhash,
|
|
2022
|
+
instructions: this.instructions
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
2027
|
+
const payerKey = this.accountKeys.get(0);
|
|
2028
|
+
|
|
2029
|
+
if (payerKey === undefined) {
|
|
2030
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
return MessageV0.compile({
|
|
2034
|
+
payerKey,
|
|
2035
|
+
recentBlockhash: this.recentBlockhash,
|
|
2036
|
+
instructions: this.instructions,
|
|
2037
|
+
addressLookupTableAccounts
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
}
|
|
2042
|
+
|
|
1624
2043
|
/**
|
|
1625
2044
|
* Versioned transaction class
|
|
1626
2045
|
*/
|
|
@@ -3945,7 +4364,8 @@ const ConfirmedTransactionMetaResult = type({
|
|
|
3945
4364
|
logMessages: optional(nullable(array(string()))),
|
|
3946
4365
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3947
4366
|
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3948
|
-
loadedAddresses: optional(LoadedAddressesResult)
|
|
4367
|
+
loadedAddresses: optional(LoadedAddressesResult),
|
|
4368
|
+
computeUnitsConsumed: optional(number())
|
|
3949
4369
|
});
|
|
3950
4370
|
/**
|
|
3951
4371
|
* @internal
|
|
@@ -3963,7 +4383,8 @@ const ParsedConfirmedTransactionMetaResult = type({
|
|
|
3963
4383
|
logMessages: optional(nullable(array(string()))),
|
|
3964
4384
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3965
4385
|
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3966
|
-
loadedAddresses: optional(LoadedAddressesResult)
|
|
4386
|
+
loadedAddresses: optional(LoadedAddressesResult),
|
|
4387
|
+
computeUnitsConsumed: optional(number())
|
|
3967
4388
|
});
|
|
3968
4389
|
const TransactionVersionStruct = union([literal(0), literal('legacy')]);
|
|
3969
4390
|
/**
|
|
@@ -5982,10 +6403,44 @@ class Connection {
|
|
|
5982
6403
|
}
|
|
5983
6404
|
/**
|
|
5984
6405
|
* Simulate a transaction
|
|
6406
|
+
*
|
|
6407
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
6408
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
5985
6409
|
*/
|
|
5986
6410
|
|
|
5987
6411
|
|
|
5988
|
-
|
|
6412
|
+
/**
|
|
6413
|
+
* Simulate a transaction
|
|
6414
|
+
*/
|
|
6415
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6416
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
6417
|
+
if ('message' in transactionOrMessage) {
|
|
6418
|
+
const versionedTx = transactionOrMessage;
|
|
6419
|
+
const wireTransaction = versionedTx.serialize();
|
|
6420
|
+
const encodedTransaction = Buffer.from(wireTransaction).toString('base64');
|
|
6421
|
+
|
|
6422
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
6423
|
+
throw new Error('Invalid arguments');
|
|
6424
|
+
}
|
|
6425
|
+
|
|
6426
|
+
const config = configOrSigners || {};
|
|
6427
|
+
config.encoding = 'base64';
|
|
6428
|
+
|
|
6429
|
+
if (!('commitment' in config)) {
|
|
6430
|
+
config.commitment = this.commitment;
|
|
6431
|
+
}
|
|
6432
|
+
|
|
6433
|
+
const args = [encodedTransaction, config];
|
|
6434
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
6435
|
+
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
6436
|
+
|
|
6437
|
+
if ('error' in res) {
|
|
6438
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
6439
|
+
}
|
|
6440
|
+
|
|
6441
|
+
return res.result;
|
|
6442
|
+
}
|
|
6443
|
+
|
|
5989
6444
|
let transaction;
|
|
5990
6445
|
|
|
5991
6446
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -6001,6 +6456,12 @@ class Connection {
|
|
|
6001
6456
|
transaction._message = transaction._json = undefined;
|
|
6002
6457
|
}
|
|
6003
6458
|
|
|
6459
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
6460
|
+
throw new Error('Invalid arguments');
|
|
6461
|
+
}
|
|
6462
|
+
|
|
6463
|
+
const signers = configOrSigners;
|
|
6464
|
+
|
|
6004
6465
|
if (transaction.nonceInfo && signers) {
|
|
6005
6466
|
transaction.sign(...signers);
|
|
6006
6467
|
} else {
|
|
@@ -6081,12 +6542,34 @@ class Connection {
|
|
|
6081
6542
|
|
|
6082
6543
|
return res.result;
|
|
6083
6544
|
}
|
|
6545
|
+
/**
|
|
6546
|
+
* Sign and send a transaction
|
|
6547
|
+
*
|
|
6548
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
6549
|
+
* VersionedTransaction}
|
|
6550
|
+
*/
|
|
6551
|
+
|
|
6552
|
+
|
|
6084
6553
|
/**
|
|
6085
6554
|
* Sign and send a transaction
|
|
6086
6555
|
*/
|
|
6556
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6557
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
6558
|
+
if ('message' in transaction) {
|
|
6559
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
6560
|
+
throw new Error('Invalid arguments');
|
|
6561
|
+
}
|
|
6562
|
+
|
|
6563
|
+
const wireTransaction = transaction.serialize();
|
|
6564
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
6565
|
+
}
|
|
6566
|
+
|
|
6567
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6568
|
+
throw new Error('Invalid arguments');
|
|
6569
|
+
}
|
|
6087
6570
|
|
|
6571
|
+
const signers = signersOrOptions;
|
|
6088
6572
|
|
|
6089
|
-
async sendTransaction(transaction, signers, options) {
|
|
6090
6573
|
if (transaction.nonceInfo) {
|
|
6091
6574
|
transaction.sign(...signers);
|
|
6092
6575
|
} else {
|
|
@@ -9113,5 +9596,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9113
9596
|
|
|
9114
9597
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9115
9598
|
|
|
9116
|
-
export { Account, AddressLookupTableAccount, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, MessageV0, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PUBLIC_KEY_LENGTH, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionStatus, VALIDATOR_INFO_KEY, VERSION_PREFIX_MASK, VOTE_PROGRAM_ID, ValidatorInfo, VersionedMessage, VersionedTransaction, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9599
|
+
export { Account, AddressLookupTableAccount, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, MessageAccountKeys, MessageV0, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PUBLIC_KEY_LENGTH, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionMessage, TransactionStatus, VALIDATOR_INFO_KEY, VERSION_PREFIX_MASK, VOTE_PROGRAM_ID, ValidatorInfo, VersionedMessage, VersionedTransaction, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9117
9600
|
//# sourceMappingURL=index.esm.js.map
|