@solana/web3.js 1.57.0 → 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 +377 -116
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +377 -117
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +377 -116
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +82 -1
- package/lib/index.esm.js +377 -117
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +377 -116
- 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 +377 -116
- 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,129 @@ 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
|
+
|
|
729
|
+
/**
|
|
730
|
+
* An instruction to execute by a program
|
|
731
|
+
*
|
|
732
|
+
* @property {number} programIdIndex
|
|
733
|
+
* @property {number[]} accounts
|
|
734
|
+
* @property {string} data
|
|
735
|
+
*/
|
|
736
|
+
|
|
614
737
|
/**
|
|
615
738
|
* List of instructions to be processed atomically
|
|
616
739
|
*/
|
|
@@ -648,6 +771,27 @@ class Message {
|
|
|
648
771
|
return [];
|
|
649
772
|
}
|
|
650
773
|
|
|
774
|
+
getAccountKeys() {
|
|
775
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
static compile(args) {
|
|
779
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
780
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
781
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
782
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
783
|
+
programIdIndex: ix.programIdIndex,
|
|
784
|
+
accounts: ix.accountKeyIndexes,
|
|
785
|
+
data: bs58.encode(ix.data)
|
|
786
|
+
}));
|
|
787
|
+
return new Message({
|
|
788
|
+
header,
|
|
789
|
+
accountKeys: staticAccountKeys,
|
|
790
|
+
recentBlockhash: args.recentBlockhash,
|
|
791
|
+
instructions
|
|
792
|
+
});
|
|
793
|
+
}
|
|
794
|
+
|
|
651
795
|
isAccountSigner(index) {
|
|
652
796
|
return index < this.header.numRequiredSignatures;
|
|
653
797
|
}
|
|
@@ -737,7 +881,7 @@ class Message {
|
|
|
737
881
|
for (let i = 0; i < accountCount; i++) {
|
|
738
882
|
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
739
883
|
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
740
|
-
accountKeys.push(
|
|
884
|
+
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
741
885
|
}
|
|
742
886
|
|
|
743
887
|
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
@@ -776,141 +920,87 @@ class Message {
|
|
|
776
920
|
|
|
777
921
|
}
|
|
778
922
|
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
}
|
|
783
|
-
}
|
|
923
|
+
/**
|
|
924
|
+
* Message constructor arguments
|
|
925
|
+
*/
|
|
784
926
|
|
|
785
|
-
class
|
|
786
|
-
constructor(
|
|
787
|
-
this.
|
|
788
|
-
this.
|
|
789
|
-
this.
|
|
790
|
-
this.
|
|
927
|
+
class MessageV0 {
|
|
928
|
+
constructor(args) {
|
|
929
|
+
this.header = void 0;
|
|
930
|
+
this.staticAccountKeys = void 0;
|
|
931
|
+
this.recentBlockhash = void 0;
|
|
932
|
+
this.compiledInstructions = void 0;
|
|
933
|
+
this.addressTableLookups = void 0;
|
|
934
|
+
this.header = args.header;
|
|
935
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
936
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
937
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
938
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
791
939
|
}
|
|
792
940
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
const getOrInsertDefault = pubkey => {
|
|
797
|
-
const address = pubkey.toBase58();
|
|
798
|
-
let keyMeta = keyMetaMap.get(address);
|
|
799
|
-
|
|
800
|
-
if (keyMeta === undefined) {
|
|
801
|
-
keyMeta = {
|
|
802
|
-
isSigner: false,
|
|
803
|
-
isWritable: false,
|
|
804
|
-
isInvoked: false
|
|
805
|
-
};
|
|
806
|
-
keyMetaMap.set(address, keyMeta);
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
return keyMeta;
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
const payerKeyMeta = getOrInsertDefault(payer);
|
|
813
|
-
payerKeyMeta.isSigner = true;
|
|
814
|
-
payerKeyMeta.isWritable = true;
|
|
941
|
+
get version() {
|
|
942
|
+
return 0;
|
|
943
|
+
}
|
|
815
944
|
|
|
816
|
-
|
|
817
|
-
|
|
945
|
+
get numAccountKeysFromLookups() {
|
|
946
|
+
let count = 0;
|
|
818
947
|
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
822
|
-
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
823
|
-
}
|
|
948
|
+
for (const lookup of this.addressTableLookups) {
|
|
949
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
824
950
|
}
|
|
825
951
|
|
|
826
|
-
return
|
|
952
|
+
return count;
|
|
827
953
|
}
|
|
828
954
|
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
832
|
-
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
833
|
-
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
834
|
-
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
835
|
-
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
836
|
-
const header = {
|
|
837
|
-
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
838
|
-
numReadonlySignedAccounts: readonlySigners.length,
|
|
839
|
-
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
840
|
-
}; // sanity checks
|
|
841
|
-
|
|
842
|
-
{
|
|
843
|
-
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
844
|
-
const [payerAddress] = writableSigners[0];
|
|
845
|
-
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
846
|
-
}
|
|
847
|
-
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))];
|
|
848
|
-
return [header, staticAccountKeys];
|
|
849
|
-
}
|
|
955
|
+
getAccountKeys(args) {
|
|
956
|
+
let accountKeysFromLookups;
|
|
850
957
|
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
958
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
959
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
960
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
961
|
+
}
|
|
854
962
|
|
|
855
|
-
|
|
856
|
-
|
|
963
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
964
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
965
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
966
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
967
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
857
968
|
}
|
|
858
969
|
|
|
859
|
-
return
|
|
860
|
-
accountKey: lookupTable.key,
|
|
861
|
-
writableIndexes,
|
|
862
|
-
readonlyIndexes
|
|
863
|
-
}, {
|
|
864
|
-
writable: drainedWritableKeys,
|
|
865
|
-
readonly: drainedReadonlyKeys
|
|
866
|
-
}];
|
|
970
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
867
971
|
}
|
|
868
|
-
/** @internal */
|
|
869
972
|
|
|
973
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
974
|
+
const accountKeysFromLookups = {
|
|
975
|
+
writable: [],
|
|
976
|
+
readonly: []
|
|
977
|
+
};
|
|
870
978
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
const drainedKeys = new Array();
|
|
979
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
980
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
874
981
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
982
|
+
if (!tableAccount) {
|
|
983
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
984
|
+
}
|
|
879
985
|
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
986
|
+
for (const index of tableLookup.writableIndexes) {
|
|
987
|
+
if (index < tableAccount.state.addresses.length) {
|
|
988
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
989
|
+
} else {
|
|
990
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
885
991
|
}
|
|
886
992
|
}
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
return [lookupTableIndexes, drainedKeys];
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
/**
|
|
895
|
-
* Message constructor arguments
|
|
896
|
-
*/
|
|
897
993
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
this.staticAccountKeys = args.staticAccountKeys;
|
|
907
|
-
this.recentBlockhash = args.recentBlockhash;
|
|
908
|
-
this.compiledInstructions = args.compiledInstructions;
|
|
909
|
-
this.addressTableLookups = args.addressTableLookups;
|
|
910
|
-
}
|
|
994
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
995
|
+
if (index < tableAccount.state.addresses.length) {
|
|
996
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
997
|
+
} else {
|
|
998
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
911
1002
|
|
|
912
|
-
|
|
913
|
-
return 0;
|
|
1003
|
+
return accountKeysFromLookups;
|
|
914
1004
|
}
|
|
915
1005
|
|
|
916
1006
|
static compile(args) {
|
|
@@ -1842,6 +1932,114 @@ class Transaction {
|
|
|
1842
1932
|
|
|
1843
1933
|
}
|
|
1844
1934
|
|
|
1935
|
+
class TransactionMessage {
|
|
1936
|
+
constructor(args) {
|
|
1937
|
+
this.accountKeys = void 0;
|
|
1938
|
+
this.instructions = void 0;
|
|
1939
|
+
this.recentBlockhash = void 0;
|
|
1940
|
+
this.accountKeys = args.accountKeys;
|
|
1941
|
+
this.instructions = args.instructions;
|
|
1942
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
static decompile(message, args) {
|
|
1946
|
+
const {
|
|
1947
|
+
header,
|
|
1948
|
+
compiledInstructions,
|
|
1949
|
+
recentBlockhash
|
|
1950
|
+
} = message;
|
|
1951
|
+
const {
|
|
1952
|
+
numRequiredSignatures,
|
|
1953
|
+
numReadonlySignedAccounts,
|
|
1954
|
+
numReadonlyUnsignedAccounts
|
|
1955
|
+
} = header;
|
|
1956
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
1957
|
+
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
1958
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1959
|
+
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1960
|
+
const accountKeys = message.getAccountKeys(args);
|
|
1961
|
+
const instructions = [];
|
|
1962
|
+
|
|
1963
|
+
for (const compiledIx of compiledInstructions) {
|
|
1964
|
+
const keys = [];
|
|
1965
|
+
|
|
1966
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
1967
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
1968
|
+
|
|
1969
|
+
if (pubkey === undefined) {
|
|
1970
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
1974
|
+
let isWritable;
|
|
1975
|
+
|
|
1976
|
+
if (isSigner) {
|
|
1977
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
1978
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
1979
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
1980
|
+
} else {
|
|
1981
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
1982
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
keys.push({
|
|
1986
|
+
pubkey,
|
|
1987
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
1988
|
+
isWritable
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
1993
|
+
|
|
1994
|
+
if (programId === undefined) {
|
|
1995
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
instructions.push(new TransactionInstruction({
|
|
1999
|
+
programId,
|
|
2000
|
+
data: toBuffer(compiledIx.data),
|
|
2001
|
+
keys
|
|
2002
|
+
}));
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
return new TransactionMessage({
|
|
2006
|
+
accountKeys,
|
|
2007
|
+
instructions,
|
|
2008
|
+
recentBlockhash
|
|
2009
|
+
});
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
compileToLegacyMessage() {
|
|
2013
|
+
const payerKey = this.accountKeys.get(0);
|
|
2014
|
+
|
|
2015
|
+
if (payerKey === undefined) {
|
|
2016
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
return Message.compile({
|
|
2020
|
+
payerKey,
|
|
2021
|
+
recentBlockhash: this.recentBlockhash,
|
|
2022
|
+
instructions: this.instructions
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
2027
|
+
const payerKey = this.accountKeys.get(0);
|
|
2028
|
+
|
|
2029
|
+
if (payerKey === undefined) {
|
|
2030
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
return MessageV0.compile({
|
|
2034
|
+
payerKey,
|
|
2035
|
+
recentBlockhash: this.recentBlockhash,
|
|
2036
|
+
instructions: this.instructions,
|
|
2037
|
+
addressLookupTableAccounts
|
|
2038
|
+
});
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
}
|
|
2042
|
+
|
|
1845
2043
|
/**
|
|
1846
2044
|
* Versioned transaction class
|
|
1847
2045
|
*/
|
|
@@ -6205,10 +6403,44 @@ class Connection {
|
|
|
6205
6403
|
}
|
|
6206
6404
|
/**
|
|
6207
6405
|
* Simulate a transaction
|
|
6406
|
+
*
|
|
6407
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
6408
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
6208
6409
|
*/
|
|
6209
6410
|
|
|
6210
6411
|
|
|
6211
|
-
|
|
6412
|
+
/**
|
|
6413
|
+
* Simulate a transaction
|
|
6414
|
+
*/
|
|
6415
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6416
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
6417
|
+
if ('message' in transactionOrMessage) {
|
|
6418
|
+
const versionedTx = transactionOrMessage;
|
|
6419
|
+
const wireTransaction = versionedTx.serialize();
|
|
6420
|
+
const encodedTransaction = Buffer.from(wireTransaction).toString('base64');
|
|
6421
|
+
|
|
6422
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
6423
|
+
throw new Error('Invalid arguments');
|
|
6424
|
+
}
|
|
6425
|
+
|
|
6426
|
+
const config = configOrSigners || {};
|
|
6427
|
+
config.encoding = 'base64';
|
|
6428
|
+
|
|
6429
|
+
if (!('commitment' in config)) {
|
|
6430
|
+
config.commitment = this.commitment;
|
|
6431
|
+
}
|
|
6432
|
+
|
|
6433
|
+
const args = [encodedTransaction, config];
|
|
6434
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
6435
|
+
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
6436
|
+
|
|
6437
|
+
if ('error' in res) {
|
|
6438
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
6439
|
+
}
|
|
6440
|
+
|
|
6441
|
+
return res.result;
|
|
6442
|
+
}
|
|
6443
|
+
|
|
6212
6444
|
let transaction;
|
|
6213
6445
|
|
|
6214
6446
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -6224,6 +6456,12 @@ class Connection {
|
|
|
6224
6456
|
transaction._message = transaction._json = undefined;
|
|
6225
6457
|
}
|
|
6226
6458
|
|
|
6459
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
6460
|
+
throw new Error('Invalid arguments');
|
|
6461
|
+
}
|
|
6462
|
+
|
|
6463
|
+
const signers = configOrSigners;
|
|
6464
|
+
|
|
6227
6465
|
if (transaction.nonceInfo && signers) {
|
|
6228
6466
|
transaction.sign(...signers);
|
|
6229
6467
|
} else {
|
|
@@ -6304,12 +6542,34 @@ class Connection {
|
|
|
6304
6542
|
|
|
6305
6543
|
return res.result;
|
|
6306
6544
|
}
|
|
6545
|
+
/**
|
|
6546
|
+
* Sign and send a transaction
|
|
6547
|
+
*
|
|
6548
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
6549
|
+
* VersionedTransaction}
|
|
6550
|
+
*/
|
|
6551
|
+
|
|
6552
|
+
|
|
6307
6553
|
/**
|
|
6308
6554
|
* Sign and send a transaction
|
|
6309
6555
|
*/
|
|
6556
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6557
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
6558
|
+
if ('message' in transaction) {
|
|
6559
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
6560
|
+
throw new Error('Invalid arguments');
|
|
6561
|
+
}
|
|
6562
|
+
|
|
6563
|
+
const wireTransaction = transaction.serialize();
|
|
6564
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
6565
|
+
}
|
|
6566
|
+
|
|
6567
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6568
|
+
throw new Error('Invalid arguments');
|
|
6569
|
+
}
|
|
6310
6570
|
|
|
6571
|
+
const signers = signersOrOptions;
|
|
6311
6572
|
|
|
6312
|
-
async sendTransaction(transaction, signers, options) {
|
|
6313
6573
|
if (transaction.nonceInfo) {
|
|
6314
6574
|
transaction.sign(...signers);
|
|
6315
6575
|
} else {
|
|
@@ -9336,5 +9596,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9336
9596
|
|
|
9337
9597
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9338
9598
|
|
|
9339
|
-
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 };
|
|
9599
|
+
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 };
|
|
9340
9600
|
//# sourceMappingURL=index.esm.js.map
|