@solana/web3.js 1.57.1 → 1.58.1
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 +370 -117
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +370 -118
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +370 -117
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +82 -1
- package/lib/index.esm.js +370 -118
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +370 -117
- 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 +370 -117
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -1
- package/src/connection.ts +106 -2
- package/src/message/legacy.ts +34 -2
- package/src/message/v0.ts +90 -0
- package/src/transaction/index.ts +1 -0
- package/src/transaction/message.ts +147 -0
package/lib/index.esm.js
CHANGED
|
@@ -611,6 +611,121 @@ function encodeLength(bytes, len) {
|
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
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
|
+
|
|
614
729
|
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
615
730
|
/**
|
|
616
731
|
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
@@ -686,6 +801,27 @@ class Message {
|
|
|
686
801
|
return [];
|
|
687
802
|
}
|
|
688
803
|
|
|
804
|
+
getAccountKeys() {
|
|
805
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
static compile(args) {
|
|
809
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
810
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
811
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
812
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
813
|
+
programIdIndex: ix.programIdIndex,
|
|
814
|
+
accounts: ix.accountKeyIndexes,
|
|
815
|
+
data: bs58.encode(ix.data)
|
|
816
|
+
}));
|
|
817
|
+
return new Message({
|
|
818
|
+
header,
|
|
819
|
+
accountKeys: staticAccountKeys,
|
|
820
|
+
recentBlockhash: args.recentBlockhash,
|
|
821
|
+
instructions
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
|
|
689
825
|
isAccountSigner(index) {
|
|
690
826
|
return index < this.header.numRequiredSignatures;
|
|
691
827
|
}
|
|
@@ -774,7 +910,7 @@ class Message {
|
|
|
774
910
|
|
|
775
911
|
for (let i = 0; i < accountCount; i++) {
|
|
776
912
|
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
777
|
-
accountKeys.push(
|
|
913
|
+
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
778
914
|
}
|
|
779
915
|
|
|
780
916
|
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
@@ -810,141 +946,87 @@ class Message {
|
|
|
810
946
|
|
|
811
947
|
}
|
|
812
948
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
}
|
|
949
|
+
/**
|
|
950
|
+
* Message constructor arguments
|
|
951
|
+
*/
|
|
818
952
|
|
|
819
|
-
class
|
|
820
|
-
constructor(
|
|
821
|
-
this.
|
|
822
|
-
this.
|
|
823
|
-
this.
|
|
824
|
-
this.
|
|
953
|
+
class MessageV0 {
|
|
954
|
+
constructor(args) {
|
|
955
|
+
this.header = void 0;
|
|
956
|
+
this.staticAccountKeys = void 0;
|
|
957
|
+
this.recentBlockhash = void 0;
|
|
958
|
+
this.compiledInstructions = void 0;
|
|
959
|
+
this.addressTableLookups = void 0;
|
|
960
|
+
this.header = args.header;
|
|
961
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
962
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
963
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
964
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
825
965
|
}
|
|
826
966
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
const getOrInsertDefault = pubkey => {
|
|
831
|
-
const address = pubkey.toBase58();
|
|
832
|
-
let keyMeta = keyMetaMap.get(address);
|
|
833
|
-
|
|
834
|
-
if (keyMeta === undefined) {
|
|
835
|
-
keyMeta = {
|
|
836
|
-
isSigner: false,
|
|
837
|
-
isWritable: false,
|
|
838
|
-
isInvoked: false
|
|
839
|
-
};
|
|
840
|
-
keyMetaMap.set(address, keyMeta);
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
return keyMeta;
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
const payerKeyMeta = getOrInsertDefault(payer);
|
|
847
|
-
payerKeyMeta.isSigner = true;
|
|
848
|
-
payerKeyMeta.isWritable = true;
|
|
967
|
+
get version() {
|
|
968
|
+
return 0;
|
|
969
|
+
}
|
|
849
970
|
|
|
850
|
-
|
|
851
|
-
|
|
971
|
+
get numAccountKeysFromLookups() {
|
|
972
|
+
let count = 0;
|
|
852
973
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
856
|
-
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
857
|
-
}
|
|
974
|
+
for (const lookup of this.addressTableLookups) {
|
|
975
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
858
976
|
}
|
|
859
977
|
|
|
860
|
-
return
|
|
978
|
+
return count;
|
|
861
979
|
}
|
|
862
980
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
866
|
-
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
867
|
-
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
868
|
-
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
869
|
-
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
870
|
-
const header = {
|
|
871
|
-
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
872
|
-
numReadonlySignedAccounts: readonlySigners.length,
|
|
873
|
-
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
874
|
-
}; // sanity checks
|
|
875
|
-
|
|
876
|
-
{
|
|
877
|
-
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
878
|
-
const [payerAddress] = writableSigners[0];
|
|
879
|
-
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
880
|
-
}
|
|
881
|
-
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))];
|
|
882
|
-
return [header, staticAccountKeys];
|
|
883
|
-
}
|
|
981
|
+
getAccountKeys(args) {
|
|
982
|
+
let accountKeysFromLookups;
|
|
884
983
|
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
984
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
985
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
986
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
987
|
+
}
|
|
888
988
|
|
|
889
|
-
|
|
890
|
-
|
|
989
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
990
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
991
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
992
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
993
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
891
994
|
}
|
|
892
995
|
|
|
893
|
-
return
|
|
894
|
-
accountKey: lookupTable.key,
|
|
895
|
-
writableIndexes,
|
|
896
|
-
readonlyIndexes
|
|
897
|
-
}, {
|
|
898
|
-
writable: drainedWritableKeys,
|
|
899
|
-
readonly: drainedReadonlyKeys
|
|
900
|
-
}];
|
|
996
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
901
997
|
}
|
|
902
|
-
/** @internal */
|
|
903
998
|
|
|
999
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
1000
|
+
const accountKeysFromLookups = {
|
|
1001
|
+
writable: [],
|
|
1002
|
+
readonly: []
|
|
1003
|
+
};
|
|
904
1004
|
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
const drainedKeys = new Array();
|
|
1005
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
1006
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
908
1007
|
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
1008
|
+
if (!tableAccount) {
|
|
1009
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
1010
|
+
}
|
|
913
1011
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
1012
|
+
for (const index of tableLookup.writableIndexes) {
|
|
1013
|
+
if (index < tableAccount.state.addresses.length) {
|
|
1014
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
1015
|
+
} else {
|
|
1016
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
919
1017
|
}
|
|
920
1018
|
}
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
return [lookupTableIndexes, drainedKeys];
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
}
|
|
927
1019
|
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
this.recentBlockhash = void 0;
|
|
937
|
-
this.compiledInstructions = void 0;
|
|
938
|
-
this.addressTableLookups = void 0;
|
|
939
|
-
this.header = args.header;
|
|
940
|
-
this.staticAccountKeys = args.staticAccountKeys;
|
|
941
|
-
this.recentBlockhash = args.recentBlockhash;
|
|
942
|
-
this.compiledInstructions = args.compiledInstructions;
|
|
943
|
-
this.addressTableLookups = args.addressTableLookups;
|
|
944
|
-
}
|
|
1020
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
1021
|
+
if (index < tableAccount.state.addresses.length) {
|
|
1022
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
1023
|
+
} else {
|
|
1024
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
945
1028
|
|
|
946
|
-
|
|
947
|
-
return 0;
|
|
1029
|
+
return accountKeysFromLookups;
|
|
948
1030
|
}
|
|
949
1031
|
|
|
950
1032
|
static compile(args) {
|
|
@@ -1875,6 +1957,114 @@ class Transaction {
|
|
|
1875
1957
|
|
|
1876
1958
|
}
|
|
1877
1959
|
|
|
1960
|
+
class TransactionMessage {
|
|
1961
|
+
constructor(args) {
|
|
1962
|
+
this.accountKeys = void 0;
|
|
1963
|
+
this.instructions = void 0;
|
|
1964
|
+
this.recentBlockhash = void 0;
|
|
1965
|
+
this.accountKeys = args.accountKeys;
|
|
1966
|
+
this.instructions = args.instructions;
|
|
1967
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
static decompile(message, args) {
|
|
1971
|
+
const {
|
|
1972
|
+
header,
|
|
1973
|
+
compiledInstructions,
|
|
1974
|
+
recentBlockhash
|
|
1975
|
+
} = message;
|
|
1976
|
+
const {
|
|
1977
|
+
numRequiredSignatures,
|
|
1978
|
+
numReadonlySignedAccounts,
|
|
1979
|
+
numReadonlyUnsignedAccounts
|
|
1980
|
+
} = header;
|
|
1981
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
1982
|
+
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
1983
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1984
|
+
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1985
|
+
const accountKeys = message.getAccountKeys(args);
|
|
1986
|
+
const instructions = [];
|
|
1987
|
+
|
|
1988
|
+
for (const compiledIx of compiledInstructions) {
|
|
1989
|
+
const keys = [];
|
|
1990
|
+
|
|
1991
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
1992
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
1993
|
+
|
|
1994
|
+
if (pubkey === undefined) {
|
|
1995
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
1999
|
+
let isWritable;
|
|
2000
|
+
|
|
2001
|
+
if (isSigner) {
|
|
2002
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
2003
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
2004
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
2005
|
+
} else {
|
|
2006
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
2007
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
keys.push({
|
|
2011
|
+
pubkey,
|
|
2012
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
2013
|
+
isWritable
|
|
2014
|
+
});
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
2018
|
+
|
|
2019
|
+
if (programId === undefined) {
|
|
2020
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
instructions.push(new TransactionInstruction({
|
|
2024
|
+
programId,
|
|
2025
|
+
data: toBuffer(compiledIx.data),
|
|
2026
|
+
keys
|
|
2027
|
+
}));
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
return new TransactionMessage({
|
|
2031
|
+
accountKeys,
|
|
2032
|
+
instructions,
|
|
2033
|
+
recentBlockhash
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
compileToLegacyMessage() {
|
|
2038
|
+
const payerKey = this.accountKeys.get(0);
|
|
2039
|
+
|
|
2040
|
+
if (payerKey === undefined) {
|
|
2041
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
return Message.compile({
|
|
2045
|
+
payerKey,
|
|
2046
|
+
recentBlockhash: this.recentBlockhash,
|
|
2047
|
+
instructions: this.instructions
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
2052
|
+
const payerKey = this.accountKeys.get(0);
|
|
2053
|
+
|
|
2054
|
+
if (payerKey === undefined) {
|
|
2055
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
return MessageV0.compile({
|
|
2059
|
+
payerKey,
|
|
2060
|
+
recentBlockhash: this.recentBlockhash,
|
|
2061
|
+
instructions: this.instructions,
|
|
2062
|
+
addressLookupTableAccounts
|
|
2063
|
+
});
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
}
|
|
2067
|
+
|
|
1878
2068
|
/**
|
|
1879
2069
|
* Versioned transaction class
|
|
1880
2070
|
*/
|
|
@@ -4378,7 +4568,7 @@ const LogsNotificationResult = type({
|
|
|
4378
4568
|
|
|
4379
4569
|
/** @internal */
|
|
4380
4570
|
const COMMON_HTTP_HEADERS = {
|
|
4381
|
-
'solana-client': `js/${(_process$env$npm_pack = "1.
|
|
4571
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.58.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4382
4572
|
};
|
|
4383
4573
|
/**
|
|
4384
4574
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -6236,12 +6426,46 @@ class Connection {
|
|
|
6236
6426
|
|
|
6237
6427
|
return res.result;
|
|
6238
6428
|
}
|
|
6429
|
+
/**
|
|
6430
|
+
* Simulate a transaction
|
|
6431
|
+
*
|
|
6432
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
6433
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
6434
|
+
*/
|
|
6435
|
+
|
|
6436
|
+
|
|
6239
6437
|
/**
|
|
6240
6438
|
* Simulate a transaction
|
|
6241
6439
|
*/
|
|
6440
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6441
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
6442
|
+
if ('message' in transactionOrMessage) {
|
|
6443
|
+
const versionedTx = transactionOrMessage;
|
|
6444
|
+
const wireTransaction = versionedTx.serialize();
|
|
6445
|
+
const encodedTransaction = Buffer.from(wireTransaction).toString('base64');
|
|
6446
|
+
|
|
6447
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
6448
|
+
throw new Error('Invalid arguments');
|
|
6449
|
+
}
|
|
6450
|
+
|
|
6451
|
+
const config = configOrSigners || {};
|
|
6452
|
+
config.encoding = 'base64';
|
|
6453
|
+
|
|
6454
|
+
if (!('commitment' in config)) {
|
|
6455
|
+
config.commitment = this.commitment;
|
|
6456
|
+
}
|
|
6242
6457
|
|
|
6458
|
+
const args = [encodedTransaction, config];
|
|
6459
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
6460
|
+
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
6461
|
+
|
|
6462
|
+
if ('error' in res) {
|
|
6463
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
6464
|
+
}
|
|
6465
|
+
|
|
6466
|
+
return res.result;
|
|
6467
|
+
}
|
|
6243
6468
|
|
|
6244
|
-
async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
|
|
6245
6469
|
let transaction;
|
|
6246
6470
|
|
|
6247
6471
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -6257,6 +6481,12 @@ class Connection {
|
|
|
6257
6481
|
transaction._message = transaction._json = undefined;
|
|
6258
6482
|
}
|
|
6259
6483
|
|
|
6484
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
6485
|
+
throw new Error('Invalid arguments');
|
|
6486
|
+
}
|
|
6487
|
+
|
|
6488
|
+
const signers = configOrSigners;
|
|
6489
|
+
|
|
6260
6490
|
if (transaction.nonceInfo && signers) {
|
|
6261
6491
|
transaction.sign(...signers);
|
|
6262
6492
|
} else {
|
|
@@ -6339,10 +6569,32 @@ class Connection {
|
|
|
6339
6569
|
}
|
|
6340
6570
|
/**
|
|
6341
6571
|
* Sign and send a transaction
|
|
6572
|
+
*
|
|
6573
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
6574
|
+
* VersionedTransaction}
|
|
6342
6575
|
*/
|
|
6343
6576
|
|
|
6344
6577
|
|
|
6345
|
-
|
|
6578
|
+
/**
|
|
6579
|
+
* Sign and send a transaction
|
|
6580
|
+
*/
|
|
6581
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6582
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
6583
|
+
if ('message' in transaction) {
|
|
6584
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
6585
|
+
throw new Error('Invalid arguments');
|
|
6586
|
+
}
|
|
6587
|
+
|
|
6588
|
+
const wireTransaction = transaction.serialize();
|
|
6589
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
6590
|
+
}
|
|
6591
|
+
|
|
6592
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6593
|
+
throw new Error('Invalid arguments');
|
|
6594
|
+
}
|
|
6595
|
+
|
|
6596
|
+
const signers = signersOrOptions;
|
|
6597
|
+
|
|
6346
6598
|
if (transaction.nonceInfo) {
|
|
6347
6599
|
transaction.sign(...signers);
|
|
6348
6600
|
} else {
|
|
@@ -9367,5 +9619,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9367
9619
|
|
|
9368
9620
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9369
9621
|
|
|
9370
|
-
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, TransactionStatus, VALIDATOR_INFO_KEY, VERSION_PREFIX_MASK, VOTE_PROGRAM_ID, ValidatorInfo, VersionedMessage, VersionedTransaction, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9622
|
+
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 };
|
|
9371
9623
|
//# sourceMappingURL=index.esm.js.map
|