@solana/web3.js 1.31.0 → 1.32.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.esm.js +113 -37
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +115 -36
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +45 -12
- package/lib/index.esm.js +113 -37
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +115 -36
- 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/module.flow.js +57 -13
- package/package.json +5 -10
- package/src/connection.ts +64 -13
- package/src/publickey.ts +4 -0
- package/src/sysvar.ts +16 -4
- package/src/transaction.ts +4 -1
- package/src/vote-account.ts +104 -31
package/lib/index.browser.esm.js
CHANGED
|
@@ -1798,6 +1798,10 @@ class PublicKey extends Struct {
|
|
|
1798
1798
|
toBase58() {
|
|
1799
1799
|
return bs58.encode(this.toBytes());
|
|
1800
1800
|
}
|
|
1801
|
+
|
|
1802
|
+
toJSON() {
|
|
1803
|
+
return this.toBase58();
|
|
1804
|
+
}
|
|
1801
1805
|
/**
|
|
1802
1806
|
* Return the byte array representation of the public key
|
|
1803
1807
|
*/
|
|
@@ -2437,8 +2441,9 @@ class Transaction {
|
|
|
2437
2441
|
}); // Sort. Prioritizing first by signer, then by writable
|
|
2438
2442
|
|
|
2439
2443
|
accountMetas.sort(function (x, y) {
|
|
2444
|
+
const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
|
|
2440
2445
|
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
|
2441
|
-
const checkWritable = x.isWritable === y.isWritable ?
|
|
2446
|
+
const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
|
|
2442
2447
|
return checkSigner || checkWritable;
|
|
2443
2448
|
}); // Cull duplicate account metas
|
|
2444
2449
|
|
|
@@ -2894,11 +2899,14 @@ class Transaction {
|
|
|
2894
2899
|
}
|
|
2895
2900
|
|
|
2896
2901
|
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
2902
|
+
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
2903
|
+
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2897
2904
|
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
2898
2905
|
const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
|
|
2899
2906
|
const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
|
|
2907
|
+
const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
|
|
2908
|
+
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
2900
2909
|
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
2901
|
-
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2902
2910
|
|
|
2903
2911
|
/**
|
|
2904
2912
|
* Sign, send and confirm a transaction.
|
|
@@ -4823,16 +4831,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4823
4831
|
let fetchWithMiddleware;
|
|
4824
4832
|
|
|
4825
4833
|
if (fetchMiddleware) {
|
|
4826
|
-
fetchWithMiddleware = (url, options) => {
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
}
|
|
4834
|
-
});
|
|
4834
|
+
fetchWithMiddleware = async (url, options) => {
|
|
4835
|
+
const modifiedFetchArgs = await new Promise((resolve, reject) => {
|
|
4836
|
+
try {
|
|
4837
|
+
fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
|
|
4838
|
+
} catch (error) {
|
|
4839
|
+
reject(error);
|
|
4840
|
+
}
|
|
4835
4841
|
});
|
|
4842
|
+
return await fetch(...modifiedFetchArgs);
|
|
4836
4843
|
};
|
|
4837
4844
|
}
|
|
4838
4845
|
|
|
@@ -5325,6 +5332,7 @@ const ParsedConfirmedTransactionResult = type({
|
|
|
5325
5332
|
const TokenBalanceResult = type({
|
|
5326
5333
|
accountIndex: number(),
|
|
5327
5334
|
mint: string(),
|
|
5335
|
+
owner: optional(string()),
|
|
5328
5336
|
uiTokenAmount: TokenAmountResult
|
|
5329
5337
|
});
|
|
5330
5338
|
/**
|
|
@@ -5928,13 +5936,25 @@ class Connection {
|
|
|
5928
5936
|
*/
|
|
5929
5937
|
|
|
5930
5938
|
|
|
5931
|
-
async getMultipleAccountsInfo(publicKeys,
|
|
5939
|
+
async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
|
|
5932
5940
|
const keys = publicKeys.map(key => key.toBase58());
|
|
5941
|
+
let commitment;
|
|
5942
|
+
let encoding = 'base64';
|
|
5933
5943
|
|
|
5934
|
-
|
|
5944
|
+
if (configOrCommitment) {
|
|
5945
|
+
if (typeof configOrCommitment === 'string') {
|
|
5946
|
+
commitment = configOrCommitment;
|
|
5947
|
+
encoding = 'base64';
|
|
5948
|
+
} else {
|
|
5949
|
+
commitment = configOrCommitment.commitment;
|
|
5950
|
+
encoding = configOrCommitment.encoding || 'base64';
|
|
5951
|
+
}
|
|
5952
|
+
}
|
|
5953
|
+
|
|
5954
|
+
const args = this._buildArgs([keys], commitment, encoding);
|
|
5935
5955
|
|
|
5936
5956
|
const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
|
|
5937
|
-
const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(
|
|
5957
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
|
|
5938
5958
|
|
|
5939
5959
|
if ('error' in res) {
|
|
5940
5960
|
throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
|
|
@@ -6415,6 +6435,29 @@ class Connection {
|
|
|
6415
6435
|
value: value !== null ? value.feeCalculator : null
|
|
6416
6436
|
};
|
|
6417
6437
|
}
|
|
6438
|
+
/**
|
|
6439
|
+
* Fetch the fee for a message from the cluster, return with context
|
|
6440
|
+
*/
|
|
6441
|
+
|
|
6442
|
+
|
|
6443
|
+
async getFeeForMessage(message, commitment) {
|
|
6444
|
+
const wireMessage = message.serialize().toString('base64');
|
|
6445
|
+
|
|
6446
|
+
const args = this._buildArgs([wireMessage], commitment);
|
|
6447
|
+
|
|
6448
|
+
const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
|
|
6449
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
|
|
6450
|
+
|
|
6451
|
+
if ('error' in res) {
|
|
6452
|
+
throw new Error('failed to get slot: ' + res.error.message);
|
|
6453
|
+
}
|
|
6454
|
+
|
|
6455
|
+
if (res.result === null) {
|
|
6456
|
+
throw new Error('invalid blockhash');
|
|
6457
|
+
}
|
|
6458
|
+
|
|
6459
|
+
return res.result;
|
|
6460
|
+
}
|
|
6418
6461
|
/**
|
|
6419
6462
|
* Fetch a recent blockhash from the cluster
|
|
6420
6463
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
|
@@ -8894,9 +8937,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
|
|
|
8894
8937
|
*
|
|
8895
8938
|
* @internal
|
|
8896
8939
|
*/
|
|
8897
|
-
const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('
|
|
8898
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64(
|
|
8899
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('
|
|
8940
|
+
const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
|
|
8941
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64(), // authorizedVoters.length
|
|
8942
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), publicKey('authorizedVoter')]), BufferLayout.offset(BufferLayout.u32(), -8), 'authorizedVoters'), BufferLayout.struct([BufferLayout.seq(BufferLayout.struct([publicKey('authorizedPubkey'), BufferLayout.nu64('epochOfLastAuthorizedSwitch'), BufferLayout.nu64('targetEpoch')]), 32, 'buf'), BufferLayout.nu64('idx'), BufferLayout.u8('isEmpty')], 'priorVoters'), BufferLayout.nu64(), // epochCredits.length
|
|
8943
|
+
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('credits'), BufferLayout.nu64('prevCredits')]), BufferLayout.offset(BufferLayout.u32(), -8), 'epochCredits'), BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.nu64('timestamp')], 'lastTimestamp')]);
|
|
8900
8944
|
|
|
8901
8945
|
/**
|
|
8902
8946
|
* VoteAccount class
|
|
@@ -8907,25 +8951,23 @@ class VoteAccount {
|
|
|
8907
8951
|
*/
|
|
8908
8952
|
constructor(args) {
|
|
8909
8953
|
this.nodePubkey = void 0;
|
|
8910
|
-
this.
|
|
8911
|
-
this.authorizedWithdrawerPubkey = void 0;
|
|
8954
|
+
this.authorizedWithdrawer = void 0;
|
|
8912
8955
|
this.commission = void 0;
|
|
8913
|
-
this.votes = void 0;
|
|
8914
8956
|
this.rootSlot = void 0;
|
|
8915
|
-
this.
|
|
8916
|
-
this.
|
|
8917
|
-
this.
|
|
8957
|
+
this.votes = void 0;
|
|
8958
|
+
this.authorizedVoters = void 0;
|
|
8959
|
+
this.priorVoters = void 0;
|
|
8918
8960
|
this.epochCredits = void 0;
|
|
8961
|
+
this.lastTimestamp = void 0;
|
|
8919
8962
|
this.nodePubkey = args.nodePubkey;
|
|
8920
|
-
this.
|
|
8921
|
-
this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
|
|
8963
|
+
this.authorizedWithdrawer = args.authorizedWithdrawer;
|
|
8922
8964
|
this.commission = args.commission;
|
|
8923
|
-
this.votes = args.votes;
|
|
8924
8965
|
this.rootSlot = args.rootSlot;
|
|
8925
|
-
this.
|
|
8926
|
-
this.
|
|
8927
|
-
this.
|
|
8966
|
+
this.votes = args.votes;
|
|
8967
|
+
this.authorizedVoters = args.authorizedVoters;
|
|
8968
|
+
this.priorVoters = args.priorVoters;
|
|
8928
8969
|
this.epochCredits = args.epochCredits;
|
|
8970
|
+
this.lastTimestamp = args.lastTimestamp;
|
|
8929
8971
|
}
|
|
8930
8972
|
/**
|
|
8931
8973
|
* Deserialize VoteAccount from the account data.
|
|
@@ -8936,7 +8978,8 @@ class VoteAccount {
|
|
|
8936
8978
|
|
|
8937
8979
|
|
|
8938
8980
|
static fromAccountData(buffer) {
|
|
8939
|
-
const
|
|
8981
|
+
const versionOffset = 4;
|
|
8982
|
+
const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
|
|
8940
8983
|
let rootSlot = va.rootSlot;
|
|
8941
8984
|
|
|
8942
8985
|
if (!va.rootSlotValid) {
|
|
@@ -8945,20 +8988,53 @@ class VoteAccount {
|
|
|
8945
8988
|
|
|
8946
8989
|
return new VoteAccount({
|
|
8947
8990
|
nodePubkey: new PublicKey(va.nodePubkey),
|
|
8948
|
-
|
|
8949
|
-
authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
|
|
8991
|
+
authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
|
|
8950
8992
|
commission: va.commission,
|
|
8951
8993
|
votes: va.votes,
|
|
8952
8994
|
rootSlot,
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
|
|
8956
|
-
|
|
8995
|
+
authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
|
|
8996
|
+
priorVoters: getPriorVoters(va.priorVoters),
|
|
8997
|
+
epochCredits: va.epochCredits,
|
|
8998
|
+
lastTimestamp: va.lastTimestamp
|
|
8957
8999
|
});
|
|
8958
9000
|
}
|
|
8959
9001
|
|
|
8960
9002
|
}
|
|
8961
9003
|
|
|
9004
|
+
function parseAuthorizedVoter({
|
|
9005
|
+
epoch,
|
|
9006
|
+
authorizedVoter
|
|
9007
|
+
}) {
|
|
9008
|
+
return {
|
|
9009
|
+
epoch,
|
|
9010
|
+
authorizedVoter: new PublicKey(authorizedVoter)
|
|
9011
|
+
};
|
|
9012
|
+
}
|
|
9013
|
+
|
|
9014
|
+
function parsePriorVoters({
|
|
9015
|
+
authorizedPubkey,
|
|
9016
|
+
epochOfLastAuthorizedSwitch,
|
|
9017
|
+
targetEpoch
|
|
9018
|
+
}) {
|
|
9019
|
+
return {
|
|
9020
|
+
authorizedPubkey: new PublicKey(authorizedPubkey),
|
|
9021
|
+
epochOfLastAuthorizedSwitch,
|
|
9022
|
+
targetEpoch
|
|
9023
|
+
};
|
|
9024
|
+
}
|
|
9025
|
+
|
|
9026
|
+
function getPriorVoters({
|
|
9027
|
+
buf,
|
|
9028
|
+
idx,
|
|
9029
|
+
isEmpty
|
|
9030
|
+
}) {
|
|
9031
|
+
if (isEmpty) {
|
|
9032
|
+
return [];
|
|
9033
|
+
}
|
|
9034
|
+
|
|
9035
|
+
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
9036
|
+
}
|
|
9037
|
+
|
|
8962
9038
|
/**
|
|
8963
9039
|
* Send and confirm a raw transaction
|
|
8964
9040
|
*
|
|
@@ -9022,5 +9098,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9022
9098
|
|
|
9023
9099
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
9024
9100
|
|
|
9025
|
-
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9101
|
+
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, 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, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
9026
9102
|
//# sourceMappingURL=index.browser.esm.js.map
|