@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.cjs.js
CHANGED
|
@@ -645,6 +645,121 @@ function encodeLength(bytes, len) {
|
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
647
|
|
|
648
|
+
function assert (condition, message) {
|
|
649
|
+
if (!condition) {
|
|
650
|
+
throw new Error(message || 'Assertion failed');
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
class CompiledKeys {
|
|
655
|
+
constructor(payer, keyMetaMap) {
|
|
656
|
+
this.payer = void 0;
|
|
657
|
+
this.keyMetaMap = void 0;
|
|
658
|
+
this.payer = payer;
|
|
659
|
+
this.keyMetaMap = keyMetaMap;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
static compile(instructions, payer) {
|
|
663
|
+
const keyMetaMap = new Map();
|
|
664
|
+
|
|
665
|
+
const getOrInsertDefault = pubkey => {
|
|
666
|
+
const address = pubkey.toBase58();
|
|
667
|
+
let keyMeta = keyMetaMap.get(address);
|
|
668
|
+
|
|
669
|
+
if (keyMeta === undefined) {
|
|
670
|
+
keyMeta = {
|
|
671
|
+
isSigner: false,
|
|
672
|
+
isWritable: false,
|
|
673
|
+
isInvoked: false
|
|
674
|
+
};
|
|
675
|
+
keyMetaMap.set(address, keyMeta);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
return keyMeta;
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
const payerKeyMeta = getOrInsertDefault(payer);
|
|
682
|
+
payerKeyMeta.isSigner = true;
|
|
683
|
+
payerKeyMeta.isWritable = true;
|
|
684
|
+
|
|
685
|
+
for (const ix of instructions) {
|
|
686
|
+
getOrInsertDefault(ix.programId).isInvoked = true;
|
|
687
|
+
|
|
688
|
+
for (const accountMeta of ix.keys) {
|
|
689
|
+
const keyMeta = getOrInsertDefault(accountMeta.pubkey);
|
|
690
|
+
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
691
|
+
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
return new CompiledKeys(payer, keyMetaMap);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
getMessageComponents() {
|
|
699
|
+
const mapEntries = [...this.keyMetaMap.entries()];
|
|
700
|
+
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
701
|
+
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
702
|
+
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
703
|
+
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
704
|
+
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
705
|
+
const header = {
|
|
706
|
+
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
707
|
+
numReadonlySignedAccounts: readonlySigners.length,
|
|
708
|
+
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
709
|
+
}; // sanity checks
|
|
710
|
+
|
|
711
|
+
{
|
|
712
|
+
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
713
|
+
const [payerAddress] = writableSigners[0];
|
|
714
|
+
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
715
|
+
}
|
|
716
|
+
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))];
|
|
717
|
+
return [header, staticAccountKeys];
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
extractTableLookup(lookupTable) {
|
|
721
|
+
const [writableIndexes, drainedWritableKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && keyMeta.isWritable);
|
|
722
|
+
const [readonlyIndexes, drainedReadonlyKeys] = this.drainKeysFoundInLookupTable(lookupTable.state.addresses, keyMeta => !keyMeta.isSigner && !keyMeta.isInvoked && !keyMeta.isWritable); // Don't extract lookup if no keys were found
|
|
723
|
+
|
|
724
|
+
if (writableIndexes.length === 0 && readonlyIndexes.length === 0) {
|
|
725
|
+
return;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
return [{
|
|
729
|
+
accountKey: lookupTable.key,
|
|
730
|
+
writableIndexes,
|
|
731
|
+
readonlyIndexes
|
|
732
|
+
}, {
|
|
733
|
+
writable: drainedWritableKeys,
|
|
734
|
+
readonly: drainedReadonlyKeys
|
|
735
|
+
}];
|
|
736
|
+
}
|
|
737
|
+
/** @internal */
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
drainKeysFoundInLookupTable(lookupTableEntries, keyMetaFilter) {
|
|
741
|
+
const lookupTableIndexes = new Array();
|
|
742
|
+
const drainedKeys = new Array();
|
|
743
|
+
|
|
744
|
+
for (const [address, keyMeta] of this.keyMetaMap.entries()) {
|
|
745
|
+
if (keyMetaFilter(keyMeta)) {
|
|
746
|
+
const key = new PublicKey(address);
|
|
747
|
+
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
748
|
+
|
|
749
|
+
if (lookupTableIndex >= 0) {
|
|
750
|
+
assert(lookupTableIndex < 256, 'Max lookup table index exceeded');
|
|
751
|
+
lookupTableIndexes.push(lookupTableIndex);
|
|
752
|
+
drainedKeys.push(key);
|
|
753
|
+
this.keyMetaMap.delete(address);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
return [lookupTableIndexes, drainedKeys];
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
}
|
|
762
|
+
|
|
648
763
|
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
649
764
|
/**
|
|
650
765
|
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
@@ -720,6 +835,27 @@ class Message {
|
|
|
720
835
|
return [];
|
|
721
836
|
}
|
|
722
837
|
|
|
838
|
+
getAccountKeys() {
|
|
839
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
static compile(args) {
|
|
843
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
844
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
845
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
846
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
847
|
+
programIdIndex: ix.programIdIndex,
|
|
848
|
+
accounts: ix.accountKeyIndexes,
|
|
849
|
+
data: bs58__default["default"].encode(ix.data)
|
|
850
|
+
}));
|
|
851
|
+
return new Message({
|
|
852
|
+
header,
|
|
853
|
+
accountKeys: staticAccountKeys,
|
|
854
|
+
recentBlockhash: args.recentBlockhash,
|
|
855
|
+
instructions
|
|
856
|
+
});
|
|
857
|
+
}
|
|
858
|
+
|
|
723
859
|
isAccountSigner(index) {
|
|
724
860
|
return index < this.header.numRequiredSignatures;
|
|
725
861
|
}
|
|
@@ -808,7 +944,7 @@ class Message {
|
|
|
808
944
|
|
|
809
945
|
for (let i = 0; i < accountCount; i++) {
|
|
810
946
|
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
811
|
-
accountKeys.push(
|
|
947
|
+
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
812
948
|
}
|
|
813
949
|
|
|
814
950
|
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
@@ -844,141 +980,87 @@ class Message {
|
|
|
844
980
|
|
|
845
981
|
}
|
|
846
982
|
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
}
|
|
851
|
-
}
|
|
983
|
+
/**
|
|
984
|
+
* Message constructor arguments
|
|
985
|
+
*/
|
|
852
986
|
|
|
853
|
-
class
|
|
854
|
-
constructor(
|
|
855
|
-
this.
|
|
856
|
-
this.
|
|
857
|
-
this.
|
|
858
|
-
this.
|
|
987
|
+
class MessageV0 {
|
|
988
|
+
constructor(args) {
|
|
989
|
+
this.header = void 0;
|
|
990
|
+
this.staticAccountKeys = void 0;
|
|
991
|
+
this.recentBlockhash = void 0;
|
|
992
|
+
this.compiledInstructions = void 0;
|
|
993
|
+
this.addressTableLookups = void 0;
|
|
994
|
+
this.header = args.header;
|
|
995
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
996
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
997
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
998
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
859
999
|
}
|
|
860
1000
|
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
const getOrInsertDefault = pubkey => {
|
|
865
|
-
const address = pubkey.toBase58();
|
|
866
|
-
let keyMeta = keyMetaMap.get(address);
|
|
867
|
-
|
|
868
|
-
if (keyMeta === undefined) {
|
|
869
|
-
keyMeta = {
|
|
870
|
-
isSigner: false,
|
|
871
|
-
isWritable: false,
|
|
872
|
-
isInvoked: false
|
|
873
|
-
};
|
|
874
|
-
keyMetaMap.set(address, keyMeta);
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
return keyMeta;
|
|
878
|
-
};
|
|
879
|
-
|
|
880
|
-
const payerKeyMeta = getOrInsertDefault(payer);
|
|
881
|
-
payerKeyMeta.isSigner = true;
|
|
882
|
-
payerKeyMeta.isWritable = true;
|
|
1001
|
+
get version() {
|
|
1002
|
+
return 0;
|
|
1003
|
+
}
|
|
883
1004
|
|
|
884
|
-
|
|
885
|
-
|
|
1005
|
+
get numAccountKeysFromLookups() {
|
|
1006
|
+
let count = 0;
|
|
886
1007
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
890
|
-
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
891
|
-
}
|
|
1008
|
+
for (const lookup of this.addressTableLookups) {
|
|
1009
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
892
1010
|
}
|
|
893
1011
|
|
|
894
|
-
return
|
|
1012
|
+
return count;
|
|
895
1013
|
}
|
|
896
1014
|
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
900
|
-
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
901
|
-
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
902
|
-
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
903
|
-
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
904
|
-
const header = {
|
|
905
|
-
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
906
|
-
numReadonlySignedAccounts: readonlySigners.length,
|
|
907
|
-
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
908
|
-
}; // sanity checks
|
|
909
|
-
|
|
910
|
-
{
|
|
911
|
-
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
912
|
-
const [payerAddress] = writableSigners[0];
|
|
913
|
-
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
914
|
-
}
|
|
915
|
-
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))];
|
|
916
|
-
return [header, staticAccountKeys];
|
|
917
|
-
}
|
|
1015
|
+
getAccountKeys(args) {
|
|
1016
|
+
let accountKeysFromLookups;
|
|
918
1017
|
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1018
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
1019
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
1020
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
1021
|
+
}
|
|
922
1022
|
|
|
923
|
-
|
|
924
|
-
|
|
1023
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
1024
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
1025
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
1026
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
1027
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
925
1028
|
}
|
|
926
1029
|
|
|
927
|
-
return
|
|
928
|
-
accountKey: lookupTable.key,
|
|
929
|
-
writableIndexes,
|
|
930
|
-
readonlyIndexes
|
|
931
|
-
}, {
|
|
932
|
-
writable: drainedWritableKeys,
|
|
933
|
-
readonly: drainedReadonlyKeys
|
|
934
|
-
}];
|
|
1030
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
935
1031
|
}
|
|
936
|
-
/** @internal */
|
|
937
1032
|
|
|
1033
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
1034
|
+
const accountKeysFromLookups = {
|
|
1035
|
+
writable: [],
|
|
1036
|
+
readonly: []
|
|
1037
|
+
};
|
|
938
1038
|
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
const drainedKeys = new Array();
|
|
1039
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
1040
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
942
1041
|
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
1042
|
+
if (!tableAccount) {
|
|
1043
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
1044
|
+
}
|
|
947
1045
|
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
1046
|
+
for (const index of tableLookup.writableIndexes) {
|
|
1047
|
+
if (index < tableAccount.state.addresses.length) {
|
|
1048
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
1049
|
+
} else {
|
|
1050
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
953
1051
|
}
|
|
954
1052
|
}
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
return [lookupTableIndexes, drainedKeys];
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
}
|
|
961
1053
|
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
this.recentBlockhash = void 0;
|
|
971
|
-
this.compiledInstructions = void 0;
|
|
972
|
-
this.addressTableLookups = void 0;
|
|
973
|
-
this.header = args.header;
|
|
974
|
-
this.staticAccountKeys = args.staticAccountKeys;
|
|
975
|
-
this.recentBlockhash = args.recentBlockhash;
|
|
976
|
-
this.compiledInstructions = args.compiledInstructions;
|
|
977
|
-
this.addressTableLookups = args.addressTableLookups;
|
|
978
|
-
}
|
|
1054
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
1055
|
+
if (index < tableAccount.state.addresses.length) {
|
|
1056
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
1057
|
+
} else {
|
|
1058
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
979
1062
|
|
|
980
|
-
|
|
981
|
-
return 0;
|
|
1063
|
+
return accountKeysFromLookups;
|
|
982
1064
|
}
|
|
983
1065
|
|
|
984
1066
|
static compile(args) {
|
|
@@ -1909,6 +1991,114 @@ class Transaction {
|
|
|
1909
1991
|
|
|
1910
1992
|
}
|
|
1911
1993
|
|
|
1994
|
+
class TransactionMessage {
|
|
1995
|
+
constructor(args) {
|
|
1996
|
+
this.accountKeys = void 0;
|
|
1997
|
+
this.instructions = void 0;
|
|
1998
|
+
this.recentBlockhash = void 0;
|
|
1999
|
+
this.accountKeys = args.accountKeys;
|
|
2000
|
+
this.instructions = args.instructions;
|
|
2001
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
static decompile(message, args) {
|
|
2005
|
+
const {
|
|
2006
|
+
header,
|
|
2007
|
+
compiledInstructions,
|
|
2008
|
+
recentBlockhash
|
|
2009
|
+
} = message;
|
|
2010
|
+
const {
|
|
2011
|
+
numRequiredSignatures,
|
|
2012
|
+
numReadonlySignedAccounts,
|
|
2013
|
+
numReadonlyUnsignedAccounts
|
|
2014
|
+
} = header;
|
|
2015
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
2016
|
+
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
2017
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
2018
|
+
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
2019
|
+
const accountKeys = message.getAccountKeys(args);
|
|
2020
|
+
const instructions = [];
|
|
2021
|
+
|
|
2022
|
+
for (const compiledIx of compiledInstructions) {
|
|
2023
|
+
const keys = [];
|
|
2024
|
+
|
|
2025
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
2026
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
2027
|
+
|
|
2028
|
+
if (pubkey === undefined) {
|
|
2029
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
2033
|
+
let isWritable;
|
|
2034
|
+
|
|
2035
|
+
if (isSigner) {
|
|
2036
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
2037
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
2038
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
2039
|
+
} else {
|
|
2040
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
2041
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
keys.push({
|
|
2045
|
+
pubkey,
|
|
2046
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
2047
|
+
isWritable
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
2052
|
+
|
|
2053
|
+
if (programId === undefined) {
|
|
2054
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
instructions.push(new TransactionInstruction({
|
|
2058
|
+
programId,
|
|
2059
|
+
data: toBuffer(compiledIx.data),
|
|
2060
|
+
keys
|
|
2061
|
+
}));
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
return new TransactionMessage({
|
|
2065
|
+
accountKeys,
|
|
2066
|
+
instructions,
|
|
2067
|
+
recentBlockhash
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
compileToLegacyMessage() {
|
|
2072
|
+
const payerKey = this.accountKeys.get(0);
|
|
2073
|
+
|
|
2074
|
+
if (payerKey === undefined) {
|
|
2075
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2076
|
+
}
|
|
2077
|
+
|
|
2078
|
+
return Message.compile({
|
|
2079
|
+
payerKey,
|
|
2080
|
+
recentBlockhash: this.recentBlockhash,
|
|
2081
|
+
instructions: this.instructions
|
|
2082
|
+
});
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
2086
|
+
const payerKey = this.accountKeys.get(0);
|
|
2087
|
+
|
|
2088
|
+
if (payerKey === undefined) {
|
|
2089
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2090
|
+
}
|
|
2091
|
+
|
|
2092
|
+
return MessageV0.compile({
|
|
2093
|
+
payerKey,
|
|
2094
|
+
recentBlockhash: this.recentBlockhash,
|
|
2095
|
+
instructions: this.instructions,
|
|
2096
|
+
addressLookupTableAccounts
|
|
2097
|
+
});
|
|
2098
|
+
}
|
|
2099
|
+
|
|
2100
|
+
}
|
|
2101
|
+
|
|
1912
2102
|
/**
|
|
1913
2103
|
* Versioned transaction class
|
|
1914
2104
|
*/
|
|
@@ -4412,7 +4602,7 @@ const LogsNotificationResult = superstruct.type({
|
|
|
4412
4602
|
|
|
4413
4603
|
/** @internal */
|
|
4414
4604
|
const COMMON_HTTP_HEADERS = {
|
|
4415
|
-
'solana-client': `js/${(_process$env$npm_pack = "1.
|
|
4605
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.58.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4416
4606
|
};
|
|
4417
4607
|
/**
|
|
4418
4608
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -6270,12 +6460,46 @@ class Connection {
|
|
|
6270
6460
|
|
|
6271
6461
|
return res.result;
|
|
6272
6462
|
}
|
|
6463
|
+
/**
|
|
6464
|
+
* Simulate a transaction
|
|
6465
|
+
*
|
|
6466
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
6467
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
6468
|
+
*/
|
|
6469
|
+
|
|
6470
|
+
|
|
6273
6471
|
/**
|
|
6274
6472
|
* Simulate a transaction
|
|
6275
6473
|
*/
|
|
6474
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6475
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
6476
|
+
if ('message' in transactionOrMessage) {
|
|
6477
|
+
const versionedTx = transactionOrMessage;
|
|
6478
|
+
const wireTransaction = versionedTx.serialize();
|
|
6479
|
+
const encodedTransaction = buffer.Buffer.from(wireTransaction).toString('base64');
|
|
6480
|
+
|
|
6481
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
6482
|
+
throw new Error('Invalid arguments');
|
|
6483
|
+
}
|
|
6484
|
+
|
|
6485
|
+
const config = configOrSigners || {};
|
|
6486
|
+
config.encoding = 'base64';
|
|
6487
|
+
|
|
6488
|
+
if (!('commitment' in config)) {
|
|
6489
|
+
config.commitment = this.commitment;
|
|
6490
|
+
}
|
|
6276
6491
|
|
|
6492
|
+
const args = [encodedTransaction, config];
|
|
6493
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
6494
|
+
const res = superstruct.create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
6495
|
+
|
|
6496
|
+
if ('error' in res) {
|
|
6497
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
6498
|
+
}
|
|
6499
|
+
|
|
6500
|
+
return res.result;
|
|
6501
|
+
}
|
|
6277
6502
|
|
|
6278
|
-
async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
|
|
6279
6503
|
let transaction;
|
|
6280
6504
|
|
|
6281
6505
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -6291,6 +6515,12 @@ class Connection {
|
|
|
6291
6515
|
transaction._message = transaction._json = undefined;
|
|
6292
6516
|
}
|
|
6293
6517
|
|
|
6518
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
6519
|
+
throw new Error('Invalid arguments');
|
|
6520
|
+
}
|
|
6521
|
+
|
|
6522
|
+
const signers = configOrSigners;
|
|
6523
|
+
|
|
6294
6524
|
if (transaction.nonceInfo && signers) {
|
|
6295
6525
|
transaction.sign(...signers);
|
|
6296
6526
|
} else {
|
|
@@ -6373,10 +6603,32 @@ class Connection {
|
|
|
6373
6603
|
}
|
|
6374
6604
|
/**
|
|
6375
6605
|
* Sign and send a transaction
|
|
6606
|
+
*
|
|
6607
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
6608
|
+
* VersionedTransaction}
|
|
6376
6609
|
*/
|
|
6377
6610
|
|
|
6378
6611
|
|
|
6379
|
-
|
|
6612
|
+
/**
|
|
6613
|
+
* Sign and send a transaction
|
|
6614
|
+
*/
|
|
6615
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6616
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
6617
|
+
if ('message' in transaction) {
|
|
6618
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
6619
|
+
throw new Error('Invalid arguments');
|
|
6620
|
+
}
|
|
6621
|
+
|
|
6622
|
+
const wireTransaction = transaction.serialize();
|
|
6623
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
6624
|
+
}
|
|
6625
|
+
|
|
6626
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6627
|
+
throw new Error('Invalid arguments');
|
|
6628
|
+
}
|
|
6629
|
+
|
|
6630
|
+
const signers = signersOrOptions;
|
|
6631
|
+
|
|
6380
6632
|
if (transaction.nonceInfo) {
|
|
6381
6633
|
transaction.sign(...signers);
|
|
6382
6634
|
} else {
|
|
@@ -9460,6 +9712,7 @@ exports.Transaction = Transaction;
|
|
|
9460
9712
|
exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheightExceededError;
|
|
9461
9713
|
exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
|
|
9462
9714
|
exports.TransactionInstruction = TransactionInstruction;
|
|
9715
|
+
exports.TransactionMessage = TransactionMessage;
|
|
9463
9716
|
exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
|
|
9464
9717
|
exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
|
|
9465
9718
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|