@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.browser.esm.js
CHANGED
|
@@ -608,6 +608,121 @@ function encodeLength(bytes, len) {
|
|
|
608
608
|
}
|
|
609
609
|
}
|
|
610
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
|
+
|
|
611
726
|
const END_OF_BUFFER_ERROR_MESSAGE = 'Reached end of buffer unexpectedly';
|
|
612
727
|
/**
|
|
613
728
|
* Delegates to `Array#shift`, but throws if the array is zero-length.
|
|
@@ -683,6 +798,27 @@ class Message {
|
|
|
683
798
|
return [];
|
|
684
799
|
}
|
|
685
800
|
|
|
801
|
+
getAccountKeys() {
|
|
802
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
static compile(args) {
|
|
806
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
807
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
808
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
809
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
810
|
+
programIdIndex: ix.programIdIndex,
|
|
811
|
+
accounts: ix.accountKeyIndexes,
|
|
812
|
+
data: bs58.encode(ix.data)
|
|
813
|
+
}));
|
|
814
|
+
return new Message({
|
|
815
|
+
header,
|
|
816
|
+
accountKeys: staticAccountKeys,
|
|
817
|
+
recentBlockhash: args.recentBlockhash,
|
|
818
|
+
instructions
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
|
|
686
822
|
isAccountSigner(index) {
|
|
687
823
|
return index < this.header.numRequiredSignatures;
|
|
688
824
|
}
|
|
@@ -771,7 +907,7 @@ class Message {
|
|
|
771
907
|
|
|
772
908
|
for (let i = 0; i < accountCount; i++) {
|
|
773
909
|
const account = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
774
|
-
accountKeys.push(
|
|
910
|
+
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
775
911
|
}
|
|
776
912
|
|
|
777
913
|
const recentBlockhash = guardedSplice(byteArray, 0, PUBLIC_KEY_LENGTH);
|
|
@@ -807,141 +943,87 @@ class Message {
|
|
|
807
943
|
|
|
808
944
|
}
|
|
809
945
|
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
}
|
|
814
|
-
}
|
|
946
|
+
/**
|
|
947
|
+
* Message constructor arguments
|
|
948
|
+
*/
|
|
815
949
|
|
|
816
|
-
class
|
|
817
|
-
constructor(
|
|
818
|
-
this.
|
|
819
|
-
this.
|
|
820
|
-
this.
|
|
821
|
-
this.
|
|
950
|
+
class MessageV0 {
|
|
951
|
+
constructor(args) {
|
|
952
|
+
this.header = void 0;
|
|
953
|
+
this.staticAccountKeys = void 0;
|
|
954
|
+
this.recentBlockhash = void 0;
|
|
955
|
+
this.compiledInstructions = void 0;
|
|
956
|
+
this.addressTableLookups = void 0;
|
|
957
|
+
this.header = args.header;
|
|
958
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
959
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
960
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
961
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
822
962
|
}
|
|
823
963
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
const getOrInsertDefault = pubkey => {
|
|
828
|
-
const address = pubkey.toBase58();
|
|
829
|
-
let keyMeta = keyMetaMap.get(address);
|
|
830
|
-
|
|
831
|
-
if (keyMeta === undefined) {
|
|
832
|
-
keyMeta = {
|
|
833
|
-
isSigner: false,
|
|
834
|
-
isWritable: false,
|
|
835
|
-
isInvoked: false
|
|
836
|
-
};
|
|
837
|
-
keyMetaMap.set(address, keyMeta);
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
return keyMeta;
|
|
841
|
-
};
|
|
842
|
-
|
|
843
|
-
const payerKeyMeta = getOrInsertDefault(payer);
|
|
844
|
-
payerKeyMeta.isSigner = true;
|
|
845
|
-
payerKeyMeta.isWritable = true;
|
|
964
|
+
get version() {
|
|
965
|
+
return 0;
|
|
966
|
+
}
|
|
846
967
|
|
|
847
|
-
|
|
848
|
-
|
|
968
|
+
get numAccountKeysFromLookups() {
|
|
969
|
+
let count = 0;
|
|
849
970
|
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
853
|
-
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
854
|
-
}
|
|
971
|
+
for (const lookup of this.addressTableLookups) {
|
|
972
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
855
973
|
}
|
|
856
974
|
|
|
857
|
-
return
|
|
975
|
+
return count;
|
|
858
976
|
}
|
|
859
977
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
863
|
-
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
864
|
-
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
865
|
-
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
866
|
-
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
867
|
-
const header = {
|
|
868
|
-
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
869
|
-
numReadonlySignedAccounts: readonlySigners.length,
|
|
870
|
-
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
871
|
-
}; // sanity checks
|
|
872
|
-
|
|
873
|
-
{
|
|
874
|
-
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
875
|
-
const [payerAddress] = writableSigners[0];
|
|
876
|
-
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
877
|
-
}
|
|
878
|
-
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))];
|
|
879
|
-
return [header, staticAccountKeys];
|
|
880
|
-
}
|
|
978
|
+
getAccountKeys(args) {
|
|
979
|
+
let accountKeysFromLookups;
|
|
881
980
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
981
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
982
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
983
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
984
|
+
}
|
|
885
985
|
|
|
886
|
-
|
|
887
|
-
|
|
986
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
987
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
988
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
989
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
990
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
888
991
|
}
|
|
889
992
|
|
|
890
|
-
return
|
|
891
|
-
accountKey: lookupTable.key,
|
|
892
|
-
writableIndexes,
|
|
893
|
-
readonlyIndexes
|
|
894
|
-
}, {
|
|
895
|
-
writable: drainedWritableKeys,
|
|
896
|
-
readonly: drainedReadonlyKeys
|
|
897
|
-
}];
|
|
993
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
898
994
|
}
|
|
899
|
-
/** @internal */
|
|
900
995
|
|
|
996
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
997
|
+
const accountKeysFromLookups = {
|
|
998
|
+
writable: [],
|
|
999
|
+
readonly: []
|
|
1000
|
+
};
|
|
901
1001
|
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
const drainedKeys = new Array();
|
|
1002
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
1003
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
905
1004
|
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
1005
|
+
if (!tableAccount) {
|
|
1006
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
1007
|
+
}
|
|
910
1008
|
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1009
|
+
for (const index of tableLookup.writableIndexes) {
|
|
1010
|
+
if (index < tableAccount.state.addresses.length) {
|
|
1011
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
1012
|
+
} else {
|
|
1013
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
916
1014
|
}
|
|
917
1015
|
}
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
return [lookupTableIndexes, drainedKeys];
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
}
|
|
924
1016
|
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
this.recentBlockhash = void 0;
|
|
934
|
-
this.compiledInstructions = void 0;
|
|
935
|
-
this.addressTableLookups = void 0;
|
|
936
|
-
this.header = args.header;
|
|
937
|
-
this.staticAccountKeys = args.staticAccountKeys;
|
|
938
|
-
this.recentBlockhash = args.recentBlockhash;
|
|
939
|
-
this.compiledInstructions = args.compiledInstructions;
|
|
940
|
-
this.addressTableLookups = args.addressTableLookups;
|
|
941
|
-
}
|
|
1017
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
1018
|
+
if (index < tableAccount.state.addresses.length) {
|
|
1019
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
1020
|
+
} else {
|
|
1021
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
942
1025
|
|
|
943
|
-
|
|
944
|
-
return 0;
|
|
1026
|
+
return accountKeysFromLookups;
|
|
945
1027
|
}
|
|
946
1028
|
|
|
947
1029
|
static compile(args) {
|
|
@@ -1872,6 +1954,114 @@ class Transaction {
|
|
|
1872
1954
|
|
|
1873
1955
|
}
|
|
1874
1956
|
|
|
1957
|
+
class TransactionMessage {
|
|
1958
|
+
constructor(args) {
|
|
1959
|
+
this.accountKeys = void 0;
|
|
1960
|
+
this.instructions = void 0;
|
|
1961
|
+
this.recentBlockhash = void 0;
|
|
1962
|
+
this.accountKeys = args.accountKeys;
|
|
1963
|
+
this.instructions = args.instructions;
|
|
1964
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
static decompile(message, args) {
|
|
1968
|
+
const {
|
|
1969
|
+
header,
|
|
1970
|
+
compiledInstructions,
|
|
1971
|
+
recentBlockhash
|
|
1972
|
+
} = message;
|
|
1973
|
+
const {
|
|
1974
|
+
numRequiredSignatures,
|
|
1975
|
+
numReadonlySignedAccounts,
|
|
1976
|
+
numReadonlyUnsignedAccounts
|
|
1977
|
+
} = header;
|
|
1978
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
1979
|
+
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
1980
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1981
|
+
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1982
|
+
const accountKeys = message.getAccountKeys(args);
|
|
1983
|
+
const instructions = [];
|
|
1984
|
+
|
|
1985
|
+
for (const compiledIx of compiledInstructions) {
|
|
1986
|
+
const keys = [];
|
|
1987
|
+
|
|
1988
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
1989
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
1990
|
+
|
|
1991
|
+
if (pubkey === undefined) {
|
|
1992
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
1996
|
+
let isWritable;
|
|
1997
|
+
|
|
1998
|
+
if (isSigner) {
|
|
1999
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
2000
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
2001
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
2002
|
+
} else {
|
|
2003
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
2004
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
keys.push({
|
|
2008
|
+
pubkey,
|
|
2009
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
2010
|
+
isWritable
|
|
2011
|
+
});
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
2015
|
+
|
|
2016
|
+
if (programId === undefined) {
|
|
2017
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
instructions.push(new TransactionInstruction({
|
|
2021
|
+
programId,
|
|
2022
|
+
data: toBuffer(compiledIx.data),
|
|
2023
|
+
keys
|
|
2024
|
+
}));
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
return new TransactionMessage({
|
|
2028
|
+
accountKeys,
|
|
2029
|
+
instructions,
|
|
2030
|
+
recentBlockhash
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
compileToLegacyMessage() {
|
|
2035
|
+
const payerKey = this.accountKeys.get(0);
|
|
2036
|
+
|
|
2037
|
+
if (payerKey === undefined) {
|
|
2038
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
return Message.compile({
|
|
2042
|
+
payerKey,
|
|
2043
|
+
recentBlockhash: this.recentBlockhash,
|
|
2044
|
+
instructions: this.instructions
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
|
|
2048
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
2049
|
+
const payerKey = this.accountKeys.get(0);
|
|
2050
|
+
|
|
2051
|
+
if (payerKey === undefined) {
|
|
2052
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
return MessageV0.compile({
|
|
2056
|
+
payerKey,
|
|
2057
|
+
recentBlockhash: this.recentBlockhash,
|
|
2058
|
+
instructions: this.instructions,
|
|
2059
|
+
addressLookupTableAccounts
|
|
2060
|
+
});
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
}
|
|
2064
|
+
|
|
1875
2065
|
/**
|
|
1876
2066
|
* Versioned transaction class
|
|
1877
2067
|
*/
|
|
@@ -4315,7 +4505,7 @@ const LogsNotificationResult = type({
|
|
|
4315
4505
|
|
|
4316
4506
|
/** @internal */
|
|
4317
4507
|
const COMMON_HTTP_HEADERS = {
|
|
4318
|
-
'solana-client': `js/${(_process$env$npm_pack = "1.
|
|
4508
|
+
'solana-client': `js/${(_process$env$npm_pack = "1.58.1") !== null && _process$env$npm_pack !== void 0 ? _process$env$npm_pack : 'UNKNOWN'}`
|
|
4319
4509
|
};
|
|
4320
4510
|
/**
|
|
4321
4511
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -6173,12 +6363,46 @@ class Connection {
|
|
|
6173
6363
|
|
|
6174
6364
|
return res.result;
|
|
6175
6365
|
}
|
|
6366
|
+
/**
|
|
6367
|
+
* Simulate a transaction
|
|
6368
|
+
*
|
|
6369
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
6370
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
6371
|
+
*/
|
|
6372
|
+
|
|
6373
|
+
|
|
6176
6374
|
/**
|
|
6177
6375
|
* Simulate a transaction
|
|
6178
6376
|
*/
|
|
6377
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6378
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
6379
|
+
if ('message' in transactionOrMessage) {
|
|
6380
|
+
const versionedTx = transactionOrMessage;
|
|
6381
|
+
const wireTransaction = versionedTx.serialize();
|
|
6382
|
+
const encodedTransaction = Buffer.from(wireTransaction).toString('base64');
|
|
6383
|
+
|
|
6384
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
6385
|
+
throw new Error('Invalid arguments');
|
|
6386
|
+
}
|
|
6387
|
+
|
|
6388
|
+
const config = configOrSigners || {};
|
|
6389
|
+
config.encoding = 'base64';
|
|
6390
|
+
|
|
6391
|
+
if (!('commitment' in config)) {
|
|
6392
|
+
config.commitment = this.commitment;
|
|
6393
|
+
}
|
|
6179
6394
|
|
|
6395
|
+
const args = [encodedTransaction, config];
|
|
6396
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
6397
|
+
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
6398
|
+
|
|
6399
|
+
if ('error' in res) {
|
|
6400
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
6401
|
+
}
|
|
6402
|
+
|
|
6403
|
+
return res.result;
|
|
6404
|
+
}
|
|
6180
6405
|
|
|
6181
|
-
async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
|
|
6182
6406
|
let transaction;
|
|
6183
6407
|
|
|
6184
6408
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -6194,6 +6418,12 @@ class Connection {
|
|
|
6194
6418
|
transaction._message = transaction._json = undefined;
|
|
6195
6419
|
}
|
|
6196
6420
|
|
|
6421
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
6422
|
+
throw new Error('Invalid arguments');
|
|
6423
|
+
}
|
|
6424
|
+
|
|
6425
|
+
const signers = configOrSigners;
|
|
6426
|
+
|
|
6197
6427
|
if (transaction.nonceInfo && signers) {
|
|
6198
6428
|
transaction.sign(...signers);
|
|
6199
6429
|
} else {
|
|
@@ -6276,10 +6506,32 @@ class Connection {
|
|
|
6276
6506
|
}
|
|
6277
6507
|
/**
|
|
6278
6508
|
* Sign and send a transaction
|
|
6509
|
+
*
|
|
6510
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
6511
|
+
* VersionedTransaction}
|
|
6279
6512
|
*/
|
|
6280
6513
|
|
|
6281
6514
|
|
|
6282
|
-
|
|
6515
|
+
/**
|
|
6516
|
+
* Sign and send a transaction
|
|
6517
|
+
*/
|
|
6518
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6519
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
6520
|
+
if ('message' in transaction) {
|
|
6521
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
6522
|
+
throw new Error('Invalid arguments');
|
|
6523
|
+
}
|
|
6524
|
+
|
|
6525
|
+
const wireTransaction = transaction.serialize();
|
|
6526
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
6527
|
+
}
|
|
6528
|
+
|
|
6529
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6530
|
+
throw new Error('Invalid arguments');
|
|
6531
|
+
}
|
|
6532
|
+
|
|
6533
|
+
const signers = signersOrOptions;
|
|
6534
|
+
|
|
6283
6535
|
if (transaction.nonceInfo) {
|
|
6284
6536
|
transaction.sign(...signers);
|
|
6285
6537
|
} else {
|
|
@@ -9304,5 +9556,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9304
9556
|
|
|
9305
9557
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9306
9558
|
|
|
9307
|
-
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 };
|
|
9559
|
+
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 };
|
|
9308
9560
|
//# sourceMappingURL=index.browser.esm.js.map
|