@solana/web3.js 1.27.1 → 1.28.1
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 +57 -7
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +57 -7
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +26 -2
- package/lib/index.esm.js +57 -7
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +57 -7
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +47 -3
- package/package.json +1 -1
- package/src/connection.ts +62 -4
- package/src/message.ts +27 -0
- package/src/transaction.ts +8 -4
package/lib/index.d.ts
CHANGED
|
@@ -302,8 +302,13 @@ declare module '@solana/web3.js' {
|
|
|
302
302
|
accountKeys: PublicKey[];
|
|
303
303
|
recentBlockhash: Blockhash;
|
|
304
304
|
instructions: CompiledInstruction[];
|
|
305
|
+
private indexToProgramIds;
|
|
305
306
|
constructor(args: MessageArgs);
|
|
307
|
+
isAccountSigner(index: number): boolean;
|
|
306
308
|
isAccountWritable(index: number): boolean;
|
|
309
|
+
isProgramId(index: number): boolean;
|
|
310
|
+
programIds(): PublicKey[];
|
|
311
|
+
nonProgramIds(): PublicKey[];
|
|
307
312
|
serialize(): Buffer;
|
|
308
313
|
/**
|
|
309
314
|
* Decode a compiled message into a Message object.
|
|
@@ -505,7 +510,7 @@ declare module '@solana/web3.js' {
|
|
|
505
510
|
/**
|
|
506
511
|
* Populate Transaction object from message and signatures
|
|
507
512
|
*/
|
|
508
|
-
static populate(message: Message, signatures
|
|
513
|
+
static populate(message: Message, signatures?: Array<string>): Transaction;
|
|
509
514
|
}
|
|
510
515
|
|
|
511
516
|
export type TokenAccountsFilter =
|
|
@@ -720,9 +725,23 @@ declare module '@solana/web3.js' {
|
|
|
720
725
|
'solana-core': string;
|
|
721
726
|
'feature-set'?: number;
|
|
722
727
|
};
|
|
728
|
+
export type SimulatedTransactionAccountInfo = {
|
|
729
|
+
/** `true` if this account's data contains a loaded program */
|
|
730
|
+
executable: boolean;
|
|
731
|
+
/** Identifier of the program that owns the account */
|
|
732
|
+
owner: string;
|
|
733
|
+
/** Number of lamports assigned to the account */
|
|
734
|
+
lamports: number;
|
|
735
|
+
/** Optional data assigned to the account */
|
|
736
|
+
data: string[];
|
|
737
|
+
/** Optional rent epoch info for account */
|
|
738
|
+
rentEpoch?: number;
|
|
739
|
+
};
|
|
723
740
|
export type SimulatedTransactionResponse = {
|
|
724
741
|
err: TransactionError | string | null;
|
|
725
742
|
logs: Array<string> | null;
|
|
743
|
+
accounts?: SimulatedTransactionAccountInfo[] | null;
|
|
744
|
+
unitsConsumed?: number;
|
|
726
745
|
};
|
|
727
746
|
export type ParsedInnerInstruction = {
|
|
728
747
|
index: number;
|
|
@@ -1172,6 +1191,8 @@ declare module '@solana/web3.js' {
|
|
|
1172
1191
|
lamports: number;
|
|
1173
1192
|
/** Optional data assigned to the account */
|
|
1174
1193
|
data: T;
|
|
1194
|
+
/** Optional rent epoch infor for account */
|
|
1195
|
+
rentEpoch?: number;
|
|
1175
1196
|
};
|
|
1176
1197
|
/**
|
|
1177
1198
|
* Account information identified by pubkey
|
|
@@ -1334,6 +1355,8 @@ declare module '@solana/web3.js' {
|
|
|
1334
1355
|
fetchMiddleware?: FetchMiddleware;
|
|
1335
1356
|
/** Optional Disable retring calls when server responds with HTTP 429 (Too Many Requests) */
|
|
1336
1357
|
disableRetryOnRateLimit?: boolean;
|
|
1358
|
+
/** time to allow for the server to initially process a transaction (in milliseconds) */
|
|
1359
|
+
confirmTransactionInitialTimeout?: number;
|
|
1337
1360
|
};
|
|
1338
1361
|
/**
|
|
1339
1362
|
* A connection to a fullnode JSON RPC endpoint
|
|
@@ -1767,8 +1790,9 @@ declare module '@solana/web3.js' {
|
|
|
1767
1790
|
* Simulate a transaction
|
|
1768
1791
|
*/
|
|
1769
1792
|
simulateTransaction(
|
|
1770
|
-
|
|
1793
|
+
transactionOrMessage: Transaction | Message,
|
|
1771
1794
|
signers?: Array<Signer>,
|
|
1795
|
+
includeAccounts?: boolean | Array<PublicKey>,
|
|
1772
1796
|
): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
|
|
1773
1797
|
/**
|
|
1774
1798
|
* Sign and send a transaction
|
package/lib/index.esm.js
CHANGED
|
@@ -491,16 +491,35 @@ class Message {
|
|
|
491
491
|
|
|
492
492
|
_defineProperty(this, "instructions", void 0);
|
|
493
493
|
|
|
494
|
+
_defineProperty(this, "indexToProgramIds", new Map());
|
|
495
|
+
|
|
494
496
|
this.header = args.header;
|
|
495
497
|
this.accountKeys = args.accountKeys.map(account => new PublicKey(account));
|
|
496
498
|
this.recentBlockhash = args.recentBlockhash;
|
|
497
499
|
this.instructions = args.instructions;
|
|
500
|
+
this.instructions.forEach(ix => this.indexToProgramIds.set(ix.programIdIndex, this.accountKeys[ix.programIdIndex]));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
isAccountSigner(index) {
|
|
504
|
+
return index < this.header.numRequiredSignatures;
|
|
498
505
|
}
|
|
499
506
|
|
|
500
507
|
isAccountWritable(index) {
|
|
501
508
|
return index < this.header.numRequiredSignatures - this.header.numReadonlySignedAccounts || index >= this.header.numRequiredSignatures && index < this.accountKeys.length - this.header.numReadonlyUnsignedAccounts;
|
|
502
509
|
}
|
|
503
510
|
|
|
511
|
+
isProgramId(index) {
|
|
512
|
+
return this.indexToProgramIds.has(index);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
programIds() {
|
|
516
|
+
return [...this.indexToProgramIds.values()];
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
nonProgramIds() {
|
|
520
|
+
return this.accountKeys.filter((_, index) => !this.isProgramId(index));
|
|
521
|
+
}
|
|
522
|
+
|
|
504
523
|
serialize() {
|
|
505
524
|
const numKeys = this.accountKeys.length;
|
|
506
525
|
let keyCount = [];
|
|
@@ -1214,7 +1233,7 @@ class Transaction {
|
|
|
1214
1233
|
*/
|
|
1215
1234
|
|
|
1216
1235
|
|
|
1217
|
-
static populate(message, signatures) {
|
|
1236
|
+
static populate(message, signatures = []) {
|
|
1218
1237
|
const transaction = new Transaction();
|
|
1219
1238
|
transaction.recentBlockhash = message.recentBlockhash;
|
|
1220
1239
|
|
|
@@ -1234,7 +1253,7 @@ class Transaction {
|
|
|
1234
1253
|
const pubkey = message.accountKeys[account];
|
|
1235
1254
|
return {
|
|
1236
1255
|
pubkey,
|
|
1237
|
-
isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()),
|
|
1256
|
+
isSigner: transaction.signatures.some(keyObj => keyObj.publicKey.toString() === pubkey.toString()) || message.isAccountSigner(account),
|
|
1238
1257
|
isWritable: message.isAccountWritable(account)
|
|
1239
1258
|
};
|
|
1240
1259
|
});
|
|
@@ -2666,7 +2685,15 @@ const VersionResult = type({
|
|
|
2666
2685
|
});
|
|
2667
2686
|
const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(type({
|
|
2668
2687
|
err: nullable(union([type({}), string()])),
|
|
2669
|
-
logs: nullable(array(string()))
|
|
2688
|
+
logs: nullable(array(string())),
|
|
2689
|
+
accounts: optional(nullable(array(type({
|
|
2690
|
+
executable: boolean(),
|
|
2691
|
+
owner: string(),
|
|
2692
|
+
lamports: number(),
|
|
2693
|
+
data: array(string()),
|
|
2694
|
+
rentEpoch: optional(number())
|
|
2695
|
+
})))),
|
|
2696
|
+
unitsConsumed: optional(number())
|
|
2670
2697
|
}));
|
|
2671
2698
|
|
|
2672
2699
|
function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit) {
|
|
@@ -3398,6 +3425,8 @@ class Connection {
|
|
|
3398
3425
|
|
|
3399
3426
|
/** @internal */
|
|
3400
3427
|
|
|
3428
|
+
/** @internal */
|
|
3429
|
+
|
|
3401
3430
|
/**
|
|
3402
3431
|
* Establish a JSON RPC connection
|
|
3403
3432
|
*
|
|
@@ -3407,6 +3436,8 @@ class Connection {
|
|
|
3407
3436
|
constructor(endpoint, commitmentOrConfig) {
|
|
3408
3437
|
_defineProperty(this, "_commitment", void 0);
|
|
3409
3438
|
|
|
3439
|
+
_defineProperty(this, "_confirmTransactionInitialTimeout", void 0);
|
|
3440
|
+
|
|
3410
3441
|
_defineProperty(this, "_rpcEndpoint", void 0);
|
|
3411
3442
|
|
|
3412
3443
|
_defineProperty(this, "_rpcWsEndpoint", void 0);
|
|
@@ -3475,6 +3506,7 @@ class Connection {
|
|
|
3475
3506
|
this._commitment = commitmentOrConfig;
|
|
3476
3507
|
} else if (commitmentOrConfig) {
|
|
3477
3508
|
this._commitment = commitmentOrConfig.commitment;
|
|
3509
|
+
this._confirmTransactionInitialTimeout = commitmentOrConfig.confirmTransactionInitialTimeout;
|
|
3478
3510
|
wsEndpoint = commitmentOrConfig.wsEndpoint;
|
|
3479
3511
|
httpHeaders = commitmentOrConfig.httpHeaders;
|
|
3480
3512
|
fetchMiddleware = commitmentOrConfig.fetchMiddleware;
|
|
@@ -3934,7 +3966,7 @@ class Connection {
|
|
|
3934
3966
|
reject(err);
|
|
3935
3967
|
}
|
|
3936
3968
|
});
|
|
3937
|
-
let timeoutMs = 60 * 1000;
|
|
3969
|
+
let timeoutMs = this._confirmTransactionInitialTimeout || 60 * 1000;
|
|
3938
3970
|
|
|
3939
3971
|
switch (subscriptionCommitment) {
|
|
3940
3972
|
case 'processed':
|
|
@@ -3943,7 +3975,7 @@ class Connection {
|
|
|
3943
3975
|
case 'confirmed':
|
|
3944
3976
|
case 'singleGossip':
|
|
3945
3977
|
{
|
|
3946
|
-
timeoutMs = 30 * 1000;
|
|
3978
|
+
timeoutMs = this._confirmTransactionInitialTimeout || 30 * 1000;
|
|
3947
3979
|
break;
|
|
3948
3980
|
}
|
|
3949
3981
|
}
|
|
@@ -4730,7 +4762,15 @@ class Connection {
|
|
|
4730
4762
|
*/
|
|
4731
4763
|
|
|
4732
4764
|
|
|
4733
|
-
async simulateTransaction(
|
|
4765
|
+
async simulateTransaction(transactionOrMessage, signers, includeAccounts) {
|
|
4766
|
+
let transaction;
|
|
4767
|
+
|
|
4768
|
+
if (transactionOrMessage instanceof Transaction) {
|
|
4769
|
+
transaction = transactionOrMessage;
|
|
4770
|
+
} else {
|
|
4771
|
+
transaction = Transaction.populate(transactionOrMessage);
|
|
4772
|
+
}
|
|
4773
|
+
|
|
4734
4774
|
if (transaction.nonceInfo && signers) {
|
|
4735
4775
|
transaction.sign(...signers);
|
|
4736
4776
|
} else {
|
|
@@ -4763,7 +4803,9 @@ class Connection {
|
|
|
4763
4803
|
}
|
|
4764
4804
|
}
|
|
4765
4805
|
|
|
4766
|
-
const
|
|
4806
|
+
const message = transaction._compile();
|
|
4807
|
+
|
|
4808
|
+
const signData = message.serialize();
|
|
4767
4809
|
|
|
4768
4810
|
const wireTransaction = transaction._serialize(signData);
|
|
4769
4811
|
|
|
@@ -4773,6 +4815,14 @@ class Connection {
|
|
|
4773
4815
|
commitment: this.commitment
|
|
4774
4816
|
};
|
|
4775
4817
|
|
|
4818
|
+
if (includeAccounts) {
|
|
4819
|
+
const addresses = (Array.isArray(includeAccounts) ? includeAccounts : message.nonProgramIds()).map(key => key.toBase58());
|
|
4820
|
+
config['accounts'] = {
|
|
4821
|
+
encoding: 'base64',
|
|
4822
|
+
addresses
|
|
4823
|
+
};
|
|
4824
|
+
}
|
|
4825
|
+
|
|
4776
4826
|
if (signers) {
|
|
4777
4827
|
config.sigVerify = true;
|
|
4778
4828
|
}
|