@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.cjs.js
CHANGED
|
@@ -645,6 +645,129 @@ 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
|
+
|
|
763
|
+
/**
|
|
764
|
+
* An instruction to execute by a program
|
|
765
|
+
*
|
|
766
|
+
* @property {number} programIdIndex
|
|
767
|
+
* @property {number[]} accounts
|
|
768
|
+
* @property {string} data
|
|
769
|
+
*/
|
|
770
|
+
|
|
648
771
|
/**
|
|
649
772
|
* List of instructions to be processed atomically
|
|
650
773
|
*/
|
|
@@ -682,6 +805,27 @@ class Message {
|
|
|
682
805
|
return [];
|
|
683
806
|
}
|
|
684
807
|
|
|
808
|
+
getAccountKeys() {
|
|
809
|
+
return new MessageAccountKeys(this.staticAccountKeys);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
static compile(args) {
|
|
813
|
+
const compiledKeys = CompiledKeys.compile(args.instructions, args.payerKey);
|
|
814
|
+
const [header, staticAccountKeys] = compiledKeys.getMessageComponents();
|
|
815
|
+
const accountKeys = new MessageAccountKeys(staticAccountKeys);
|
|
816
|
+
const instructions = accountKeys.compileInstructions(args.instructions).map(ix => ({
|
|
817
|
+
programIdIndex: ix.programIdIndex,
|
|
818
|
+
accounts: ix.accountKeyIndexes,
|
|
819
|
+
data: bs58__default["default"].encode(ix.data)
|
|
820
|
+
}));
|
|
821
|
+
return new Message({
|
|
822
|
+
header,
|
|
823
|
+
accountKeys: staticAccountKeys,
|
|
824
|
+
recentBlockhash: args.recentBlockhash,
|
|
825
|
+
instructions
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
|
|
685
829
|
isAccountSigner(index) {
|
|
686
830
|
return index < this.header.numRequiredSignatures;
|
|
687
831
|
}
|
|
@@ -771,7 +915,7 @@ class Message {
|
|
|
771
915
|
for (let i = 0; i < accountCount; i++) {
|
|
772
916
|
const account = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
773
917
|
byteArray = byteArray.slice(PUBLIC_KEY_LENGTH);
|
|
774
|
-
accountKeys.push(
|
|
918
|
+
accountKeys.push(new PublicKey(buffer.Buffer.from(account)));
|
|
775
919
|
}
|
|
776
920
|
|
|
777
921
|
const recentBlockhash = byteArray.slice(0, PUBLIC_KEY_LENGTH);
|
|
@@ -810,141 +954,87 @@ class Message {
|
|
|
810
954
|
|
|
811
955
|
}
|
|
812
956
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
}
|
|
957
|
+
/**
|
|
958
|
+
* Message constructor arguments
|
|
959
|
+
*/
|
|
818
960
|
|
|
819
|
-
class
|
|
820
|
-
constructor(
|
|
821
|
-
this.
|
|
822
|
-
this.
|
|
823
|
-
this.
|
|
824
|
-
this.
|
|
961
|
+
class MessageV0 {
|
|
962
|
+
constructor(args) {
|
|
963
|
+
this.header = void 0;
|
|
964
|
+
this.staticAccountKeys = void 0;
|
|
965
|
+
this.recentBlockhash = void 0;
|
|
966
|
+
this.compiledInstructions = void 0;
|
|
967
|
+
this.addressTableLookups = void 0;
|
|
968
|
+
this.header = args.header;
|
|
969
|
+
this.staticAccountKeys = args.staticAccountKeys;
|
|
970
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
971
|
+
this.compiledInstructions = args.compiledInstructions;
|
|
972
|
+
this.addressTableLookups = args.addressTableLookups;
|
|
825
973
|
}
|
|
826
974
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
const getOrInsertDefault = pubkey => {
|
|
831
|
-
const address = pubkey.toBase58();
|
|
832
|
-
let keyMeta = keyMetaMap.get(address);
|
|
833
|
-
|
|
834
|
-
if (keyMeta === undefined) {
|
|
835
|
-
keyMeta = {
|
|
836
|
-
isSigner: false,
|
|
837
|
-
isWritable: false,
|
|
838
|
-
isInvoked: false
|
|
839
|
-
};
|
|
840
|
-
keyMetaMap.set(address, keyMeta);
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
return keyMeta;
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
const payerKeyMeta = getOrInsertDefault(payer);
|
|
847
|
-
payerKeyMeta.isSigner = true;
|
|
848
|
-
payerKeyMeta.isWritable = true;
|
|
975
|
+
get version() {
|
|
976
|
+
return 0;
|
|
977
|
+
}
|
|
849
978
|
|
|
850
|
-
|
|
851
|
-
|
|
979
|
+
get numAccountKeysFromLookups() {
|
|
980
|
+
let count = 0;
|
|
852
981
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
keyMeta.isSigner || (keyMeta.isSigner = accountMeta.isSigner);
|
|
856
|
-
keyMeta.isWritable || (keyMeta.isWritable = accountMeta.isWritable);
|
|
857
|
-
}
|
|
982
|
+
for (const lookup of this.addressTableLookups) {
|
|
983
|
+
count += lookup.readonlyIndexes.length + lookup.writableIndexes.length;
|
|
858
984
|
}
|
|
859
985
|
|
|
860
|
-
return
|
|
986
|
+
return count;
|
|
861
987
|
}
|
|
862
988
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
assert(mapEntries.length <= 256, 'Max static account keys length exceeded');
|
|
866
|
-
const writableSigners = mapEntries.filter(([, meta]) => meta.isSigner && meta.isWritable);
|
|
867
|
-
const readonlySigners = mapEntries.filter(([, meta]) => meta.isSigner && !meta.isWritable);
|
|
868
|
-
const writableNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && meta.isWritable);
|
|
869
|
-
const readonlyNonSigners = mapEntries.filter(([, meta]) => !meta.isSigner && !meta.isWritable);
|
|
870
|
-
const header = {
|
|
871
|
-
numRequiredSignatures: writableSigners.length + readonlySigners.length,
|
|
872
|
-
numReadonlySignedAccounts: readonlySigners.length,
|
|
873
|
-
numReadonlyUnsignedAccounts: readonlyNonSigners.length
|
|
874
|
-
}; // sanity checks
|
|
875
|
-
|
|
876
|
-
{
|
|
877
|
-
assert(writableSigners.length > 0, 'Expected at least one writable signer key');
|
|
878
|
-
const [payerAddress] = writableSigners[0];
|
|
879
|
-
assert(payerAddress === this.payer.toBase58(), 'Expected first writable signer key to be the fee payer');
|
|
880
|
-
}
|
|
881
|
-
const staticAccountKeys = [...writableSigners.map(([address]) => new PublicKey(address)), ...readonlySigners.map(([address]) => new PublicKey(address)), ...writableNonSigners.map(([address]) => new PublicKey(address)), ...readonlyNonSigners.map(([address]) => new PublicKey(address))];
|
|
882
|
-
return [header, staticAccountKeys];
|
|
883
|
-
}
|
|
989
|
+
getAccountKeys(args) {
|
|
990
|
+
let accountKeysFromLookups;
|
|
884
991
|
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
992
|
+
if (args && 'accountKeysFromLookups' in args) {
|
|
993
|
+
if (this.numAccountKeysFromLookups != args.accountKeysFromLookups.writable.length + args.accountKeysFromLookups.readonly.length) {
|
|
994
|
+
throw new Error('Failed to get account keys because of a mismatch in the number of account keys from lookups');
|
|
995
|
+
}
|
|
888
996
|
|
|
889
|
-
|
|
890
|
-
|
|
997
|
+
accountKeysFromLookups = args.accountKeysFromLookups;
|
|
998
|
+
} else if (args && 'addressLookupTableAccounts' in args) {
|
|
999
|
+
accountKeysFromLookups = this.resolveAddressTableLookups(args.addressLookupTableAccounts);
|
|
1000
|
+
} else if (this.addressTableLookups.length > 0) {
|
|
1001
|
+
throw new Error('Failed to get account keys because address table lookups were not resolved');
|
|
891
1002
|
}
|
|
892
1003
|
|
|
893
|
-
return
|
|
894
|
-
accountKey: lookupTable.key,
|
|
895
|
-
writableIndexes,
|
|
896
|
-
readonlyIndexes
|
|
897
|
-
}, {
|
|
898
|
-
writable: drainedWritableKeys,
|
|
899
|
-
readonly: drainedReadonlyKeys
|
|
900
|
-
}];
|
|
1004
|
+
return new MessageAccountKeys(this.staticAccountKeys, accountKeysFromLookups);
|
|
901
1005
|
}
|
|
902
|
-
/** @internal */
|
|
903
1006
|
|
|
1007
|
+
resolveAddressTableLookups(addressLookupTableAccounts) {
|
|
1008
|
+
const accountKeysFromLookups = {
|
|
1009
|
+
writable: [],
|
|
1010
|
+
readonly: []
|
|
1011
|
+
};
|
|
904
1012
|
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
const drainedKeys = new Array();
|
|
1013
|
+
for (const tableLookup of this.addressTableLookups) {
|
|
1014
|
+
const tableAccount = addressLookupTableAccounts.find(account => account.key.equals(tableLookup.accountKey));
|
|
908
1015
|
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
const lookupTableIndex = lookupTableEntries.findIndex(entry => entry.equals(key));
|
|
1016
|
+
if (!tableAccount) {
|
|
1017
|
+
throw new Error(`Failed to find address lookup table account for table key ${tableLookup.accountKey.toBase58()}`);
|
|
1018
|
+
}
|
|
913
1019
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
1020
|
+
for (const index of tableLookup.writableIndexes) {
|
|
1021
|
+
if (index < tableAccount.state.addresses.length) {
|
|
1022
|
+
accountKeysFromLookups.writable.push(tableAccount.state.addresses[index]);
|
|
1023
|
+
} else {
|
|
1024
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
919
1025
|
}
|
|
920
1026
|
}
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
return [lookupTableIndexes, drainedKeys];
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
/**
|
|
929
|
-
* Message constructor arguments
|
|
930
|
-
*/
|
|
931
1027
|
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
this.staticAccountKeys = args.staticAccountKeys;
|
|
941
|
-
this.recentBlockhash = args.recentBlockhash;
|
|
942
|
-
this.compiledInstructions = args.compiledInstructions;
|
|
943
|
-
this.addressTableLookups = args.addressTableLookups;
|
|
944
|
-
}
|
|
1028
|
+
for (const index of tableLookup.readonlyIndexes) {
|
|
1029
|
+
if (index < tableAccount.state.addresses.length) {
|
|
1030
|
+
accountKeysFromLookups.readonly.push(tableAccount.state.addresses[index]);
|
|
1031
|
+
} else {
|
|
1032
|
+
throw new Error(`Failed to find address for index ${index} in address lookup table ${tableLookup.accountKey.toBase58()}`);
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
945
1036
|
|
|
946
|
-
|
|
947
|
-
return 0;
|
|
1037
|
+
return accountKeysFromLookups;
|
|
948
1038
|
}
|
|
949
1039
|
|
|
950
1040
|
static compile(args) {
|
|
@@ -1876,6 +1966,114 @@ class Transaction {
|
|
|
1876
1966
|
|
|
1877
1967
|
}
|
|
1878
1968
|
|
|
1969
|
+
class TransactionMessage {
|
|
1970
|
+
constructor(args) {
|
|
1971
|
+
this.accountKeys = void 0;
|
|
1972
|
+
this.instructions = void 0;
|
|
1973
|
+
this.recentBlockhash = void 0;
|
|
1974
|
+
this.accountKeys = args.accountKeys;
|
|
1975
|
+
this.instructions = args.instructions;
|
|
1976
|
+
this.recentBlockhash = args.recentBlockhash;
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
static decompile(message, args) {
|
|
1980
|
+
const {
|
|
1981
|
+
header,
|
|
1982
|
+
compiledInstructions,
|
|
1983
|
+
recentBlockhash
|
|
1984
|
+
} = message;
|
|
1985
|
+
const {
|
|
1986
|
+
numRequiredSignatures,
|
|
1987
|
+
numReadonlySignedAccounts,
|
|
1988
|
+
numReadonlyUnsignedAccounts
|
|
1989
|
+
} = header;
|
|
1990
|
+
const numWritableSignedAccounts = numRequiredSignatures - numReadonlySignedAccounts;
|
|
1991
|
+
assert(numWritableSignedAccounts > 0, 'Message header is invalid');
|
|
1992
|
+
const numWritableUnsignedAccounts = message.staticAccountKeys.length - numReadonlyUnsignedAccounts;
|
|
1993
|
+
assert(numWritableUnsignedAccounts >= 0, 'Message header is invalid');
|
|
1994
|
+
const accountKeys = message.getAccountKeys(args);
|
|
1995
|
+
const instructions = [];
|
|
1996
|
+
|
|
1997
|
+
for (const compiledIx of compiledInstructions) {
|
|
1998
|
+
const keys = [];
|
|
1999
|
+
|
|
2000
|
+
for (const keyIndex of compiledIx.accountKeyIndexes) {
|
|
2001
|
+
const pubkey = accountKeys.get(keyIndex);
|
|
2002
|
+
|
|
2003
|
+
if (pubkey === undefined) {
|
|
2004
|
+
throw new Error(`Failed to find key for account key index ${keyIndex}`);
|
|
2005
|
+
}
|
|
2006
|
+
|
|
2007
|
+
const isSigner = keyIndex < numRequiredSignatures;
|
|
2008
|
+
let isWritable;
|
|
2009
|
+
|
|
2010
|
+
if (isSigner) {
|
|
2011
|
+
isWritable = keyIndex < numWritableSignedAccounts;
|
|
2012
|
+
} else if (keyIndex < accountKeys.staticAccountKeys.length) {
|
|
2013
|
+
isWritable = keyIndex - numRequiredSignatures < numWritableUnsignedAccounts;
|
|
2014
|
+
} else {
|
|
2015
|
+
isWritable = keyIndex - accountKeys.staticAccountKeys.length < // accountKeysFromLookups cannot be undefined because we already found a pubkey for this index above
|
|
2016
|
+
accountKeys.accountKeysFromLookups.writable.length;
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
keys.push({
|
|
2020
|
+
pubkey,
|
|
2021
|
+
isSigner: keyIndex < header.numRequiredSignatures,
|
|
2022
|
+
isWritable
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
const programId = accountKeys.get(compiledIx.programIdIndex);
|
|
2027
|
+
|
|
2028
|
+
if (programId === undefined) {
|
|
2029
|
+
throw new Error(`Failed to find program id for program id index ${compiledIx.programIdIndex}`);
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
instructions.push(new TransactionInstruction({
|
|
2033
|
+
programId,
|
|
2034
|
+
data: toBuffer(compiledIx.data),
|
|
2035
|
+
keys
|
|
2036
|
+
}));
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
return new TransactionMessage({
|
|
2040
|
+
accountKeys,
|
|
2041
|
+
instructions,
|
|
2042
|
+
recentBlockhash
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
compileToLegacyMessage() {
|
|
2047
|
+
const payerKey = this.accountKeys.get(0);
|
|
2048
|
+
|
|
2049
|
+
if (payerKey === undefined) {
|
|
2050
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
return Message.compile({
|
|
2054
|
+
payerKey,
|
|
2055
|
+
recentBlockhash: this.recentBlockhash,
|
|
2056
|
+
instructions: this.instructions
|
|
2057
|
+
});
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
compileToV0Message(addressLookupTableAccounts) {
|
|
2061
|
+
const payerKey = this.accountKeys.get(0);
|
|
2062
|
+
|
|
2063
|
+
if (payerKey === undefined) {
|
|
2064
|
+
throw new Error('Failed to compile message because no account keys were found');
|
|
2065
|
+
}
|
|
2066
|
+
|
|
2067
|
+
return MessageV0.compile({
|
|
2068
|
+
payerKey,
|
|
2069
|
+
recentBlockhash: this.recentBlockhash,
|
|
2070
|
+
instructions: this.instructions,
|
|
2071
|
+
addressLookupTableAccounts
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
}
|
|
2076
|
+
|
|
1879
2077
|
/**
|
|
1880
2078
|
* Versioned transaction class
|
|
1881
2079
|
*/
|
|
@@ -6239,10 +6437,44 @@ class Connection {
|
|
|
6239
6437
|
}
|
|
6240
6438
|
/**
|
|
6241
6439
|
* Simulate a transaction
|
|
6440
|
+
*
|
|
6441
|
+
* @deprecated Instead, call {@link simulateTransaction} with {@link
|
|
6442
|
+
* VersionedTransaction} and {@link SimulateTransactionConfig} parameters
|
|
6242
6443
|
*/
|
|
6243
6444
|
|
|
6244
6445
|
|
|
6245
|
-
|
|
6446
|
+
/**
|
|
6447
|
+
* Simulate a transaction
|
|
6448
|
+
*/
|
|
6449
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6450
|
+
async simulateTransaction(transactionOrMessage, configOrSigners, includeAccounts) {
|
|
6451
|
+
if ('message' in transactionOrMessage) {
|
|
6452
|
+
const versionedTx = transactionOrMessage;
|
|
6453
|
+
const wireTransaction = versionedTx.serialize();
|
|
6454
|
+
const encodedTransaction = buffer.Buffer.from(wireTransaction).toString('base64');
|
|
6455
|
+
|
|
6456
|
+
if (Array.isArray(configOrSigners) || includeAccounts !== undefined) {
|
|
6457
|
+
throw new Error('Invalid arguments');
|
|
6458
|
+
}
|
|
6459
|
+
|
|
6460
|
+
const config = configOrSigners || {};
|
|
6461
|
+
config.encoding = 'base64';
|
|
6462
|
+
|
|
6463
|
+
if (!('commitment' in config)) {
|
|
6464
|
+
config.commitment = this.commitment;
|
|
6465
|
+
}
|
|
6466
|
+
|
|
6467
|
+
const args = [encodedTransaction, config];
|
|
6468
|
+
const unsafeRes = await this._rpcRequest('simulateTransaction', args);
|
|
6469
|
+
const res = superstruct.create(unsafeRes, SimulatedTransactionResponseStruct);
|
|
6470
|
+
|
|
6471
|
+
if ('error' in res) {
|
|
6472
|
+
throw new Error('failed to simulate transaction: ' + res.error.message);
|
|
6473
|
+
}
|
|
6474
|
+
|
|
6475
|
+
return res.result;
|
|
6476
|
+
}
|
|
6477
|
+
|
|
6246
6478
|
let transaction;
|
|
6247
6479
|
|
|
6248
6480
|
if (transactionOrMessage instanceof Transaction) {
|
|
@@ -6258,6 +6490,12 @@ class Connection {
|
|
|
6258
6490
|
transaction._message = transaction._json = undefined;
|
|
6259
6491
|
}
|
|
6260
6492
|
|
|
6493
|
+
if (configOrSigners !== undefined && !Array.isArray(configOrSigners)) {
|
|
6494
|
+
throw new Error('Invalid arguments');
|
|
6495
|
+
}
|
|
6496
|
+
|
|
6497
|
+
const signers = configOrSigners;
|
|
6498
|
+
|
|
6261
6499
|
if (transaction.nonceInfo && signers) {
|
|
6262
6500
|
transaction.sign(...signers);
|
|
6263
6501
|
} else {
|
|
@@ -6338,12 +6576,34 @@ class Connection {
|
|
|
6338
6576
|
|
|
6339
6577
|
return res.result;
|
|
6340
6578
|
}
|
|
6579
|
+
/**
|
|
6580
|
+
* Sign and send a transaction
|
|
6581
|
+
*
|
|
6582
|
+
* @deprecated Instead, call {@link sendTransaction} with a {@link
|
|
6583
|
+
* VersionedTransaction}
|
|
6584
|
+
*/
|
|
6585
|
+
|
|
6586
|
+
|
|
6341
6587
|
/**
|
|
6342
6588
|
* Sign and send a transaction
|
|
6343
6589
|
*/
|
|
6590
|
+
// eslint-disable-next-line no-dupe-class-members
|
|
6591
|
+
async sendTransaction(transaction, signersOrOptions, options) {
|
|
6592
|
+
if ('message' in transaction) {
|
|
6593
|
+
if (signersOrOptions && Array.isArray(signersOrOptions)) {
|
|
6594
|
+
throw new Error('Invalid arguments');
|
|
6595
|
+
}
|
|
6596
|
+
|
|
6597
|
+
const wireTransaction = transaction.serialize();
|
|
6598
|
+
return await this.sendRawTransaction(wireTransaction, options);
|
|
6599
|
+
}
|
|
6600
|
+
|
|
6601
|
+
if (signersOrOptions === undefined || !Array.isArray(signersOrOptions)) {
|
|
6602
|
+
throw new Error('Invalid arguments');
|
|
6603
|
+
}
|
|
6344
6604
|
|
|
6605
|
+
const signers = signersOrOptions;
|
|
6345
6606
|
|
|
6346
|
-
async sendTransaction(transaction, signers, options) {
|
|
6347
6607
|
if (transaction.nonceInfo) {
|
|
6348
6608
|
transaction.sign(...signers);
|
|
6349
6609
|
} else {
|
|
@@ -9429,6 +9689,7 @@ exports.Transaction = Transaction;
|
|
|
9429
9689
|
exports.TransactionExpiredBlockheightExceededError = TransactionExpiredBlockheightExceededError;
|
|
9430
9690
|
exports.TransactionExpiredTimeoutError = TransactionExpiredTimeoutError;
|
|
9431
9691
|
exports.TransactionInstruction = TransactionInstruction;
|
|
9692
|
+
exports.TransactionMessage = TransactionMessage;
|
|
9432
9693
|
exports.VALIDATOR_INFO_KEY = VALIDATOR_INFO_KEY;
|
|
9433
9694
|
exports.VERSION_PREFIX_MASK = VERSION_PREFIX_MASK;
|
|
9434
9695
|
exports.VOTE_PROGRAM_ID = VOTE_PROGRAM_ID;
|