@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.esm.js
CHANGED
|
@@ -112,12 +112,14 @@ const PUBLIC_KEY_LENGTH = 32;
|
|
|
112
112
|
|
|
113
113
|
function isPublicKeyData(value) {
|
|
114
114
|
return value._bn !== undefined;
|
|
115
|
-
}
|
|
115
|
+
} // local counter used by PublicKey.unique()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
let uniquePublicKeyCounter = 1;
|
|
116
119
|
/**
|
|
117
120
|
* A public key
|
|
118
121
|
*/
|
|
119
122
|
|
|
120
|
-
|
|
121
123
|
class PublicKey extends Struct {
|
|
122
124
|
/** @internal */
|
|
123
125
|
|
|
@@ -150,6 +152,16 @@ class PublicKey extends Struct {
|
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Returns a unique PublicKey for tests and benchmarks using acounter
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
static unique() {
|
|
161
|
+
const key = new PublicKey(uniquePublicKeyCounter);
|
|
162
|
+
uniquePublicKeyCounter += 1;
|
|
163
|
+
return new PublicKey(key.toBuffer());
|
|
164
|
+
}
|
|
153
165
|
/**
|
|
154
166
|
* Default public key value. (All zeros)
|
|
155
167
|
*/
|
|
@@ -406,6 +418,71 @@ Object.defineProperty(TransactionExpiredTimeoutError.prototype, 'name', {
|
|
|
406
418
|
value: 'TransactionExpiredTimeoutError'
|
|
407
419
|
});
|
|
408
420
|
|
|
421
|
+
class MessageAccountKeys {
|
|
422
|
+
constructor(staticAccountKeys, accountKeysFromLookups) {
|
|
423
|
+
this.staticAccountKeys = void 0;
|
|
424
|
+
this.accountKeysFromLookups = void 0;
|
|
425
|
+
this.staticAccountKeys = staticAccountKeys;
|
|
426
|
+
this.accountKeysFromLookups = accountKeysFromLookups;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
keySegments() {
|
|
430
|
+
const keySegments = [this.staticAccountKeys];
|
|
431
|
+
|
|
432
|
+
if (this.accountKeysFromLookups) {
|
|
433
|
+
keySegments.push(this.accountKeysFromLookups.writable);
|
|
434
|
+
keySegments.push(this.accountKeysFromLookups.readonly);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
return keySegments;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
get(index) {
|
|
441
|
+
for (const keySegment of this.keySegments()) {
|
|
442
|
+
if (index < keySegment.length) {
|
|
443
|
+
return keySegment[index];
|
|
444
|
+
} else {
|
|
445
|
+
index -= keySegment.length;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
get length() {
|
|
453
|
+
return this.keySegments().flat().length;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
compileInstructions(instructions) {
|
|
457
|
+
// Bail early if any account indexes would overflow a u8
|
|
458
|
+
const U8_MAX = 255;
|
|
459
|
+
|
|
460
|
+
if (this.length > U8_MAX + 1) {
|
|
461
|
+
throw new Error('Account index overflow encountered during compilation');
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
const keyIndexMap = new Map();
|
|
465
|
+
this.keySegments().flat().forEach((key, index) => {
|
|
466
|
+
keyIndexMap.set(key.toBase58(), index);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
const findKeyIndex = key => {
|
|
470
|
+
const keyIndex = keyIndexMap.get(key.toBase58());
|
|
471
|
+
if (keyIndex === undefined) throw new Error('Encountered an unknown instruction account key during compilation');
|
|
472
|
+
return keyIndex;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
return instructions.map(instruction => {
|
|
476
|
+
return {
|
|
477
|
+
programIdIndex: findKeyIndex(instruction.programId),
|
|
478
|
+
accountKeyIndexes: instruction.keys.map(meta => findKeyIndex(meta.pubkey)),
|
|
479
|
+
data: instruction.data
|
|
480
|
+
};
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
}
|
|
485
|
+
|
|
409
486
|
/**
|
|
410
487
|
* Layout for a public key
|
|
411
488
|
*/
|
|
@@ -531,6 +608,129 @@ function encodeLength(bytes, len) {
|
|
|
531
608
|
}
|
|
532
609
|
}
|
|
533
610
|
|
|
611
|
+
function assert (condition, message) {
|
|
612
|
+
if (!condition) {
|
|
613
|
+
throw new Error(message || 'Assertion failed');
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
class CompiledKeys {
|
|
618
|
+
constructor(payer, keyMetaMap) {
|
|
619
|
+
this.payer = void 0;
|
|
620
|
+
this.keyMetaMap = void 0;
|
|
621
|
+
this.payer = payer;
|
|
622
|
+
this.keyMetaMap = keyMetaMap;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
static compile(instructions, payer) {
|
|
626
|
+
const keyMetaMap = new Map();
|
|
627
|
+
|
|
628
|
+
const getOrInsertDefault = pubkey => {
|
|
629
|
+
const address = pubkey.toBase58();
|
|
630
|
+
let keyMeta = keyMetaMap.get(address);
|
|
631
|
+
|
|
632
|
+
if (keyMeta === undefined) {
|
|
633
|
+
keyMeta = {
|
|
634
|
+
isSigner: false,
|
|
635
|
+
isWritable: false,
|
|
636
|
+
isInvoked: false
|
|
637
|
+
};
|
|
638
|
+
keyMetaMap.set(address, keyMeta);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
return keyMeta;
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
const payerKeyMeta = getOrInsertDefault(payer);
|
|
645
|
+
payerKeyMeta.isSigner = true;
|
|
646
|
+
payerKeyMeta.isWritable = true;
|
|
647
|
+
|
|
648
|
+
for (const ix of instructions) {
|
|
649
|
+
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
650
|
+
|
|
651
|
+
for (const accountMeta of ix.keys) {
|
|
652
|
+
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
653
|
+
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
654
|
+
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
return new CompiledKeys(payer, keyMetaMap);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
getMessageComponents() {
|
|
662
|
+
const mapEntries = [...this.keyMetaMap.entries()];
|
|
663
|
+
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
664
|
+
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
665
|
+
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
666
|
+
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
667
|
+
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
668
|
+
const header = {
|
|
669
|
+
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
670
|
+
numReadonlySignedAccounts: readonlySigners.length,
|
|
671
|
+
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
672
|
+
}; // sanity checks
|
|
673
|
+
|
|
674
|
+
{
|
|
675
|
+
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
676
|
+
const [payerAddress] = writableSigners[0];
|
|
677
|
+
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
678
|
+
}
|
|
679
|
+
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))];
|
|
680
|
+
return [header, staticAccountKeys];
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
extractTableLookup(lookupTable) {
|
|
684
|
+
const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
|
|
685
|
+
const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
|
|
686
|
+
|
|
687
|
+
if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
return [{
|
|
692
|
+
accountKey: lookupTable.key,
|
|
693
|
+
writableIndexes,
|
|
694
|
+
readonlyIndexes
|
|
695
|
+
}, {
|
|
696
|
+
writable: drainedWritableKeys,
|
|
697
|
+
readonly: drainedReadonlyKeys
|
|
698
|
+
}];
|
|
699
|
+
}
|
|
700
|
+
/** @internal */
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
|
|
704
|
+
const lookupTableIndexes = new Array();
|
|
705
|
+
const drainedKeys = new Array();
|
|
706
|
+
|
|
707
|
+
for (const [address, keyMeta] of this.keyMetaMap.entries()) {
|
|
708
|
+
if (keyMetaFilter(keyMeta)) {
|
|
709
|
+
const key = new PublicKey(address);
|
|
710
|
+
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
711
|
+
|
|
712
|
+
if (lookupTableIndex >= 0) {
|
|
713
|
+
assert(lookupTableIndex < 256, 'Max lookup table index exceeded');
|
|
714
|
+
lookupTableIndexes.push(lookupTableIndex);
|
|
715
|
+
drainedKeys.push(key);
|
|
716
|
+
this.keyMetaMap.delete(address);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
return [lookupTableIndexes, drainedKeys];
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* An instruction to execute by a program
|
|
728
|
+
*
|
|
729
|
+
* @property {number} programIdIndex
|
|
730
|
+
* @property {number[]} accounts
|
|
731
|
+
* @property {string} data
|
|
732
|
+
*/
|
|
733
|
+
|
|
534
734
|
/**
|
|
535
735
|
* List of instructions to be processed atomically
|
|
536
736
|
*/
|
|
@@ -568,6 +768,27 @@ class Message {
|
|
|
568
768
|
return [];
|
|
569
769
|
}
|
|
570
770
|
|
|
771
|
+
getAccountKeys() {
|
|
772
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
static compile(args) {
|
|
776
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
777
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
778
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
779
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
780
|
+
programIdIndex: ix.programIdIndex,
|
|
781
|
+
accounts: ix.accountKeyIndexes,
|
|
782
|
+
data: bs58.encode(ix.data)
|
|
783
|
+
}));
|
|
784
|
+
return new Message({
|
|
785
|
+
header,
|
|
786
|
+
accountKeys: staticAccountKeys,
|
|
787
|
+
recentBlockhash: args.recentBlockhash,
|
|
788
|
+
instructions
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
|
|
571
792
|
isAccountSigner(index) {
|
|
572
793
|
return index < this.header.numRequiredSignatures;
|
|
573
794
|
}
|
|
@@ -657,7 +878,7 @@ class Message {
|
|
|
657
878
|
for (let i = 0; i < accountCount; i++) {
|
|
658
879
|
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
659
880
|
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
660
|
-
accountKeys.push(
|
|
881
|
+
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
661
882
|
}
|
|
662
883
|
|
|
663
884
|
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
@@ -696,12 +917,6 @@ class Message {
|
|
|
696
917
|
|
|
697
918
|
}
|
|
698
919
|
|
|
699
|
-
function assert (condition, message) {
|
|
700
|
-
if (!condition) {
|
|
701
|
-
throw new Error(message || 'Assertion failed');
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
920
|
/**
|
|
706
921
|
* Message constructor arguments
|
|
707
922
|
*/
|
|
@@ -724,6 +939,102 @@ class MessageV0 {
|
|
|
724
939
|
return 0;
|
|
725
940
|
}
|
|
726
941
|
|
|
942
|
+
get numAccountKeysFromLookups() {
|
|
943
|
+
let count = 0;
|
|
944
|
+
|
|
945
|
+
for (const lookup of this.addressTableLookups) {
|
|
946
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
return count;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
getAccountKeys(args) {
|
|
953
|
+
let accountKeysFromLookups;
|
|
954
|
+
|
|
955
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
956
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
957
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
961
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
962
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
963
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
964
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
971
|
+
const accountKeysFromLookups = {
|
|
972
|
+
writable: [],
|
|
973
|
+
readonly: []
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
977
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
978
|
+
|
|
979
|
+
if (!tableAccount) {
|
|
980
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
for (const index of tableLookup.writableIndexes) {
|
|
984
|
+
if (index < tableAccount.state.addresses.length) {
|
|
985
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
986
|
+
} else {
|
|
987
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
992
|
+
if (index < tableAccount.state.addresses.length) {
|
|
993
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
994
|
+
} else {
|
|
995
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
return accountKeysFromLookups;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
static compile(args) {
|
|
1004
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
1005
|
+
const addressTableLookups = new Array();
|
|
1006
|
+
const accountKeysFromLookups = {
|
|
1007
|
+
writable: new Array(),
|
|
1008
|
+
readonly: new Array()
|
|
1009
|
+
};
|
|
1010
|
+
const lookupTableAccounts = args.addressLookupTableAccounts || [];
|
|
1011
|
+
|
|
1012
|
+
for (const lookupTable of lookupTableAccounts) {
|
|
1013
|
+
const extractResult = compiledKeys.extractTableLookup(lookupTable);
|
|
1014
|
+
|
|
1015
|
+
if (extractResult !== undefined) {
|
|
1016
|
+
const [addressTableLookup, {
|
|
1017
|
+
writable,
|
|
1018
|
+
readonly
|
|
1019
|
+
}] = extractResult;
|
|
1020
|
+
addressTableLookups.push(addressTableLookup);
|
|
1021
|
+
accountKeysFromLookups.writable.push(...writable);
|
|
1022
|
+
accountKeysFromLookups.readonly.push(...readonly);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
1027
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys, accountKeysFromLookups);
|
|
1028
|
+
const compiledInstructions = accountKeys.compileInstructions(args.instructions);
|
|
1029
|
+
return new MessageV0({
|
|
1030
|
+
header,
|
|
1031
|
+
staticAccountKeys,
|
|
1032
|
+
recentBlockhash: args.recentBlockhash,
|
|
1033
|
+
compiledInstructions,
|
|
1034
|
+
addressTableLookups
|
|
1035
|
+
});
|
|
1036
|
+
}
|
|
1037
|
+
|
|
727
1038
|
serialize() {
|
|
728
1039
|
const encodedStaticAccountKeysLength = Array();
|
|
729
1040
|
encodeLength(encodedStaticAccountKeysLength, this.staticAccountKeys.length);
|
|
@@ -1618,6 +1929,114 @@ class Transaction {
|
|
|
1618
1929
|
|
|
1619
1930
|
}
|
|
1620
1931
|
|
|
1932
|
+
class TransactionMessage {
|
|
1933
|
+
constructor(args) {
|
|
1934
|
+
this.accountKeys = void 0;
|
|
1935
|
+
this.instructions = void 0;
|
|
1936
|
+
this.recentBlockhash = void 0;
|
|
1937
|
+
this.accountKeys = args.accountKeys;
|
|
1938
|
+
this.instructions = args.instructions;
|
|
1939
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
static decompile(message, args) {
|
|
1943
|
+
const {
|
|
1944
|
+
header,
|
|
1945
|
+
compiledInstructions,
|
|
1946
|
+
recentBlockhash
|
|
1947
|
+
} = message;
|
|
1948
|
+
const {
|
|
1949
|
+
numRequiredSignatures,
|
|
1950
|
+
numReadonlySignedAccounts,
|
|
1951
|
+
numReadonlyUnsignedAccounts
|
|
1952
|
+
} = header;
|
|
1953
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
1954
|
+
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
1955
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1956
|
+
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1957
|
+
const accountKeys = message.getAccountKeys(args);
|
|
1958
|
+
const instructions = [];
|
|
1959
|
+
|
|
1960
|
+
for (const compiledIx of compiledInstructions) {
|
|
1961
|
+
const keys = [];
|
|
1962
|
+
|
|
1963
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
1964
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
1965
|
+
|
|
1966
|
+
if (pubkey === undefined) {
|
|
1967
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
1971
|
+
let isWritable;
|
|
1972
|
+
|
|
1973
|
+
if (isSigner) {
|
|
1974
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
1975
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
1976
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
1977
|
+
} else {
|
|
1978
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
1979
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
keys.push({
|
|
1983
|
+
pubkey,
|
|
1984
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
1985
|
+
isWritable
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
1990
|
+
|
|
1991
|
+
if (programId === undefined) {
|
|
1992
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
instructions.push(new TransactionInstruction({
|
|
1996
|
+
programId,
|
|
1997
|
+
data: toBuffer(compiledIx.data),
|
|
1998
|
+
keys
|
|
1999
|
+
}));
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
return new TransactionMessage({
|
|
2003
|
+
accountKeys,
|
|
2004
|
+
instructions,
|
|
2005
|
+
recentBlockhash
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
compileToLegacyMessage() {
|
|
2010
|
+
const payerKey = this.accountKeys.get(0);
|
|
2011
|
+
|
|
2012
|
+
if (payerKey === undefined) {
|
|
2013
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
return Message.compile({
|
|
2017
|
+
payerKey,
|
|
2018
|
+
recentBlockhash: this.recentBlockhash,
|
|
2019
|
+
instructions: this.instructions
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
2024
|
+
const payerKey = this.accountKeys.get(0);
|
|
2025
|
+
|
|
2026
|
+
if (payerKey === undefined) {
|
|
2027
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
return MessageV0.compile({
|
|
2031
|
+
payerKey,
|
|
2032
|
+
recentBlockhash: this.recentBlockhash,
|
|
2033
|
+
instructions: this.instructions,
|
|
2034
|
+
addressLookupTableAccounts
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
}
|
|
2039
|
+
|
|
1621
2040
|
/**
|
|
1622
2041
|
* Versioned transaction class
|
|
1623
2042
|
*/
|
|
@@ -3882,7 +4301,8 @@ const ConfirmedTransactionMetaResult = type({
|
|
|
3882
4301
|
logMessages: optional(nullable(array(string()))),
|
|
3883
4302
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3884
4303
|
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3885
|
-
loadedAddresses: optional(LoadedAddressesResult)
|
|
4304
|
+
loadedAddresses: optional(LoadedAddressesResult),
|
|
4305
|
+
computeUnitsConsumed: optional(number())
|
|
3886
4306
|
});
|
|
3887
4307
|
/**
|
|
3888
4308
|
* @internal
|
|
@@ -3900,7 +4320,8 @@ const ParsedConfirmedTransactionMetaResult = type({
|
|
|
3900
4320
|
logMessages: optional(nullable(array(string()))),
|
|
3901
4321
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3902
4322
|
postTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
3903
|
-
loadedAddresses: optional(LoadedAddressesResult)
|
|
4323
|
+
loadedAddresses: optional(LoadedAddressesResult),
|
|
4324
|
+
computeUnitsConsumed: optional(number())
|
|
3904
4325
|
});
|
|
3905
4326
|
const TransactionVersionStruct = union([literal(0), literal('legacy')]);
|
|
3906
4327
|
/**
|
|
@@ -5919,10 +6340,44 @@ class Connection {
|
|
|
5919
6340
|
}
|
|
5920
6341
|
/**
|
|
5921
6342
|
* Simulate a transaction
|
|
6343
|
+
*
|
|
6344
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
6345
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
5922
6346
|
*/
|
|
5923
6347
|
|
|
5924
6348
|
|
|
5925
|
-
|
|
6349
|
+
/**
|
|
6350
|
+
* Simulate a transaction
|
|
6351
|
+
*/
|
|
6352
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6353
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
6354
|
+
if ('message' in transactionOrMessage) {
|
|
6355
|
+
const versionedTx = transactionOrMessage;
|
|
6356
|
+
const wireTransaction = versionedTx.serialize();
|
|
6357
|
+
const encodedTransaction = Buffer.from(wireTransaction).toString('base64');
|
|
6358
|
+
|
|
6359
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
6360
|
+
throw new Error('Invalid arguments');
|
|
6361
|
+
}
|
|
6362
|
+
|
|
6363
|
+
const config = configOrSigners || {};
|
|
6364
|
+
config.encoding = 'base64';
|
|
6365
|
+
|
|
6366
|
+
if (!('commitment' in config)) {
|
|
6367
|
+
config.commitment = this.commitment;
|
|
6368
|
+
}
|
|
6369
|
+
|
|
6370
|
+
const args = [encodedTransaction, config];
|
|
6371
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
6372
|
+
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
6373
|
+
|
|
6374
|
+
if ('error' in res) {
|
|
6375
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
6376
|
+
}
|
|
6377
|
+
|
|
6378
|
+
return res.result;
|
|
6379
|
+
}
|
|
6380
|
+
|
|
5926
6381
|
let transaction;
|
|
5927
6382
|
|
|
5928
6383
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -5938,6 +6393,12 @@ class Connection {
|
|
|
5938
6393
|
transaction._message = transaction._json = undefined;
|
|
5939
6394
|
}
|
|
5940
6395
|
|
|
6396
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
6397
|
+
throw new Error('Invalid arguments');
|
|
6398
|
+
}
|
|
6399
|
+
|
|
6400
|
+
const signers = configOrSigners;
|
|
6401
|
+
|
|
5941
6402
|
if (transaction.nonceInfo && signers) {
|
|
5942
6403
|
transaction.sign(...signers);
|
|
5943
6404
|
} else {
|
|
@@ -6018,12 +6479,34 @@ class Connection {
|
|
|
6018
6479
|
|
|
6019
6480
|
return res.result;
|
|
6020
6481
|
}
|
|
6482
|
+
/**
|
|
6483
|
+
* Sign and send a transaction
|
|
6484
|
+
*
|
|
6485
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
6486
|
+
* VersionedTransaction}
|
|
6487
|
+
*/
|
|
6488
|
+
|
|
6489
|
+
|
|
6021
6490
|
/**
|
|
6022
6491
|
* Sign and send a transaction
|
|
6023
6492
|
*/
|
|
6493
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6494
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
6495
|
+
if ('message' in transaction) {
|
|
6496
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
6497
|
+
throw new Error('Invalid arguments');
|
|
6498
|
+
}
|
|
6499
|
+
|
|
6500
|
+
const wireTransaction = transaction.serialize();
|
|
6501
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
6502
|
+
}
|
|
6503
|
+
|
|
6504
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6505
|
+
throw new Error('Invalid arguments');
|
|
6506
|
+
}
|
|
6024
6507
|
|
|
6508
|
+
const signers = signersOrOptions;
|
|
6025
6509
|
|
|
6026
|
-
async sendTransaction(transaction, signers, options) {
|
|
6027
6510
|
if (transaction.nonceInfo) {
|
|
6028
6511
|
transaction.sign(...signers);
|
|
6029
6512
|
} else {
|
|
@@ -9050,5 +9533,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9050
9533
|
|
|
9051
9534
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9052
9535
|
|
|
9053
|
-
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 };
|
|
9536
|
+
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 };
|
|
9054
9537
|
//# sourceMappingURL=index.browser.esm.js.map
|