@solana/web3.js 1.39.1 → 1.40.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/package.json +3 -3
- package/src/connection.ts +50 -12
- package/src/publickey.ts +31 -7
- package/src/stake-program.ts +2 -2
- package/src/transaction.ts +5 -6
- package/lib/index.browser.cjs.js +0 -9908
- package/lib/index.browser.cjs.js.map +0 -1
- package/lib/index.browser.esm.js +0 -9822
- package/lib/index.browser.esm.js.map +0 -1
- package/lib/index.cjs.js +0 -9414
- package/lib/index.cjs.js.map +0 -1
- package/lib/index.d.ts +0 -3216
- package/lib/index.esm.js +0 -9325
- package/lib/index.esm.js.map +0 -1
- package/lib/index.iife.js +0 -29982
- package/lib/index.iife.js.map +0 -1
- package/lib/index.iife.min.js +0 -40
- package/lib/index.iife.min.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/web3.js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.40.0",
|
|
4
4
|
"description": "Solana Javascript API",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@babel/preset-typescript": "^7.12.16",
|
|
80
80
|
"@babel/register": "^7.12.13",
|
|
81
81
|
"@commitlint/config-conventional": "^15.0.0",
|
|
82
|
-
"@commitlint/travis-cli": "^
|
|
82
|
+
"@commitlint/travis-cli": "^16.2.3",
|
|
83
83
|
"@rollup/plugin-alias": "^3.1.2",
|
|
84
84
|
"@rollup/plugin-babel": "^5.2.3",
|
|
85
85
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
@@ -95,7 +95,7 @@
|
|
|
95
95
|
"@types/express-serve-static-core": "^4.17.21",
|
|
96
96
|
"@types/mocha": "^9.0.0",
|
|
97
97
|
"@types/mz": "^2.7.3",
|
|
98
|
-
"@types/node": "^
|
|
98
|
+
"@types/node": "^17.0.24",
|
|
99
99
|
"@types/secp256k1": "^4.0.1",
|
|
100
100
|
"@types/sinon": "^10.0.0",
|
|
101
101
|
"@typescript-eslint/eslint-plugin": "^4.14.2",
|
package/src/connection.ts
CHANGED
|
@@ -2120,6 +2120,13 @@ export type ConnectionConfig = {
|
|
|
2120
2120
|
confirmTransactionInitialTimeout?: number;
|
|
2121
2121
|
};
|
|
2122
2122
|
|
|
2123
|
+
function createSubscriptionWarningMessage(id: number, label: string): string {
|
|
2124
|
+
return (
|
|
2125
|
+
'Ignored unsubscribe request because an active subscription ' +
|
|
2126
|
+
`with id \`${id}\` for '${label}' events could not be found.`
|
|
2127
|
+
);
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2123
2130
|
/**
|
|
2124
2131
|
* A connection to a fullnode JSON RPC endpoint
|
|
2125
2132
|
*/
|
|
@@ -3404,6 +3411,34 @@ export class Connection {
|
|
|
3404
3411
|
return res;
|
|
3405
3412
|
}
|
|
3406
3413
|
|
|
3414
|
+
/**
|
|
3415
|
+
* Fetch transaction details for a batch of confirmed transactions.
|
|
3416
|
+
* Similar to {@link getParsedTransactions} but returns a {@link TransactionResponse}.
|
|
3417
|
+
*/
|
|
3418
|
+
async getTransactions(
|
|
3419
|
+
signatures: TransactionSignature[],
|
|
3420
|
+
commitment?: Finality,
|
|
3421
|
+
): Promise<(TransactionResponse | null)[]> {
|
|
3422
|
+
const batch = signatures.map(signature => {
|
|
3423
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment);
|
|
3424
|
+
return {
|
|
3425
|
+
methodName: 'getTransaction',
|
|
3426
|
+
args,
|
|
3427
|
+
};
|
|
3428
|
+
});
|
|
3429
|
+
|
|
3430
|
+
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
3431
|
+
const res = unsafeRes.map((unsafeRes: any) => {
|
|
3432
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
3433
|
+
if ('error' in res) {
|
|
3434
|
+
throw new Error('failed to get transactions: ' + res.error.message);
|
|
3435
|
+
}
|
|
3436
|
+
return res.result;
|
|
3437
|
+
});
|
|
3438
|
+
|
|
3439
|
+
return res;
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3407
3442
|
/**
|
|
3408
3443
|
* Fetch a list of Transactions and transaction statuses from the cluster
|
|
3409
3444
|
* for a confirmed block.
|
|
@@ -4353,7 +4388,7 @@ export class Connection {
|
|
|
4353
4388
|
await this._unsubscribe(subInfo, 'accountUnsubscribe');
|
|
4354
4389
|
this._updateSubscriptions();
|
|
4355
4390
|
} else {
|
|
4356
|
-
|
|
4391
|
+
console.warn(createSubscriptionWarningMessage(id, 'account change'));
|
|
4357
4392
|
}
|
|
4358
4393
|
}
|
|
4359
4394
|
|
|
@@ -4417,7 +4452,9 @@ export class Connection {
|
|
|
4417
4452
|
await this._unsubscribe(subInfo, 'programUnsubscribe');
|
|
4418
4453
|
this._updateSubscriptions();
|
|
4419
4454
|
} else {
|
|
4420
|
-
|
|
4455
|
+
console.warn(
|
|
4456
|
+
createSubscriptionWarningMessage(id, 'program account change'),
|
|
4457
|
+
);
|
|
4421
4458
|
}
|
|
4422
4459
|
}
|
|
4423
4460
|
|
|
@@ -4446,13 +4483,14 @@ export class Connection {
|
|
|
4446
4483
|
* @param id subscription id to deregister.
|
|
4447
4484
|
*/
|
|
4448
4485
|
async removeOnLogsListener(id: number): Promise<void> {
|
|
4449
|
-
if (
|
|
4450
|
-
|
|
4486
|
+
if (this._logsSubscriptions[id]) {
|
|
4487
|
+
const subInfo = this._logsSubscriptions[id];
|
|
4488
|
+
delete this._logsSubscriptions[id];
|
|
4489
|
+
await this._unsubscribe(subInfo, 'logsUnsubscribe');
|
|
4490
|
+
this._updateSubscriptions();
|
|
4491
|
+
} else {
|
|
4492
|
+
console.warn(createSubscriptionWarningMessage(id, 'logs'));
|
|
4451
4493
|
}
|
|
4452
|
-
const subInfo = this._logsSubscriptions[id];
|
|
4453
|
-
delete this._logsSubscriptions[id];
|
|
4454
|
-
await this._unsubscribe(subInfo, 'logsUnsubscribe');
|
|
4455
|
-
this._updateSubscriptions();
|
|
4456
4494
|
}
|
|
4457
4495
|
|
|
4458
4496
|
/**
|
|
@@ -4511,7 +4549,7 @@ export class Connection {
|
|
|
4511
4549
|
await this._unsubscribe(subInfo, 'slotUnsubscribe');
|
|
4512
4550
|
this._updateSubscriptions();
|
|
4513
4551
|
} else {
|
|
4514
|
-
|
|
4552
|
+
console.warn(createSubscriptionWarningMessage(id, 'slot change'));
|
|
4515
4553
|
}
|
|
4516
4554
|
}
|
|
4517
4555
|
|
|
@@ -4557,7 +4595,7 @@ export class Connection {
|
|
|
4557
4595
|
await this._unsubscribe(subInfo, 'slotsUpdatesUnsubscribe');
|
|
4558
4596
|
this._updateSubscriptions();
|
|
4559
4597
|
} else {
|
|
4560
|
-
|
|
4598
|
+
console.warn(createSubscriptionWarningMessage(id, 'slot update'));
|
|
4561
4599
|
}
|
|
4562
4600
|
}
|
|
4563
4601
|
|
|
@@ -4702,7 +4740,7 @@ export class Connection {
|
|
|
4702
4740
|
await this._unsubscribe(subInfo, 'signatureUnsubscribe');
|
|
4703
4741
|
this._updateSubscriptions();
|
|
4704
4742
|
} else {
|
|
4705
|
-
|
|
4743
|
+
console.warn(createSubscriptionWarningMessage(id, 'signature result'));
|
|
4706
4744
|
}
|
|
4707
4745
|
}
|
|
4708
4746
|
|
|
@@ -4747,7 +4785,7 @@ export class Connection {
|
|
|
4747
4785
|
await this._unsubscribe(subInfo, 'rootUnsubscribe');
|
|
4748
4786
|
this._updateSubscriptions();
|
|
4749
4787
|
} else {
|
|
4750
|
-
|
|
4788
|
+
console.warn(createSubscriptionWarningMessage(id, 'root change'));
|
|
4751
4789
|
}
|
|
4752
4790
|
}
|
|
4753
4791
|
}
|
package/src/publickey.ts
CHANGED
|
@@ -143,10 +143,10 @@ export class PublicKey extends Struct {
|
|
|
143
143
|
* Derive a program address from seeds and a program ID.
|
|
144
144
|
*/
|
|
145
145
|
/* eslint-disable require-await */
|
|
146
|
-
static
|
|
146
|
+
static createProgramAddressSync(
|
|
147
147
|
seeds: Array<Buffer | Uint8Array>,
|
|
148
148
|
programId: PublicKey,
|
|
149
|
-
):
|
|
149
|
+
): PublicKey {
|
|
150
150
|
let buffer = Buffer.alloc(0);
|
|
151
151
|
seeds.forEach(function (seed) {
|
|
152
152
|
if (seed.length > MAX_SEED_LENGTH) {
|
|
@@ -167,6 +167,18 @@ export class PublicKey extends Struct {
|
|
|
167
167
|
return new PublicKey(publicKeyBytes);
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
/**
|
|
171
|
+
* Async version of createProgramAddressSync
|
|
172
|
+
* For backwards compatibility
|
|
173
|
+
*/
|
|
174
|
+
/* eslint-disable require-await */
|
|
175
|
+
static async createProgramAddress(
|
|
176
|
+
seeds: Array<Buffer | Uint8Array>,
|
|
177
|
+
programId: PublicKey,
|
|
178
|
+
): Promise<PublicKey> {
|
|
179
|
+
return this.createProgramAddressSync(seeds, programId);
|
|
180
|
+
}
|
|
181
|
+
|
|
170
182
|
/**
|
|
171
183
|
* Find a valid program address
|
|
172
184
|
*
|
|
@@ -174,16 +186,16 @@ export class PublicKey extends Struct {
|
|
|
174
186
|
* iterates a nonce until it finds one that when combined with the seeds
|
|
175
187
|
* results in a valid program address.
|
|
176
188
|
*/
|
|
177
|
-
static
|
|
189
|
+
static findProgramAddressSync(
|
|
178
190
|
seeds: Array<Buffer | Uint8Array>,
|
|
179
191
|
programId: PublicKey,
|
|
180
|
-
):
|
|
192
|
+
): [PublicKey, number] {
|
|
181
193
|
let nonce = 255;
|
|
182
194
|
let address;
|
|
183
195
|
while (nonce != 0) {
|
|
184
196
|
try {
|
|
185
197
|
const seedsWithNonce = seeds.concat(Buffer.from([nonce]));
|
|
186
|
-
address =
|
|
198
|
+
address = this.createProgramAddressSync(seedsWithNonce, programId);
|
|
187
199
|
} catch (err) {
|
|
188
200
|
if (err instanceof TypeError) {
|
|
189
201
|
throw err;
|
|
@@ -196,11 +208,23 @@ export class PublicKey extends Struct {
|
|
|
196
208
|
throw new Error(`Unable to find a viable program address nonce`);
|
|
197
209
|
}
|
|
198
210
|
|
|
211
|
+
/**
|
|
212
|
+
* Async version of findProgramAddressSync
|
|
213
|
+
* For backwards compatibility
|
|
214
|
+
*/
|
|
215
|
+
static async findProgramAddress(
|
|
216
|
+
seeds: Array<Buffer | Uint8Array>,
|
|
217
|
+
programId: PublicKey,
|
|
218
|
+
): Promise<[PublicKey, number]> {
|
|
219
|
+
return this.findProgramAddressSync(seeds, programId);
|
|
220
|
+
}
|
|
221
|
+
|
|
199
222
|
/**
|
|
200
223
|
* Check that a pubkey is on the ed25519 curve.
|
|
201
224
|
*/
|
|
202
|
-
static isOnCurve(
|
|
203
|
-
|
|
225
|
+
static isOnCurve(pubkeyData: PublicKeyInitData): boolean {
|
|
226
|
+
const pubkey = new PublicKey(pubkeyData);
|
|
227
|
+
return is_on_curve(pubkey.toBytes()) == 1;
|
|
204
228
|
}
|
|
205
229
|
}
|
|
206
230
|
|
package/src/stake-program.ts
CHANGED
|
@@ -601,8 +601,8 @@ export class StakeProgram {
|
|
|
601
601
|
* Max space of a Stake account
|
|
602
602
|
*
|
|
603
603
|
* This is generated from the solana-stake-program StakeState struct as
|
|
604
|
-
* `
|
|
605
|
-
* https://docs.rs/solana-stake-program/
|
|
604
|
+
* `StakeState::size_of()`:
|
|
605
|
+
* https://docs.rs/solana-stake-program/latest/solana_stake_program/stake_state/enum.StakeState.html
|
|
606
606
|
*/
|
|
607
607
|
static space: number = 200;
|
|
608
608
|
|
package/src/transaction.ts
CHANGED
|
@@ -167,7 +167,7 @@ export interface TransactionJSON {
|
|
|
167
167
|
nonceInstruction: TransactionInstructionJSON;
|
|
168
168
|
} | null;
|
|
169
169
|
instructions: TransactionInstructionJSON[];
|
|
170
|
-
|
|
170
|
+
signers: string[];
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
/**
|
|
@@ -242,10 +242,9 @@ export class Transaction {
|
|
|
242
242
|
}
|
|
243
243
|
: null,
|
|
244
244
|
instructions: this.instructions.map(instruction => instruction.toJSON()),
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
})),
|
|
245
|
+
signers: this.signatures.map(({publicKey}) => {
|
|
246
|
+
return publicKey.toJSON();
|
|
247
|
+
}),
|
|
249
248
|
};
|
|
250
249
|
}
|
|
251
250
|
|
|
@@ -280,7 +279,7 @@ export class Transaction {
|
|
|
280
279
|
if (this._message) {
|
|
281
280
|
if (JSON.stringify(this.toJSON()) !== JSON.stringify(this._json)) {
|
|
282
281
|
throw new Error(
|
|
283
|
-
'Transaction mutated after being populated from Message',
|
|
282
|
+
'Transaction message mutated after being populated from Message',
|
|
284
283
|
);
|
|
285
284
|
}
|
|
286
285
|
return this._message;
|