@solana/web3.js 1.30.2 → 1.32.2
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/README.md +2 -2
- package/lib/index.browser.esm.js +338 -77
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +344 -79
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +121 -19
- package/lib/index.esm.js +338 -77
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +346 -79
- 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 +145 -20
- package/package.json +7 -12
- package/src/account.ts +1 -1
- package/src/connection.ts +323 -42
- package/src/keypair.ts +1 -1
- package/src/publickey.ts +4 -0
- package/src/secp256k1-program.ts +5 -5
- package/src/sysvar.ts +16 -4
- package/src/transaction.ts +4 -1
- package/src/util/cluster.ts +2 -2
- package/src/util/send-and-confirm-transaction.ts +1 -0
- package/src/vote-account.ts +104 -31
package/src/sysvar.ts
CHANGED
|
@@ -4,6 +4,14 @@ export const SYSVAR_CLOCK_PUBKEY = new PublicKey(
|
|
|
4
4
|
'SysvarC1ock11111111111111111111111111111111',
|
|
5
5
|
);
|
|
6
6
|
|
|
7
|
+
export const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey(
|
|
8
|
+
'SysvarEpochSchedu1e111111111111111111111111',
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
export const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey(
|
|
12
|
+
'Sysvar1nstructions1111111111111111111111111',
|
|
13
|
+
);
|
|
14
|
+
|
|
7
15
|
export const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey(
|
|
8
16
|
'SysvarRecentB1ockHashes11111111111111111111',
|
|
9
17
|
);
|
|
@@ -16,10 +24,14 @@ export const SYSVAR_REWARDS_PUBKEY = new PublicKey(
|
|
|
16
24
|
'SysvarRewards111111111111111111111111111111',
|
|
17
25
|
);
|
|
18
26
|
|
|
19
|
-
export const
|
|
20
|
-
'
|
|
27
|
+
export const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey(
|
|
28
|
+
'SysvarS1otHashes111111111111111111111111111',
|
|
21
29
|
);
|
|
22
30
|
|
|
23
|
-
export const
|
|
24
|
-
'
|
|
31
|
+
export const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey(
|
|
32
|
+
'SysvarS1otHistory11111111111111111111111111',
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey(
|
|
36
|
+
'SysvarStakeHistory1111111111111111111111111',
|
|
25
37
|
);
|
package/src/transaction.ts
CHANGED
|
@@ -259,9 +259,12 @@ export class Transaction {
|
|
|
259
259
|
|
|
260
260
|
// Sort. Prioritizing first by signer, then by writable
|
|
261
261
|
accountMetas.sort(function (x, y) {
|
|
262
|
+
const pubkeySorting = x.pubkey
|
|
263
|
+
.toBase58()
|
|
264
|
+
.localeCompare(y.pubkey.toBase58());
|
|
262
265
|
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
|
263
266
|
const checkWritable =
|
|
264
|
-
x.isWritable === y.isWritable ?
|
|
267
|
+
x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
|
|
265
268
|
return checkSigner || checkWritable;
|
|
266
269
|
});
|
|
267
270
|
|
package/src/util/cluster.ts
CHANGED
|
@@ -2,12 +2,12 @@ const endpoint = {
|
|
|
2
2
|
http: {
|
|
3
3
|
devnet: 'http://api.devnet.solana.com',
|
|
4
4
|
testnet: 'http://api.testnet.solana.com',
|
|
5
|
-
'mainnet-beta': 'http://api.mainnet-beta.solana.com',
|
|
5
|
+
'mainnet-beta': 'http://api.mainnet-beta.solana.com/',
|
|
6
6
|
},
|
|
7
7
|
https: {
|
|
8
8
|
devnet: 'https://api.devnet.solana.com',
|
|
9
9
|
testnet: 'https://api.testnet.solana.com',
|
|
10
|
-
'mainnet-beta': 'https://api.mainnet-beta.solana.com',
|
|
10
|
+
'mainnet-beta': 'https://api.mainnet-beta.solana.com/',
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
13
|
|
|
@@ -24,6 +24,7 @@ export async function sendAndConfirmTransaction(
|
|
|
24
24
|
const sendOptions = options && {
|
|
25
25
|
skipPreflight: options.skipPreflight,
|
|
26
26
|
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
27
|
+
maxRetries: options.maxRetries,
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
const signature = await connection.sendTransaction(
|
package/src/vote-account.ts
CHANGED
|
@@ -23,6 +23,22 @@ export type EpochCredits = {
|
|
|
23
23
|
prevCredits: number;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
export type AuthorizedVoter = {
|
|
27
|
+
epoch: number;
|
|
28
|
+
authorizedVoter: PublicKey;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type PriorVoter = {
|
|
32
|
+
authorizedPubkey: PublicKey;
|
|
33
|
+
epochOfLastAuthorizedSwitch: number;
|
|
34
|
+
targetEpoch: number;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type BlockTimestamp = {
|
|
38
|
+
slot: number;
|
|
39
|
+
timetamp: number;
|
|
40
|
+
};
|
|
41
|
+
|
|
26
42
|
/**
|
|
27
43
|
* See https://github.com/solana-labs/solana/blob/8a12ed029cfa38d4a45400916c2463fb82bbec8c/programs/vote_api/src/vote_state.rs#L68-L88
|
|
28
44
|
*
|
|
@@ -30,8 +46,7 @@ export type EpochCredits = {
|
|
|
30
46
|
*/
|
|
31
47
|
const VoteAccountLayout = BufferLayout.struct([
|
|
32
48
|
Layout.publicKey('nodePubkey'),
|
|
33
|
-
Layout.publicKey('
|
|
34
|
-
Layout.publicKey('authorizedWithdrawerPubkey'),
|
|
49
|
+
Layout.publicKey('authorizedWithdrawer'),
|
|
35
50
|
BufferLayout.u8('commission'),
|
|
36
51
|
BufferLayout.nu64(), // votes.length
|
|
37
52
|
BufferLayout.seq(
|
|
@@ -44,9 +59,31 @@ const VoteAccountLayout = BufferLayout.struct([
|
|
|
44
59
|
),
|
|
45
60
|
BufferLayout.u8('rootSlotValid'),
|
|
46
61
|
BufferLayout.nu64('rootSlot'),
|
|
47
|
-
BufferLayout.nu64(
|
|
48
|
-
BufferLayout.
|
|
49
|
-
|
|
62
|
+
BufferLayout.nu64(), // authorizedVoters.length
|
|
63
|
+
BufferLayout.seq(
|
|
64
|
+
BufferLayout.struct([
|
|
65
|
+
BufferLayout.nu64('epoch'),
|
|
66
|
+
Layout.publicKey('authorizedVoter'),
|
|
67
|
+
]),
|
|
68
|
+
BufferLayout.offset(BufferLayout.u32(), -8),
|
|
69
|
+
'authorizedVoters',
|
|
70
|
+
),
|
|
71
|
+
BufferLayout.struct(
|
|
72
|
+
[
|
|
73
|
+
BufferLayout.seq(
|
|
74
|
+
BufferLayout.struct([
|
|
75
|
+
Layout.publicKey('authorizedPubkey'),
|
|
76
|
+
BufferLayout.nu64('epochOfLastAuthorizedSwitch'),
|
|
77
|
+
BufferLayout.nu64('targetEpoch'),
|
|
78
|
+
]),
|
|
79
|
+
32,
|
|
80
|
+
'buf',
|
|
81
|
+
),
|
|
82
|
+
BufferLayout.nu64('idx'),
|
|
83
|
+
BufferLayout.u8('isEmpty'),
|
|
84
|
+
],
|
|
85
|
+
'priorVoters',
|
|
86
|
+
),
|
|
50
87
|
BufferLayout.nu64(), // epochCredits.length
|
|
51
88
|
BufferLayout.seq(
|
|
52
89
|
BufferLayout.struct([
|
|
@@ -57,19 +94,22 @@ const VoteAccountLayout = BufferLayout.struct([
|
|
|
57
94
|
BufferLayout.offset(BufferLayout.u32(), -8),
|
|
58
95
|
'epochCredits',
|
|
59
96
|
),
|
|
97
|
+
BufferLayout.struct(
|
|
98
|
+
[BufferLayout.nu64('slot'), BufferLayout.nu64('timestamp')],
|
|
99
|
+
'lastTimestamp',
|
|
100
|
+
),
|
|
60
101
|
]);
|
|
61
102
|
|
|
62
103
|
type VoteAccountArgs = {
|
|
63
104
|
nodePubkey: PublicKey;
|
|
64
|
-
|
|
65
|
-
authorizedWithdrawerPubkey: PublicKey;
|
|
105
|
+
authorizedWithdrawer: PublicKey;
|
|
66
106
|
commission: number;
|
|
67
|
-
votes: Array<Lockout>;
|
|
68
107
|
rootSlot: number | null;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
epochCredits:
|
|
108
|
+
votes: Lockout[];
|
|
109
|
+
authorizedVoters: AuthorizedVoter[];
|
|
110
|
+
priorVoters: PriorVoter[];
|
|
111
|
+
epochCredits: EpochCredits[];
|
|
112
|
+
lastTimestamp: BlockTimestamp;
|
|
73
113
|
};
|
|
74
114
|
|
|
75
115
|
/**
|
|
@@ -77,30 +117,28 @@ type VoteAccountArgs = {
|
|
|
77
117
|
*/
|
|
78
118
|
export class VoteAccount {
|
|
79
119
|
nodePubkey: PublicKey;
|
|
80
|
-
|
|
81
|
-
authorizedWithdrawerPubkey: PublicKey;
|
|
120
|
+
authorizedWithdrawer: PublicKey;
|
|
82
121
|
commission: number;
|
|
83
|
-
votes: Array<Lockout>;
|
|
84
122
|
rootSlot: number | null;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
epochCredits:
|
|
123
|
+
votes: Lockout[];
|
|
124
|
+
authorizedVoters: AuthorizedVoter[];
|
|
125
|
+
priorVoters: PriorVoter[];
|
|
126
|
+
epochCredits: EpochCredits[];
|
|
127
|
+
lastTimestamp: BlockTimestamp;
|
|
89
128
|
|
|
90
129
|
/**
|
|
91
130
|
* @internal
|
|
92
131
|
*/
|
|
93
132
|
constructor(args: VoteAccountArgs) {
|
|
94
133
|
this.nodePubkey = args.nodePubkey;
|
|
95
|
-
this.
|
|
96
|
-
this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
|
|
134
|
+
this.authorizedWithdrawer = args.authorizedWithdrawer;
|
|
97
135
|
this.commission = args.commission;
|
|
98
|
-
this.votes = args.votes;
|
|
99
136
|
this.rootSlot = args.rootSlot;
|
|
100
|
-
this.
|
|
101
|
-
this.
|
|
102
|
-
this.
|
|
137
|
+
this.votes = args.votes;
|
|
138
|
+
this.authorizedVoters = args.authorizedVoters;
|
|
139
|
+
this.priorVoters = args.priorVoters;
|
|
103
140
|
this.epochCredits = args.epochCredits;
|
|
141
|
+
this.lastTimestamp = args.lastTimestamp;
|
|
104
142
|
}
|
|
105
143
|
|
|
106
144
|
/**
|
|
@@ -112,7 +150,8 @@ export class VoteAccount {
|
|
|
112
150
|
static fromAccountData(
|
|
113
151
|
buffer: Buffer | Uint8Array | Array<number>,
|
|
114
152
|
): VoteAccount {
|
|
115
|
-
const
|
|
153
|
+
const versionOffset = 4;
|
|
154
|
+
const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
|
|
116
155
|
|
|
117
156
|
let rootSlot: number | null = va.rootSlot;
|
|
118
157
|
if (!va.rootSlotValid) {
|
|
@@ -121,15 +160,49 @@ export class VoteAccount {
|
|
|
121
160
|
|
|
122
161
|
return new VoteAccount({
|
|
123
162
|
nodePubkey: new PublicKey(va.nodePubkey),
|
|
124
|
-
|
|
125
|
-
authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
|
|
163
|
+
authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
|
|
126
164
|
commission: va.commission,
|
|
127
165
|
votes: va.votes,
|
|
128
166
|
rootSlot,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
lastEpochCredits: va.lastEpochCredits,
|
|
167
|
+
authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
|
|
168
|
+
priorVoters: getPriorVoters(va.priorVoters),
|
|
132
169
|
epochCredits: va.epochCredits,
|
|
170
|
+
lastTimestamp: va.lastTimestamp,
|
|
133
171
|
});
|
|
134
172
|
}
|
|
135
173
|
}
|
|
174
|
+
|
|
175
|
+
function parseAuthorizedVoter({epoch, authorizedVoter}: AuthorizedVoter) {
|
|
176
|
+
return {
|
|
177
|
+
epoch,
|
|
178
|
+
authorizedVoter: new PublicKey(authorizedVoter),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function parsePriorVoters({
|
|
183
|
+
authorizedPubkey,
|
|
184
|
+
epochOfLastAuthorizedSwitch,
|
|
185
|
+
targetEpoch,
|
|
186
|
+
}: PriorVoter) {
|
|
187
|
+
return {
|
|
188
|
+
authorizedPubkey: new PublicKey(authorizedPubkey),
|
|
189
|
+
epochOfLastAuthorizedSwitch,
|
|
190
|
+
targetEpoch,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function getPriorVoters({
|
|
195
|
+
buf,
|
|
196
|
+
idx,
|
|
197
|
+
isEmpty,
|
|
198
|
+
}: {
|
|
199
|
+
buf: PriorVoter[];
|
|
200
|
+
idx: number;
|
|
201
|
+
isEmpty: boolean;
|
|
202
|
+
}): PriorVoter[] {
|
|
203
|
+
if (isEmpty) {
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
208
|
+
}
|