@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.browser.esm.js
CHANGED
|
@@ -608,6 +608,129 @@ 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
|
+
|
|
726
|
+
/**
|
|
727
|
+
* An instruction to execute by a program
|
|
728
|
+
*
|
|
729
|
+
* @property {number} programIdIndex
|
|
730
|
+
* @property {number[]} accounts
|
|
731
|
+
* @property {string} data
|
|
732
|
+
*/
|
|
733
|
+
|
|
611
734
|
/**
|
|
612
735
|
* List of instructions to be processed atomically
|
|
613
736
|
*/
|
|
@@ -645,6 +768,27 @@ class Message {
|
|
|
645
768
|
return [];
|
|
646
769
|
}
|
|
647
770
|
|
|
771
|
+
getAccountKeys() {
|
|
772
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
static compile(args) {
|
|
776
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
777
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
778
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
779
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
780
|
+
programIdIndex: ix.programIdIndex,
|
|
781
|
+
accounts: ix.accountKeyIndexes,
|
|
782
|
+
data: bs58.encode(ix.data)
|
|
783
|
+
}));
|
|
784
|
+
return new Message({
|
|
785
|
+
header,
|
|
786
|
+
accountKeys: staticAccountKeys,
|
|
787
|
+
recentBlockhash: args.recentBlockhash,
|
|
788
|
+
instructions
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
|
|
648
792
|
isAccountSigner(index) {
|
|
649
793
|
return index < this.header.numRequiredSignatures;
|
|
650
794
|
}
|
|
@@ -734,7 +878,7 @@ class Message {
|
|
|
734
878
|
for (let i = 0; i < accountCount; i++) {
|
|
735
879
|
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
736
880
|
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
737
|
-
accountKeys.push(
|
|
881
|
+
accountKeys.push(new PublicKey(Buffer.from(account)));
|
|
738
882
|
}
|
|
739
883
|
|
|
740
884
|
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
@@ -773,141 +917,87 @@ class Message {
|
|
|
773
917
|
|
|
774
918
|
}
|
|
775
919
|
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
}
|
|
780
|
-
}
|
|
920
|
+
/**
|
|
921
|
+
* Message constructor arguments
|
|
922
|
+
*/
|
|
781
923
|
|
|
782
|
-
class
|
|
783
|
-
constructor(
|
|
784
|
-
this.
|
|
785
|
-
this.
|
|
786
|
-
this.
|
|
787
|
-
this.
|
|
924
|
+
class MessageV0 {
|
|
925
|
+
constructor(args) {
|
|
926
|
+
this.header = void 0;
|
|
927
|
+
this.staticAccountKeys = void 0;
|
|
928
|
+
this.recentBlockhash = void 0;
|
|
929
|
+
this.compiledInstructions = void 0;
|
|
930
|
+
this.addressTableLookups = void 0;
|
|
931
|
+
this.header = args.header;
|
|
932
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
933
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
934
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
935
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
788
936
|
}
|
|
789
937
|
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
const getOrInsertDefault = pubkey => {
|
|
794
|
-
const address = pubkey.toBase58();
|
|
795
|
-
let keyMeta = keyMetaMap.get(address);
|
|
796
|
-
|
|
797
|
-
if (keyMeta === undefined) {
|
|
798
|
-
keyMeta = {
|
|
799
|
-
isSigner: false,
|
|
800
|
-
isWritable: false,
|
|
801
|
-
isInvoked: false
|
|
802
|
-
};
|
|
803
|
-
keyMetaMap.set(address, keyMeta);
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
return keyMeta;
|
|
807
|
-
};
|
|
808
|
-
|
|
809
|
-
const payerKeyMeta = getOrInsertDefault(payer);
|
|
810
|
-
payerKeyMeta.isSigner = true;
|
|
811
|
-
payerKeyMeta.isWritable = true;
|
|
938
|
+
get version() {
|
|
939
|
+
return 0;
|
|
940
|
+
}
|
|
812
941
|
|
|
813
|
-
|
|
814
|
-
|
|
942
|
+
get numAccountKeysFromLookups() {
|
|
943
|
+
let count = 0;
|
|
815
944
|
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
819
|
-
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
820
|
-
}
|
|
945
|
+
for (const lookup of this.addressTableLookups) {
|
|
946
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
821
947
|
}
|
|
822
948
|
|
|
823
|
-
return
|
|
949
|
+
return count;
|
|
824
950
|
}
|
|
825
951
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
829
|
-
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
830
|
-
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
831
|
-
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
832
|
-
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
833
|
-
const header = {
|
|
834
|
-
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
835
|
-
numReadonlySignedAccounts: readonlySigners.length,
|
|
836
|
-
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
837
|
-
}; // sanity checks
|
|
838
|
-
|
|
839
|
-
{
|
|
840
|
-
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
841
|
-
const [payerAddress] = writableSigners[0];
|
|
842
|
-
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
843
|
-
}
|
|
844
|
-
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))];
|
|
845
|
-
return [header, staticAccountKeys];
|
|
846
|
-
}
|
|
952
|
+
getAccountKeys(args) {
|
|
953
|
+
let accountKeysFromLookups;
|
|
847
954
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
955
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
956
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
957
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
958
|
+
}
|
|
851
959
|
|
|
852
|
-
|
|
853
|
-
|
|
960
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
961
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
962
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
963
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
964
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
854
965
|
}
|
|
855
966
|
|
|
856
|
-
return
|
|
857
|
-
accountKey: lookupTable.key,
|
|
858
|
-
writableIndexes,
|
|
859
|
-
readonlyIndexes
|
|
860
|
-
}, {
|
|
861
|
-
writable: drainedWritableKeys,
|
|
862
|
-
readonly: drainedReadonlyKeys
|
|
863
|
-
}];
|
|
967
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
864
968
|
}
|
|
865
|
-
/** @internal */
|
|
866
969
|
|
|
970
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
971
|
+
const accountKeysFromLookups = {
|
|
972
|
+
writable: [],
|
|
973
|
+
readonly: []
|
|
974
|
+
};
|
|
867
975
|
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
const drainedKeys = new Array();
|
|
976
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
977
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
871
978
|
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
979
|
+
if (!tableAccount) {
|
|
980
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
981
|
+
}
|
|
876
982
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
983
|
+
for (const index of tableLookup.writableIndexes) {
|
|
984
|
+
if (index < tableAccount.state.addresses.length) {
|
|
985
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
986
|
+
} else {
|
|
987
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
882
988
|
}
|
|
883
989
|
}
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
return [lookupTableIndexes, drainedKeys];
|
|
887
|
-
}
|
|
888
|
-
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
/**
|
|
892
|
-
* Message constructor arguments
|
|
893
|
-
*/
|
|
894
990
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
this.staticAccountKeys = args.staticAccountKeys;
|
|
904
|
-
this.recentBlockhash = args.recentBlockhash;
|
|
905
|
-
this.compiledInstructions = args.compiledInstructions;
|
|
906
|
-
this.addressTableLookups = args.addressTableLookups;
|
|
907
|
-
}
|
|
991
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
992
|
+
if (index < tableAccount.state.addresses.length) {
|
|
993
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
994
|
+
} else {
|
|
995
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
908
999
|
|
|
909
|
-
|
|
910
|
-
return 0;
|
|
1000
|
+
return accountKeysFromLookups;
|
|
911
1001
|
}
|
|
912
1002
|
|
|
913
1003
|
static compile(args) {
|
|
@@ -1839,6 +1929,114 @@ class Transaction {
|
|
|
1839
1929
|
|
|
1840
1930
|
}
|
|
1841
1931
|
|
|
1932
|
+
class TransactionMessage {
|
|
1933
|
+
constructor(args) {
|
|
1934
|
+
this.accountKeys = void 0;
|
|
1935
|
+
this.instructions = void 0;
|
|
1936
|
+
this.recentBlockhash = void 0;
|
|
1937
|
+
this.accountKeys = args.accountKeys;
|
|
1938
|
+
this.instructions = args.instructions;
|
|
1939
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
static decompile(message, args) {
|
|
1943
|
+
const {
|
|
1944
|
+
header,
|
|
1945
|
+
compiledInstructions,
|
|
1946
|
+
recentBlockhash
|
|
1947
|
+
} = message;
|
|
1948
|
+
const {
|
|
1949
|
+
numRequiredSignatures,
|
|
1950
|
+
numReadonlySignedAccounts,
|
|
1951
|
+
numReadonlyUnsignedAccounts
|
|
1952
|
+
} = header;
|
|
1953
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
1954
|
+
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
1955
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1956
|
+
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1957
|
+
const accountKeys = message.getAccountKeys(args);
|
|
1958
|
+
const instructions = [];
|
|
1959
|
+
|
|
1960
|
+
for (const compiledIx of compiledInstructions) {
|
|
1961
|
+
const keys = [];
|
|
1962
|
+
|
|
1963
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
1964
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
1965
|
+
|
|
1966
|
+
if (pubkey === undefined) {
|
|
1967
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
1971
|
+
let isWritable;
|
|
1972
|
+
|
|
1973
|
+
if (isSigner) {
|
|
1974
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
1975
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
1976
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
1977
|
+
} else {
|
|
1978
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
1979
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
keys.push({
|
|
1983
|
+
pubkey,
|
|
1984
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
1985
|
+
isWritable
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
1990
|
+
|
|
1991
|
+
if (programId === undefined) {
|
|
1992
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
1993
|
+
}
|
|
1994
|
+
|
|
1995
|
+
instructions.push(new TransactionInstruction({
|
|
1996
|
+
programId,
|
|
1997
|
+
data: toBuffer(compiledIx.data),
|
|
1998
|
+
keys
|
|
1999
|
+
}));
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
return new TransactionMessage({
|
|
2003
|
+
accountKeys,
|
|
2004
|
+
instructions,
|
|
2005
|
+
recentBlockhash
|
|
2006
|
+
});
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
compileToLegacyMessage() {
|
|
2010
|
+
const payerKey = this.accountKeys.get(0);
|
|
2011
|
+
|
|
2012
|
+
if (payerKey === undefined) {
|
|
2013
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
return Message.compile({
|
|
2017
|
+
payerKey,
|
|
2018
|
+
recentBlockhash: this.recentBlockhash,
|
|
2019
|
+
instructions: this.instructions
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
2024
|
+
const payerKey = this.accountKeys.get(0);
|
|
2025
|
+
|
|
2026
|
+
if (payerKey === undefined) {
|
|
2027
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
return MessageV0.compile({
|
|
2031
|
+
payerKey,
|
|
2032
|
+
recentBlockhash: this.recentBlockhash,
|
|
2033
|
+
instructions: this.instructions,
|
|
2034
|
+
addressLookupTableAccounts
|
|
2035
|
+
});
|
|
2036
|
+
}
|
|
2037
|
+
|
|
2038
|
+
}
|
|
2039
|
+
|
|
1842
2040
|
/**
|
|
1843
2041
|
* Versioned transaction class
|
|
1844
2042
|
*/
|
|
@@ -6142,10 +6340,44 @@ class Connection {
|
|
|
6142
6340
|
}
|
|
6143
6341
|
/**
|
|
6144
6342
|
* Simulate a transaction
|
|
6343
|
+
*
|
|
6344
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
6345
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
6145
6346
|
*/
|
|
6146
6347
|
|
|
6147
6348
|
|
|
6148
|
-
|
|
6349
|
+
/**
|
|
6350
|
+
* Simulate a transaction
|
|
6351
|
+
*/
|
|
6352
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6353
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
6354
|
+
if ('message' in transactionOrMessage) {
|
|
6355
|
+
const versionedTx = transactionOrMessage;
|
|
6356
|
+
const wireTransaction = versionedTx.serialize();
|
|
6357
|
+
const encodedTransaction = Buffer.from(wireTransaction).toString('base64');
|
|
6358
|
+
|
|
6359
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
6360
|
+
throw new Error('Invalid arguments');
|
|
6361
|
+
}
|
|
6362
|
+
|
|
6363
|
+
const config = configOrSigners || {};
|
|
6364
|
+
config.encoding = 'base64';
|
|
6365
|
+
|
|
6366
|
+
if (!('commitment' in config)) {
|
|
6367
|
+
config.commitment = this.commitment;
|
|
6368
|
+
}
|
|
6369
|
+
|
|
6370
|
+
const args = [encodedTransaction, config];
|
|
6371
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
6372
|
+
const res = create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
6373
|
+
|
|
6374
|
+
if ('error' in res) {
|
|
6375
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
6376
|
+
}
|
|
6377
|
+
|
|
6378
|
+
return res.result;
|
|
6379
|
+
}
|
|
6380
|
+
|
|
6149
6381
|
let transaction;
|
|
6150
6382
|
|
|
6151
6383
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -6161,6 +6393,12 @@ class Connection {
|
|
|
6161
6393
|
transaction._message = transaction._json = undefined;
|
|
6162
6394
|
}
|
|
6163
6395
|
|
|
6396
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
6397
|
+
throw new Error('Invalid arguments');
|
|
6398
|
+
}
|
|
6399
|
+
|
|
6400
|
+
const signers = configOrSigners;
|
|
6401
|
+
|
|
6164
6402
|
if (transaction.nonceInfo && signers) {
|
|
6165
6403
|
transaction.sign(...signers);
|
|
6166
6404
|
} else {
|
|
@@ -6241,12 +6479,34 @@ class Connection {
|
|
|
6241
6479
|
|
|
6242
6480
|
return res.result;
|
|
6243
6481
|
}
|
|
6482
|
+
/**
|
|
6483
|
+
* Sign and send a transaction
|
|
6484
|
+
*
|
|
6485
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
6486
|
+
* VersionedTransaction}
|
|
6487
|
+
*/
|
|
6488
|
+
|
|
6489
|
+
|
|
6244
6490
|
/**
|
|
6245
6491
|
* Sign and send a transaction
|
|
6246
6492
|
*/
|
|
6493
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6494
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
6495
|
+
if ('message' in transaction) {
|
|
6496
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
6497
|
+
throw new Error('Invalid arguments');
|
|
6498
|
+
}
|
|
6499
|
+
|
|
6500
|
+
const wireTransaction = transaction.serialize();
|
|
6501
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
6502
|
+
}
|
|
6503
|
+
|
|
6504
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6505
|
+
throw new Error('Invalid arguments');
|
|
6506
|
+
}
|
|
6247
6507
|
|
|
6508
|
+
const signers = signersOrOptions;
|
|
6248
6509
|
|
|
6249
|
-
async sendTransaction(transaction, signers, options) {
|
|
6250
6510
|
if (transaction.nonceInfo) {
|
|
6251
6511
|
transaction.sign(...signers);
|
|
6252
6512
|
} else {
|
|
@@ -9273,5 +9533,5 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
9273
9533
|
|
|
9274
9534
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9275
9535
|
|
|
9276
|
-
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 };
|
|
9536
|
+
export { Account, AddressLookupTableAccount, AddressLookupTableInstruction, AddressLookupTableProgram, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, LOOKUP_TABLE_INSTRUCTION_LAYOUTS, Loader, Lockup, MAX_SEED_LENGTH, Message, MessageAccountKeys, MessageV0, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PUBLIC_KEY_LENGTH, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, SolanaJSONRPCError, SolanaJSONRPCErrorCode, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionExpiredBlockheightExceededError, TransactionExpiredTimeoutError, TransactionInstruction, TransactionMessage, TransactionStatus, VALIDATOR_INFO_KEY, VERSION_PREFIX_MASK, VOTE_PROGRAM_ID, ValidatorInfo, VersionedMessage, VersionedTransaction, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9277
9537
|
//# sourceMappingURL=index.browser.esm.js.map
|