@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.browser.cjs.js
CHANGED
|
@@ -143,12 +143,14 @@ const PUBLIC_KEY_LENGTH = 32;
|
|
|
143
143
|
|
|
144
144
|
function isPublicKeyData(value) {
|
|
145
145
|
return value._bn !== undefined;
|
|
146
|
-
}
|
|
146
|
+
} // local counter used by PublicKey.unique()
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
let uniquePublicKeyCounter = 1;
|
|
147
150
|
/**
|
|
148
151
|
* A public key
|
|
149
152
|
*/
|
|
150
153
|
|
|
151
|
-
|
|
152
154
|
class PublicKey extends Struct {
|
|
153
155
|
/** @internal */
|
|
154
156
|
|
|
@@ -181,6 +183,16 @@ class PublicKey extends Struct {
|
|
|
181
183
|
}
|
|
182
184
|
}
|
|
183
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Returns a unique PublicKey for tests and benchmarks using acounter
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
static unique() {
|
|
192
|
+
const key = new PublicKey(uniquePublicKeyCounter);
|
|
193
|
+
uniquePublicKeyCounter += 1;
|
|
194
|
+
return new PublicKey(key.toBuffer());
|
|
195
|
+
}
|
|
184
196
|
/**
|
|
185
197
|
* Default public key value. (All zeros)
|
|
186
198
|
*/
|
|
@@ -437,6 +449,71 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
|
437
449
|
value: 'TransactionExpiredTimeoutError'
|
|
438
450
|
});
|
|
439
451
|
|
|
452
|
+
class MessageAccountKeys {
|
|
453
|
+
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
454
|
+
this.staticAccountKeys = void 0;
|
|
455
|
+
this.accountKeysFromLookups = void 0;
|
|
456
|
+
this.staticAccountKeys = staticAccountKeys;
|
|
457
|
+
this.accountKeysFromLookups = accountKeysFromLookups;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
keySegments() {
|
|
461
|
+
const keySegments = [this.staticAccountKeys];
|
|
462
|
+
|
|
463
|
+
if (this.accountKeysFromLookups) {
|
|
464
|
+
keySegments.push(this.accountKeysFromLookups.writable);
|
|
465
|
+
keySegments.push(this.accountKeysFromLookups.readonly);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return keySegments;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
get(index) {
|
|
472
|
+
for (const keySegment of this.keySegments()) {
|
|
473
|
+
if (index < keySegment.length) {
|
|
474
|
+
return keySegment[index];
|
|
475
|
+
} else {
|
|
476
|
+
index -= keySegment.length;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
get length() {
|
|
484
|
+
return this.keySegments().flat().length;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
compileInstructions(instructions) {
|
|
488
|
+
// Bail early if any account indexes would overflow a u8
|
|
489
|
+
const U8_MAX = 255;
|
|
490
|
+
|
|
491
|
+
if (this.length > U8_MAX + 1) {
|
|
492
|
+
throw new Error('Account index overflow encountered during compilation');
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const keyIndexMap = new Map();
|
|
496
|
+
this.keySegments().flat().forEach((key, index) => {
|
|
497
|
+
keyIndexMap.set(key.toBase58(), index);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
const findKeyIndex = key => {
|
|
501
|
+
const keyIndex = keyIndexMap.get(key.toBase58());
|
|
502
|
+
if (keyIndex === undefined) throw new Error('Encountered an unknown instruction account key during compilation');
|
|
503
|
+
return keyIndex;
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
return instructions.map(instruction => {
|
|
507
|
+
return {
|
|
508
|
+
programIdIndex: findKeyIndex(instruction.programId),
|
|
509
|
+
accountKeyIndexes: instruction.keys.map(meta => findKeyIndex(meta.pubkey)),
|
|
510
|
+
data: instruction.data
|
|
511
|
+
};
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
}
|
|
516
|
+
|
|
440
517
|
/**
|
|
441
518
|
* Layout for a public key
|
|
442
519
|
*/
|
|
@@ -562,6 +639,129 @@ function encodeLength(bytes, len) {
|
|
|
562
639
|
}
|
|
563
640
|
}
|
|
564
641
|
|
|
642
|
+
function assert (condition, message) {
|
|
643
|
+
if (!condition) {
|
|
644
|
+
throw new Error(message || 'Assertion failed');
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
class CompiledKeys {
|
|
649
|
+
constructor(payer, keyMetaMap) {
|
|
650
|
+
this.payer = void 0;
|
|
651
|
+
this.keyMetaMap = void 0;
|
|
652
|
+
this.payer = payer;
|
|
653
|
+
this.keyMetaMap = keyMetaMap;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
static compile(instructions, payer) {
|
|
657
|
+
const keyMetaMap = new Map();
|
|
658
|
+
|
|
659
|
+
const getOrInsertDefault = pubkey => {
|
|
660
|
+
const address = pubkey.toBase58();
|
|
661
|
+
let keyMeta = keyMetaMap.get(address);
|
|
662
|
+
|
|
663
|
+
if (keyMeta === undefined) {
|
|
664
|
+
keyMeta = {
|
|
665
|
+
isSigner: false,
|
|
666
|
+
isWritable: false,
|
|
667
|
+
isInvoked: false
|
|
668
|
+
};
|
|
669
|
+
keyMetaMap.set(address, keyMeta);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
return keyMeta;
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
const payerKeyMeta = getOrInsertDefault(payer);
|
|
676
|
+
payerKeyMeta.isSigner = true;
|
|
677
|
+
payerKeyMeta.isWritable = true;
|
|
678
|
+
|
|
679
|
+
for (const ix of instructions) {
|
|
680
|
+
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
681
|
+
|
|
682
|
+
for (const accountMeta of ix.keys) {
|
|
683
|
+
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
684
|
+
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
685
|
+
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
return new CompiledKeys(payer, keyMetaMap);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
getMessageComponents() {
|
|
693
|
+
const mapEntries = [...this.keyMetaMap.entries()];
|
|
694
|
+
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
695
|
+
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
696
|
+
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
697
|
+
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
698
|
+
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
699
|
+
const header = {
|
|
700
|
+
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
701
|
+
numReadonlySignedAccounts: readonlySigners.length,
|
|
702
|
+
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
703
|
+
}; // sanity checks
|
|
704
|
+
|
|
705
|
+
{
|
|
706
|
+
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
707
|
+
const [payerAddress] = writableSigners[0];
|
|
708
|
+
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
709
|
+
}
|
|
710
|
+
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))];
|
|
711
|
+
return [header, staticAccountKeys];
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
extractTableLookup(lookupTable) {
|
|
715
|
+
const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
|
|
716
|
+
const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
|
|
717
|
+
|
|
718
|
+
if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
return [{
|
|
723
|
+
accountKey: lookupTable.key,
|
|
724
|
+
writableIndexes,
|
|
725
|
+
readonlyIndexes
|
|
726
|
+
}, {
|
|
727
|
+
writable: drainedWritableKeys,
|
|
728
|
+
readonly: drainedReadonlyKeys
|
|
729
|
+
}];
|
|
730
|
+
}
|
|
731
|
+
/** @internal */
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
|
|
735
|
+
const lookupTableIndexes = new Array();
|
|
736
|
+
const drainedKeys = new Array();
|
|
737
|
+
|
|
738
|
+
for (const [address, keyMeta] of this.keyMetaMap.entries()) {
|
|
739
|
+
if (keyMetaFilter(keyMeta)) {
|
|
740
|
+
const key = new PublicKey(address);
|
|
741
|
+
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
742
|
+
|
|
743
|
+
if (lookupTableIndex >= 0) {
|
|
744
|
+
assert(lookupTableIndex < 256, 'Max lookup table index exceeded');
|
|
745
|
+
lookupTableIndexes.push(lookupTableIndex);
|
|
746
|
+
drainedKeys.push(key);
|
|
747
|
+
this.keyMetaMap.delete(address);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
return [lookupTableIndexes, drainedKeys];
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* An instruction to execute by a program
|
|
759
|
+
*
|
|
760
|
+
* @property {number} programIdIndex
|
|
761
|
+
* @property {number[]} accounts
|
|
762
|
+
* @property {string} data
|
|
763
|
+
*/
|
|
764
|
+
|
|
565
765
|
/**
|
|
566
766
|
* List of instructions to be processed atomically
|
|
567
767
|
*/
|
|
@@ -599,6 +799,27 @@ class Message {
|
|
|
599
799
|
return [];
|
|
600
800
|
}
|
|
601
801
|
|
|
802
|
+
getAccountKeys() {
|
|
803
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
static compile(args) {
|
|
807
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
808
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
809
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
810
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
811
|
+
programIdIndex: ix.programIdIndex,
|
|
812
|
+
accounts: ix.accountKeyIndexes,
|
|
813
|
+
data: bs58__default["default"].encode(ix.data)
|
|
814
|
+
}));
|
|
815
|
+
return new Message({
|
|
816
|
+
header,
|
|
817
|
+
accountKeys: staticAccountKeys,
|
|
818
|
+
recentBlockhash: args.recentBlockhash,
|
|
819
|
+
instructions
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
|
|
602
823
|
isAccountSigner(index) {
|
|
603
824
|
return index < this.header.numRequiredSignatures;
|
|
604
825
|
}
|
|
@@ -688,7 +909,7 @@ class Message {
|
|
|
688
909
|
for (let i = 0; i < accountCount; i++) {
|
|
689
910
|
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
690
911
|
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
691
|
-
accountKeys.push(
|
|
912
|
+
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
692
913
|
}
|
|
693
914
|
|
|
694
915
|
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
@@ -727,12 +948,6 @@ class Message {
|
|
|
727
948
|
|
|
728
949
|
}
|
|
729
950
|
|
|
730
|
-
function assert (condition, message) {
|
|
731
|
-
if (!condition) {
|
|
732
|
-
throw new Error(message || 'Assertion failed');
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
|
|
736
951
|
/**
|
|
737
952
|
* Message constructor arguments
|
|
738
953
|
*/
|
|
@@ -755,6 +970,102 @@ class MessageV0 {
|
|
|
755
970
|
return 0;
|
|
756
971
|
}
|
|
757
972
|
|
|
973
|
+
get numAccountKeysFromLookups() {
|
|
974
|
+
let count = 0;
|
|
975
|
+
|
|
976
|
+
for (const lookup of this.addressTableLookups) {
|
|
977
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
return count;
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
getAccountKeys(args) {
|
|
984
|
+
let accountKeysFromLookups;
|
|
985
|
+
|
|
986
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
987
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
988
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
992
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
993
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
994
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
995
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
1002
|
+
const accountKeysFromLookups = {
|
|
1003
|
+
writable: [],
|
|
1004
|
+
readonly: []
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
1008
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
1009
|
+
|
|
1010
|
+
if (!tableAccount) {
|
|
1011
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
for (const index of tableLookup.writableIndexes) {
|
|
1015
|
+
if (index < tableAccount.state.addresses.length) {
|
|
1016
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
1017
|
+
} else {
|
|
1018
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
1023
|
+
if (index < tableAccount.state.addresses.length) {
|
|
1024
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
1025
|
+
} else {
|
|
1026
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
return accountKeysFromLookups;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
static compile(args) {
|
|
1035
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
1036
|
+
const addressTableLookups = new Array();
|
|
1037
|
+
const accountKeysFromLookups = {
|
|
1038
|
+
writable: new Array(),
|
|
1039
|
+
readonly: new Array()
|
|
1040
|
+
};
|
|
1041
|
+
const lookupTableAccounts = args.addressLookupTableAccounts || [];
|
|
1042
|
+
|
|
1043
|
+
for (const lookupTable of lookupTableAccounts) {
|
|
1044
|
+
const extractResult = compiledKeys.extractTableLookup(lookupTable);
|
|
1045
|
+
|
|
1046
|
+
if (extractResult !== undefined) {
|
|
1047
|
+
const [addressTableLookup, {
|
|
1048
|
+
writable,
|
|
1049
|
+
readonly
|
|
1050
|
+
}] = extractResult;
|
|
1051
|
+
addressTableLookups.push(addressTableLookup);
|
|
1052
|
+
accountKeysFromLookups.writable.push(...writable);
|
|
1053
|
+
accountKeysFromLookups.readonly.push(...readonly);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
1058
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys, accountKeysFromLookups);
|
|
1059
|
+
const compiledInstructions = accountKeys.compileInstructions(args.instructions);
|
|
1060
|
+
return new MessageV0({
|
|
1061
|
+
header,
|
|
1062
|
+
staticAccountKeys,
|
|
1063
|
+
recentBlockhash: args.recentBlockhash,
|
|
1064
|
+
compiledInstructions,
|
|
1065
|
+
addressTableLookups
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
|
|
758
1069
|
serialize() {
|
|
759
1070
|
const encodedStaticAccountKeysLength = Array();
|
|
760
1071
|
encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
|
|
@@ -1649,6 +1960,114 @@ class Transaction {
|
|
|
1649
1960
|
|
|
1650
1961
|
}
|
|
1651
1962
|
|
|
1963
|
+
class TransactionMessage {
|
|
1964
|
+
constructor(args) {
|
|
1965
|
+
this.accountKeys = void 0;
|
|
1966
|
+
this.instructions = void 0;
|
|
1967
|
+
this.recentBlockhash = void 0;
|
|
1968
|
+
this.accountKeys = args.accountKeys;
|
|
1969
|
+
this.instructions = args.instructions;
|
|
1970
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
static decompile(message, args) {
|
|
1974
|
+
const {
|
|
1975
|
+
header,
|
|
1976
|
+
compiledInstructions,
|
|
1977
|
+
recentBlockhash
|
|
1978
|
+
} = message;
|
|
1979
|
+
const {
|
|
1980
|
+
numRequiredSignatures,
|
|
1981
|
+
numReadonlySignedAccounts,
|
|
1982
|
+
numReadonlyUnsignedAccounts
|
|
1983
|
+
} = header;
|
|
1984
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
1985
|
+
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
1986
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1987
|
+
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1988
|
+
const accountKeys = message.getAccountKeys(args);
|
|
1989
|
+
const instructions = [];
|
|
1990
|
+
|
|
1991
|
+
for (const compiledIx of compiledInstructions) {
|
|
1992
|
+
const keys = [];
|
|
1993
|
+
|
|
1994
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
1995
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
1996
|
+
|
|
1997
|
+
if (pubkey === undefined) {
|
|
1998
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
2002
|
+
let isWritable;
|
|
2003
|
+
|
|
2004
|
+
if (isSigner) {
|
|
2005
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
2006
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
2007
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
2008
|
+
} else {
|
|
2009
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
2010
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
keys.push({
|
|
2014
|
+
pubkey,
|
|
2015
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
2016
|
+
isWritable
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
2021
|
+
|
|
2022
|
+
if (programId === undefined) {
|
|
2023
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
instructions.push(new TransactionInstruction({
|
|
2027
|
+
programId,
|
|
2028
|
+
data: toBuffer(compiledIx.data),
|
|
2029
|
+
keys
|
|
2030
|
+
}));
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
return new TransactionMessage({
|
|
2034
|
+
accountKeys,
|
|
2035
|
+
instructions,
|
|
2036
|
+
recentBlockhash
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
|
|
2040
|
+
compileToLegacyMessage() {
|
|
2041
|
+
const payerKey = this.accountKeys.get(0);
|
|
2042
|
+
|
|
2043
|
+
if (payerKey === undefined) {
|
|
2044
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
return Message.compile({
|
|
2048
|
+
payerKey,
|
|
2049
|
+
recentBlockhash: this.recentBlockhash,
|
|
2050
|
+
instructions: this.instructions
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
2055
|
+
const payerKey = this.accountKeys.get(0);
|
|
2056
|
+
|
|
2057
|
+
if (payerKey === undefined) {
|
|
2058
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2059
|
+
}
|
|
2060
|
+
|
|
2061
|
+
return MessageV0.compile({
|
|
2062
|
+
payerKey,
|
|
2063
|
+
recentBlockhash: this.recentBlockhash,
|
|
2064
|
+
instructions: this.instructions,
|
|
2065
|
+
addressLookupTableAccounts
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
}
|
|
2070
|
+
|
|
1652
2071
|
/**
|
|
1653
2072
|
* Versioned transaction class
|
|
1654
2073
|
*/
|
|
@@ -3913,7 +4332,8 @@ const ConfirmedTransactionMetaResult = superstruct.type({
|
|
|
3913
4332
|
logMessages: superstruct.optional(superstruct.nullable(superstruct.array(superstruct.string()))),
|
|
3914
4333
|
preTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
3915
4334
|
postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
3916
|
-
loadedAddresses: superstruct.optional(LoadedAddressesResult)
|
|
4335
|
+
loadedAddresses: superstruct.optional(LoadedAddressesResult),
|
|
4336
|
+
computeUnitsConsumed: superstruct.optional(superstruct.number())
|
|
3917
4337
|
});
|
|
3918
4338
|
/**
|
|
3919
4339
|
* @internal
|
|
@@ -3931,7 +4351,8 @@ const ParsedConfirmedTransactionMetaResult = superstruct.type({
|
|
|
3931
4351
|
logMessages: superstruct.optional(superstruct.nullable(superstruct.array(superstruct.string()))),
|
|
3932
4352
|
preTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
3933
4353
|
postTokenBalances: superstruct.optional(superstruct.nullable(superstruct.array(TokenBalanceResult))),
|
|
3934
|
-
loadedAddresses: superstruct.optional(LoadedAddressesResult)
|
|
4354
|
+
loadedAddresses: superstruct.optional(LoadedAddressesResult),
|
|
4355
|
+
computeUnitsConsumed: superstruct.optional(superstruct.number())
|
|
3935
4356
|
});
|
|
3936
4357
|
const TransactionVersionStruct = superstruct.union([superstruct.literal(0), superstruct.literal('legacy')]);
|
|
3937
4358
|
/**
|
|
@@ -5950,10 +6371,44 @@ class Connection {
|
|
|
5950
6371
|
}
|
|
5951
6372
|
/**
|
|
5952
6373
|
* Simulate a transaction
|
|
6374
|
+
*
|
|
6375
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
6376
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
5953
6377
|
*/
|
|
5954
6378
|
|
|
5955
6379
|
|
|
5956
|
-
|
|
6380
|
+
/**
|
|
6381
|
+
* Simulate a transaction
|
|
6382
|
+
*/
|
|
6383
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6384
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
6385
|
+
if ('message' in transactionOrMessage) {
|
|
6386
|
+
const versionedTx = transactionOrMessage;
|
|
6387
|
+
const wireTransaction = versionedTx.serialize();
|
|
6388
|
+
const encodedTransaction = buffer.Buffer.from(wireTransaction).toString('base64');
|
|
6389
|
+
|
|
6390
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
6391
|
+
throw new Error('Invalid arguments');
|
|
6392
|
+
}
|
|
6393
|
+
|
|
6394
|
+
const config = configOrSigners || {};
|
|
6395
|
+
config.encoding = 'base64';
|
|
6396
|
+
|
|
6397
|
+
if (!('commitment' in config)) {
|
|
6398
|
+
config.commitment = this.commitment;
|
|
6399
|
+
}
|
|
6400
|
+
|
|
6401
|
+
const args = [encodedTransaction, config];
|
|
6402
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
6403
|
+
const res = superstruct.create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
6404
|
+
|
|
6405
|
+
if ('error' in res) {
|
|
6406
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
6407
|
+
}
|
|
6408
|
+
|
|
6409
|
+
return res.result;
|
|
6410
|
+
}
|
|
6411
|
+
|
|
5957
6412
|
let transaction;
|
|
5958
6413
|
|
|
5959
6414
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -5969,6 +6424,12 @@ class Connection {
|
|
|
5969
6424
|
transaction._message = transaction._json = undefined;
|
|
5970
6425
|
}
|
|
5971
6426
|
|
|
6427
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
6428
|
+
throw new Error('Invalid arguments');
|
|
6429
|
+
}
|
|
6430
|
+
|
|
6431
|
+
const signers = configOrSigners;
|
|
6432
|
+
|
|
5972
6433
|
if (transaction.nonceInfo && signers) {
|
|
5973
6434
|
transaction.sign(...signers);
|
|
5974
6435
|
} else {
|
|
@@ -6049,12 +6510,34 @@ class Connection {
|
|
|
6049
6510
|
|
|
6050
6511
|
return res.result;
|
|
6051
6512
|
}
|
|
6513
|
+
/**
|
|
6514
|
+
* Sign and send a transaction
|
|
6515
|
+
*
|
|
6516
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
6517
|
+
* VersionedTransaction}
|
|
6518
|
+
*/
|
|
6519
|
+
|
|
6520
|
+
|
|
6052
6521
|
/**
|
|
6053
6522
|
* Sign and send a transaction
|
|
6054
6523
|
*/
|
|
6524
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6525
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
6526
|
+
if ('message' in transaction) {
|
|
6527
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
6528
|
+
throw new Error('Invalid arguments');
|
|
6529
|
+
}
|
|
6530
|
+
|
|
6531
|
+
const wireTransaction = transaction.serialize();
|
|
6532
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
6533
|
+
}
|
|
6534
|
+
|
|
6535
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6536
|
+
throw new Error('Invalid arguments');
|
|
6537
|
+
}
|
|
6055
6538
|
|
|
6539
|
+
const signers = signersOrOptions;
|
|
6056
6540
|
|
|
6057
|
-
async sendTransaction(transaction, signers, options) {
|
|
6058
6541
|
if (transaction.nonceInfo) {
|
|
6059
6542
|
transaction.sign(...signers);
|
|
6060
6543
|
} else {
|
|
@@ -9105,6 +9588,7 @@ exports.Loader = Loader;
|
|
|
9105
9588
|
exports.Lockup = Lockup;
|
|
9106
9589
|
exports.MAX_SEED_LENGTH = MAX_SEED_LENGTH;
|
|
9107
9590
|
exports.Message = Message;
|
|
9591
|
+
exports.MessageAccountKeys = MessageAccountKeys;
|
|
9108
9592
|
exports.MessageV0 = MessageV0;
|
|
9109
9593
|
exports.NONCE_ACCOUNT_LENGTH = NONCE_ACCOUNT_LENGTH;
|
|
9110
9594
|
exports.NonceAccount = NonceAccount;
|
|
@@ -9139,6 +9623,7 @@ exports.Transaction = Transaction;
|
|
|
9139
9623
|
exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheightExceededError;
|
|
9140
9624
|
exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
|
|
9141
9625
|
exports.TransactionInstruction = TransactionInstruction;
|
|
9626
|
+
exports.TransactionMessage = TransactionMessage;
|
|
9142
9627
|
exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
|
|
9143
9628
|
exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
|
|
9144
9629
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|