@solana/web3.js 1.30.1 → 1.32.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/README.md +2 -2
- package/lib/index.browser.esm.js +443 -268
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +453 -279
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +121 -19
- package/lib/index.esm.js +447 -276
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +29025 -28864
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +30 -30
- 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 +313 -41
- 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/lib/index.esm.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as nacl from 'tweetnacl';
|
|
3
|
-
import nacl__default from 'tweetnacl';
|
|
1
|
+
import nacl from 'tweetnacl';
|
|
4
2
|
import { Buffer } from 'buffer';
|
|
5
3
|
import BN from 'bn.js';
|
|
6
4
|
import bs58 from 'bs58';
|
|
@@ -13,7 +11,7 @@ import RpcClient from 'jayson/lib/client/browser';
|
|
|
13
11
|
import http from 'http';
|
|
14
12
|
import https from 'https';
|
|
15
13
|
import secp256k1 from 'secp256k1';
|
|
16
|
-
import
|
|
14
|
+
import sha3 from 'js-sha3';
|
|
17
15
|
|
|
18
16
|
const toBuffer = arr => {
|
|
19
17
|
if (Buffer.isBuffer(arr)) {
|
|
@@ -1725,8 +1723,7 @@ class Struct {
|
|
|
1725
1723
|
class Enum extends Struct {
|
|
1726
1724
|
constructor(properties) {
|
|
1727
1725
|
super(properties);
|
|
1728
|
-
|
|
1729
|
-
_defineProperty(this, "enum", '');
|
|
1726
|
+
this.enum = '';
|
|
1730
1727
|
|
|
1731
1728
|
if (Object.keys(properties).length !== 1) {
|
|
1732
1729
|
throw new Error('Enum can only take single value');
|
|
@@ -1766,8 +1763,7 @@ class PublicKey extends Struct {
|
|
|
1766
1763
|
*/
|
|
1767
1764
|
constructor(value) {
|
|
1768
1765
|
super({});
|
|
1769
|
-
|
|
1770
|
-
_defineProperty(this, "_bn", void 0);
|
|
1766
|
+
this._bn = void 0;
|
|
1771
1767
|
|
|
1772
1768
|
if (isPublicKeyData(value)) {
|
|
1773
1769
|
this._bn = value._bn;
|
|
@@ -1777,7 +1773,7 @@ class PublicKey extends Struct {
|
|
|
1777
1773
|
const decoded = bs58.decode(value);
|
|
1778
1774
|
|
|
1779
1775
|
if (decoded.length != 32) {
|
|
1780
|
-
throw new Error(
|
|
1776
|
+
throw new Error(`Invalid public key input`);
|
|
1781
1777
|
}
|
|
1782
1778
|
|
|
1783
1779
|
this._bn = new BN(decoded);
|
|
@@ -1786,7 +1782,7 @@ class PublicKey extends Struct {
|
|
|
1786
1782
|
}
|
|
1787
1783
|
|
|
1788
1784
|
if (this._bn.byteLength() > 32) {
|
|
1789
|
-
throw new Error(
|
|
1785
|
+
throw new Error(`Invalid public key input`);
|
|
1790
1786
|
}
|
|
1791
1787
|
}
|
|
1792
1788
|
}
|
|
@@ -1809,6 +1805,10 @@ class PublicKey extends Struct {
|
|
|
1809
1805
|
toBase58() {
|
|
1810
1806
|
return bs58.encode(this.toBytes());
|
|
1811
1807
|
}
|
|
1808
|
+
|
|
1809
|
+
toJSON() {
|
|
1810
|
+
return this.toBase58();
|
|
1811
|
+
}
|
|
1812
1812
|
/**
|
|
1813
1813
|
* Return the byte array representation of the public key
|
|
1814
1814
|
*/
|
|
@@ -1866,7 +1866,7 @@ class PublicKey extends Struct {
|
|
|
1866
1866
|
let buffer = Buffer.alloc(0);
|
|
1867
1867
|
seeds.forEach(function (seed) {
|
|
1868
1868
|
if (seed.length > MAX_SEED_LENGTH) {
|
|
1869
|
-
throw new TypeError(
|
|
1869
|
+
throw new TypeError(`Max seed length exceeded`);
|
|
1870
1870
|
}
|
|
1871
1871
|
|
|
1872
1872
|
buffer = Buffer.concat([buffer, toBuffer(seed)]);
|
|
@@ -1876,7 +1876,7 @@ class PublicKey extends Struct {
|
|
|
1876
1876
|
let publicKeyBytes = new BN(hash, 16).toArray(undefined, 32);
|
|
1877
1877
|
|
|
1878
1878
|
if (is_on_curve(publicKeyBytes)) {
|
|
1879
|
-
throw new Error(
|
|
1879
|
+
throw new Error(`Invalid seeds, address must fall off the curve`);
|
|
1880
1880
|
}
|
|
1881
1881
|
|
|
1882
1882
|
return new PublicKey(publicKeyBytes);
|
|
@@ -1910,7 +1910,7 @@ class PublicKey extends Struct {
|
|
|
1910
1910
|
return [address, nonce];
|
|
1911
1911
|
}
|
|
1912
1912
|
|
|
1913
|
-
throw new Error(
|
|
1913
|
+
throw new Error(`Unable to find a viable program address nonce`);
|
|
1914
1914
|
}
|
|
1915
1915
|
/**
|
|
1916
1916
|
* Check that a pubkey is on the ed25519 curve.
|
|
@@ -1922,15 +1922,13 @@ class PublicKey extends Struct {
|
|
|
1922
1922
|
}
|
|
1923
1923
|
|
|
1924
1924
|
}
|
|
1925
|
-
|
|
1926
|
-
_defineProperty(PublicKey, "default", new PublicKey('11111111111111111111111111111111'));
|
|
1927
|
-
|
|
1925
|
+
PublicKey.default = new PublicKey('11111111111111111111111111111111');
|
|
1928
1926
|
SOLANA_SCHEMA.set(PublicKey, {
|
|
1929
1927
|
kind: 'struct',
|
|
1930
1928
|
fields: [['_bn', 'u256']]
|
|
1931
1929
|
}); // @ts-ignore
|
|
1932
1930
|
|
|
1933
|
-
let naclLowLevel =
|
|
1931
|
+
let naclLowLevel = nacl.lowlevel; // Check that a pubkey is on the curve.
|
|
1934
1932
|
// This function and its dependents were sourced from:
|
|
1935
1933
|
// https://github.com/dchest/tweetnacl-js/blob/f1ec050ceae0861f34280e62498b1d3ed9c350c6/nacl.js#L792
|
|
1936
1934
|
|
|
@@ -1997,7 +1995,7 @@ class Account {
|
|
|
1997
1995
|
* @param secretKey Secret key for the account
|
|
1998
1996
|
*/
|
|
1999
1997
|
constructor(secretKey) {
|
|
2000
|
-
|
|
1998
|
+
this._keypair = void 0;
|
|
2001
1999
|
|
|
2002
2000
|
if (secretKey) {
|
|
2003
2001
|
this._keypair = nacl.sign.keyPair.fromSecretKey(toBuffer(secretKey));
|
|
@@ -2133,16 +2131,11 @@ const PUBKEY_LENGTH = 32;
|
|
|
2133
2131
|
|
|
2134
2132
|
class Message {
|
|
2135
2133
|
constructor(args) {
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
_defineProperty(this, "instructions", void 0);
|
|
2143
|
-
|
|
2144
|
-
_defineProperty(this, "indexToProgramIds", new Map());
|
|
2145
|
-
|
|
2134
|
+
this.header = void 0;
|
|
2135
|
+
this.accountKeys = void 0;
|
|
2136
|
+
this.recentBlockhash = void 0;
|
|
2137
|
+
this.instructions = void 0;
|
|
2138
|
+
this.indexToProgramIds = new Map();
|
|
2146
2139
|
this.header = args.header;
|
|
2147
2140
|
this.accountKeys = args.accountKeys.map(account => new PublicKey(account));
|
|
2148
2141
|
this.recentBlockhash = args.recentBlockhash;
|
|
@@ -2316,12 +2309,9 @@ class TransactionInstruction {
|
|
|
2316
2309
|
* Program input
|
|
2317
2310
|
*/
|
|
2318
2311
|
constructor(opts) {
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
_defineProperty(this, "data", Buffer.alloc(0));
|
|
2324
|
-
|
|
2312
|
+
this.keys = void 0;
|
|
2313
|
+
this.programId = void 0;
|
|
2314
|
+
this.data = Buffer.alloc(0);
|
|
2325
2315
|
this.programId = opts.programId;
|
|
2326
2316
|
this.keys = opts.keys;
|
|
2327
2317
|
|
|
@@ -2363,16 +2353,11 @@ class Transaction {
|
|
|
2363
2353
|
* Construct an empty Transaction
|
|
2364
2354
|
*/
|
|
2365
2355
|
constructor(opts) {
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
_defineProperty(this, "recentBlockhash", void 0);
|
|
2373
|
-
|
|
2374
|
-
_defineProperty(this, "nonceInfo", void 0);
|
|
2375
|
-
|
|
2356
|
+
this.signatures = [];
|
|
2357
|
+
this.feePayer = void 0;
|
|
2358
|
+
this.instructions = [];
|
|
2359
|
+
this.recentBlockhash = void 0;
|
|
2360
|
+
this.nonceInfo = void 0;
|
|
2376
2361
|
opts && Object.assign(this, opts);
|
|
2377
2362
|
}
|
|
2378
2363
|
/**
|
|
@@ -2436,7 +2421,7 @@ class Transaction {
|
|
|
2436
2421
|
|
|
2437
2422
|
for (let i = 0; i < this.instructions.length; i++) {
|
|
2438
2423
|
if (this.instructions[i].programId === undefined) {
|
|
2439
|
-
throw new Error(
|
|
2424
|
+
throw new Error(`Transaction instruction index ${i} has undefined program id`);
|
|
2440
2425
|
}
|
|
2441
2426
|
}
|
|
2442
2427
|
|
|
@@ -2463,8 +2448,9 @@ class Transaction {
|
|
|
2463
2448
|
}); // Sort. Prioritizing first by signer, then by writable
|
|
2464
2449
|
|
|
2465
2450
|
accountMetas.sort(function (x, y) {
|
|
2451
|
+
const pubkeySorting = x.pubkey.toBase58().localeCompare(y.pubkey.toBase58());
|
|
2466
2452
|
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1;
|
|
2467
|
-
const checkWritable = x.isWritable === y.isWritable ?
|
|
2453
|
+
const checkWritable = x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1;
|
|
2468
2454
|
return checkSigner || checkWritable;
|
|
2469
2455
|
}); // Cull duplicate account metas
|
|
2470
2456
|
|
|
@@ -2511,7 +2497,7 @@ class Transaction {
|
|
|
2511
2497
|
console.warn('Transaction references a signature that is unnecessary, ' + 'only the fee payer and instruction signer accounts should sign a transaction. ' + 'This behavior is deprecated and will throw an error in the next major version release.');
|
|
2512
2498
|
}
|
|
2513
2499
|
} else {
|
|
2514
|
-
throw new Error(
|
|
2500
|
+
throw new Error(`unknown signer: ${signature.publicKey.toString()}`);
|
|
2515
2501
|
}
|
|
2516
2502
|
}
|
|
2517
2503
|
|
|
@@ -2718,7 +2704,7 @@ class Transaction {
|
|
|
2718
2704
|
_partialSign(message, ...signers) {
|
|
2719
2705
|
const signData = message.serialize();
|
|
2720
2706
|
signers.forEach(signer => {
|
|
2721
|
-
const signature =
|
|
2707
|
+
const signature = nacl.sign.detached(signData, signer.secretKey);
|
|
2722
2708
|
|
|
2723
2709
|
this._addSignature(signer.publicKey, toBuffer(signature));
|
|
2724
2710
|
});
|
|
@@ -2746,7 +2732,7 @@ class Transaction {
|
|
|
2746
2732
|
const index = this.signatures.findIndex(sigpair => pubkey.equals(sigpair.publicKey));
|
|
2747
2733
|
|
|
2748
2734
|
if (index < 0) {
|
|
2749
|
-
throw new Error(
|
|
2735
|
+
throw new Error(`unknown signer: ${pubkey.toString()}`);
|
|
2750
2736
|
}
|
|
2751
2737
|
|
|
2752
2738
|
this.signatures[index].signature = Buffer.from(signature);
|
|
@@ -2774,7 +2760,7 @@ class Transaction {
|
|
|
2774
2760
|
return false;
|
|
2775
2761
|
}
|
|
2776
2762
|
} else {
|
|
2777
|
-
if (!
|
|
2763
|
+
if (!nacl.sign.detached.verify(signData, signature, publicKey.toBuffer())) {
|
|
2778
2764
|
return false;
|
|
2779
2765
|
}
|
|
2780
2766
|
}
|
|
@@ -2822,12 +2808,12 @@ class Transaction {
|
|
|
2822
2808
|
signature
|
|
2823
2809
|
}, index) => {
|
|
2824
2810
|
if (signature !== null) {
|
|
2825
|
-
assert(signature.length === 64,
|
|
2811
|
+
assert(signature.length === 64, `signature has invalid length`);
|
|
2826
2812
|
Buffer.from(signature).copy(wireTransaction, signatureCount.length + index * 64);
|
|
2827
2813
|
}
|
|
2828
2814
|
});
|
|
2829
2815
|
signData.copy(wireTransaction, signatureCount.length + signatures.length * 64);
|
|
2830
|
-
assert(wireTransaction.length <= PACKET_DATA_SIZE,
|
|
2816
|
+
assert(wireTransaction.length <= PACKET_DATA_SIZE, `Transaction too large: ${wireTransaction.length} > ${PACKET_DATA_SIZE}`);
|
|
2831
2817
|
return wireTransaction;
|
|
2832
2818
|
}
|
|
2833
2819
|
/**
|
|
@@ -2920,11 +2906,14 @@ class Transaction {
|
|
|
2920
2906
|
}
|
|
2921
2907
|
|
|
2922
2908
|
const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
|
|
2909
|
+
const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
|
|
2910
|
+
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2923
2911
|
const SYSVAR_RECENT_BLOCKHASHES_PUBKEY = new PublicKey('SysvarRecentB1ockHashes11111111111111111111');
|
|
2924
2912
|
const SYSVAR_RENT_PUBKEY = new PublicKey('SysvarRent111111111111111111111111111111111');
|
|
2925
2913
|
const SYSVAR_REWARDS_PUBKEY = new PublicKey('SysvarRewards111111111111111111111111111111');
|
|
2914
|
+
const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111111111111111');
|
|
2915
|
+
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
2926
2916
|
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
2927
|
-
const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
|
|
2928
2917
|
|
|
2929
2918
|
/**
|
|
2930
2919
|
* Sign, send and confirm a transaction.
|
|
@@ -2940,13 +2929,14 @@ const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions111111111111
|
|
|
2940
2929
|
async function sendAndConfirmTransaction(connection, transaction, signers, options) {
|
|
2941
2930
|
const sendOptions = options && {
|
|
2942
2931
|
skipPreflight: options.skipPreflight,
|
|
2943
|
-
preflightCommitment: options.preflightCommitment || options.commitment
|
|
2932
|
+
preflightCommitment: options.preflightCommitment || options.commitment,
|
|
2933
|
+
maxRetries: options.maxRetries
|
|
2944
2934
|
};
|
|
2945
2935
|
const signature = await connection.sendTransaction(transaction, signers, sendOptions);
|
|
2946
2936
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2947
2937
|
|
|
2948
2938
|
if (status.err) {
|
|
2949
|
-
throw new Error(
|
|
2939
|
+
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
2950
2940
|
}
|
|
2951
2941
|
|
|
2952
2942
|
return signature;
|
|
@@ -2989,7 +2979,7 @@ function decodeData(type, buffer) {
|
|
|
2989
2979
|
}
|
|
2990
2980
|
|
|
2991
2981
|
if (data.instruction !== type.index) {
|
|
2992
|
-
throw new Error(
|
|
2982
|
+
throw new Error(`invalid instruction; instruction index mismatch ${data.instruction} != ${type.index}`);
|
|
2993
2983
|
}
|
|
2994
2984
|
|
|
2995
2985
|
return data;
|
|
@@ -3023,12 +3013,9 @@ class NonceAccount {
|
|
|
3023
3013
|
* @internal
|
|
3024
3014
|
*/
|
|
3025
3015
|
constructor(args) {
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
_defineProperty(this, "feeCalculator", void 0);
|
|
3031
|
-
|
|
3016
|
+
this.authorizedPubkey = void 0;
|
|
3017
|
+
this.nonce = void 0;
|
|
3018
|
+
this.feeCalculator = void 0;
|
|
3032
3019
|
this.authorizedPubkey = args.authorizedPubkey;
|
|
3033
3020
|
this.nonce = args.nonce;
|
|
3034
3021
|
this.feeCalculator = args.feeCalculator;
|
|
@@ -3329,7 +3316,7 @@ class SystemInstruction {
|
|
|
3329
3316
|
|
|
3330
3317
|
static checkKeyLength(keys, expectedLength) {
|
|
3331
3318
|
if (keys.length < expectedLength) {
|
|
3332
|
-
throw new Error(
|
|
3319
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
3333
3320
|
}
|
|
3334
3321
|
}
|
|
3335
3322
|
|
|
@@ -3761,8 +3748,7 @@ class SystemProgram {
|
|
|
3761
3748
|
}
|
|
3762
3749
|
|
|
3763
3750
|
}
|
|
3764
|
-
|
|
3765
|
-
_defineProperty(SystemProgram, "programId", new PublicKey('11111111111111111111111111111111'));
|
|
3751
|
+
SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
|
|
3766
3752
|
|
|
3767
3753
|
// rest of the Transaction fields
|
|
3768
3754
|
//
|
|
@@ -3931,8 +3917,7 @@ class Loader {
|
|
|
3931
3917
|
}
|
|
3932
3918
|
|
|
3933
3919
|
}
|
|
3934
|
-
|
|
3935
|
-
_defineProperty(Loader, "chunkSize", CHUNK_SIZE);
|
|
3920
|
+
Loader.chunkSize = CHUNK_SIZE;
|
|
3936
3921
|
|
|
3937
3922
|
const BPF_LOADER_PROGRAM_ID = new PublicKey('BPFLoader2111111111111111111111111111111111');
|
|
3938
3923
|
/**
|
|
@@ -3983,14 +3968,10 @@ class AgentManager {
|
|
|
3983
3968
|
}
|
|
3984
3969
|
|
|
3985
3970
|
constructor(useHttps) {
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
_defineProperty(this, "_destroyTimeout", null);
|
|
3991
|
-
|
|
3992
|
-
_defineProperty(this, "_useHttps", void 0);
|
|
3993
|
-
|
|
3971
|
+
this._agent = void 0;
|
|
3972
|
+
this._activeRequests = 0;
|
|
3973
|
+
this._destroyTimeout = null;
|
|
3974
|
+
this._useHttps = void 0;
|
|
3994
3975
|
this._useHttps = useHttps === true;
|
|
3995
3976
|
this._agent = AgentManager._newAgent(this._useHttps);
|
|
3996
3977
|
}
|
|
@@ -4063,16 +4044,11 @@ class EpochSchedule {
|
|
|
4063
4044
|
|
|
4064
4045
|
/** The first slot of `firstNormalEpoch` */
|
|
4065
4046
|
constructor(slotsPerEpoch, leaderScheduleSlotOffset, warmup, firstNormalEpoch, firstNormalSlot) {
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
_defineProperty(this, "firstNormalEpoch", void 0);
|
|
4073
|
-
|
|
4074
|
-
_defineProperty(this, "firstNormalSlot", void 0);
|
|
4075
|
-
|
|
4047
|
+
this.slotsPerEpoch = void 0;
|
|
4048
|
+
this.leaderScheduleSlotOffset = void 0;
|
|
4049
|
+
this.warmup = void 0;
|
|
4050
|
+
this.firstNormalEpoch = void 0;
|
|
4051
|
+
this.firstNormalSlot = void 0;
|
|
4076
4052
|
this.slotsPerEpoch = slotsPerEpoch;
|
|
4077
4053
|
this.leaderScheduleSlotOffset = leaderScheduleSlotOffset;
|
|
4078
4054
|
this.warmup = warmup;
|
|
@@ -4124,9 +4100,7 @@ class EpochSchedule {
|
|
|
4124
4100
|
class SendTransactionError extends Error {
|
|
4125
4101
|
constructor(message, logs) {
|
|
4126
4102
|
super(message);
|
|
4127
|
-
|
|
4128
|
-
_defineProperty(this, "logs", void 0);
|
|
4129
|
-
|
|
4103
|
+
this.logs = void 0;
|
|
4130
4104
|
this.logs = logs;
|
|
4131
4105
|
}
|
|
4132
4106
|
|
|
@@ -4358,16 +4332,15 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4358
4332
|
let fetchWithMiddleware;
|
|
4359
4333
|
|
|
4360
4334
|
if (fetchMiddleware) {
|
|
4361
|
-
fetchWithMiddleware = (url, options) => {
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
}
|
|
4369
|
-
});
|
|
4335
|
+
fetchWithMiddleware = async (url, options) => {
|
|
4336
|
+
const modifiedFetchArgs = await new Promise((resolve, reject) => {
|
|
4337
|
+
try {
|
|
4338
|
+
fetchMiddleware(url, options, (modifiedUrl, modifiedOptions) => resolve([modifiedUrl, modifiedOptions]));
|
|
4339
|
+
} catch (error) {
|
|
4340
|
+
reject(error);
|
|
4341
|
+
}
|
|
4370
4342
|
});
|
|
4343
|
+
return await fetch(...modifiedFetchArgs);
|
|
4371
4344
|
};
|
|
4372
4345
|
}
|
|
4373
4346
|
|
|
@@ -4410,7 +4383,7 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4410
4383
|
break;
|
|
4411
4384
|
}
|
|
4412
4385
|
|
|
4413
|
-
console.log(
|
|
4386
|
+
console.log(`Server responded with ${res.status} ${res.statusText}. Retrying after ${waitTime}ms delay...`);
|
|
4414
4387
|
await sleep(waitTime);
|
|
4415
4388
|
waitTime *= 2;
|
|
4416
4389
|
}
|
|
@@ -4420,7 +4393,7 @@ function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRet
|
|
|
4420
4393
|
if (res.ok) {
|
|
4421
4394
|
callback(null, text);
|
|
4422
4395
|
} else {
|
|
4423
|
-
callback(new Error(
|
|
4396
|
+
callback(new Error(`${res.status} ${res.statusText}: ${text}`));
|
|
4424
4397
|
}
|
|
4425
4398
|
} catch (err) {
|
|
4426
4399
|
if (err instanceof Error) callback(err);
|
|
@@ -4861,6 +4834,7 @@ const ParsedConfirmedTransactionResult = type({
|
|
|
4861
4834
|
const TokenBalanceResult = type({
|
|
4862
4835
|
accountIndex: number(),
|
|
4863
4836
|
mint: string(),
|
|
4837
|
+
owner: optional(string()),
|
|
4864
4838
|
uiTokenAmount: TokenAmountResult
|
|
4865
4839
|
});
|
|
4866
4840
|
/**
|
|
@@ -4901,8 +4875,31 @@ const ParsedConfirmedTransactionMetaResult = type({
|
|
|
4901
4875
|
preTokenBalances: optional(nullable(array(TokenBalanceResult))),
|
|
4902
4876
|
postTokenBalances: optional(nullable(array(TokenBalanceResult)))
|
|
4903
4877
|
});
|
|
4878
|
+
/**
|
|
4879
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
4880
|
+
*/
|
|
4881
|
+
|
|
4882
|
+
const GetBlockRpcResult = jsonRpcResult(nullable(type({
|
|
4883
|
+
blockhash: string(),
|
|
4884
|
+
previousBlockhash: string(),
|
|
4885
|
+
parentSlot: number(),
|
|
4886
|
+
transactions: array(type({
|
|
4887
|
+
transaction: ConfirmedTransactionResult,
|
|
4888
|
+
meta: nullable(ConfirmedTransactionMetaResult)
|
|
4889
|
+
})),
|
|
4890
|
+
rewards: optional(array(type({
|
|
4891
|
+
pubkey: string(),
|
|
4892
|
+
lamports: number(),
|
|
4893
|
+
postBalance: nullable(number()),
|
|
4894
|
+
rewardType: nullable(string())
|
|
4895
|
+
}))),
|
|
4896
|
+
blockTime: nullable(number()),
|
|
4897
|
+
blockHeight: nullable(number())
|
|
4898
|
+
})));
|
|
4904
4899
|
/**
|
|
4905
4900
|
* Expected JSON RPC response for the "getConfirmedBlock" message
|
|
4901
|
+
*
|
|
4902
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetBlockRpcResult} instead.
|
|
4906
4903
|
*/
|
|
4907
4904
|
|
|
4908
4905
|
const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
|
|
@@ -4922,10 +4919,10 @@ const GetConfirmedBlockRpcResult = jsonRpcResult(nullable(type({
|
|
|
4922
4919
|
blockTime: nullable(number())
|
|
4923
4920
|
})));
|
|
4924
4921
|
/**
|
|
4925
|
-
* Expected JSON RPC response for the "
|
|
4922
|
+
* Expected JSON RPC response for the "getBlock" message
|
|
4926
4923
|
*/
|
|
4927
4924
|
|
|
4928
|
-
const
|
|
4925
|
+
const GetBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
|
|
4929
4926
|
blockhash: string(),
|
|
4930
4927
|
previousBlockhash: string(),
|
|
4931
4928
|
parentSlot: number(),
|
|
@@ -4933,20 +4930,20 @@ const GetConfirmedBlockSignaturesRpcResult = jsonRpcResult(nullable(type({
|
|
|
4933
4930
|
blockTime: nullable(number())
|
|
4934
4931
|
})));
|
|
4935
4932
|
/**
|
|
4936
|
-
* Expected JSON RPC response for the "
|
|
4933
|
+
* Expected JSON RPC response for the "getTransaction" message
|
|
4937
4934
|
*/
|
|
4938
4935
|
|
|
4939
|
-
const
|
|
4936
|
+
const GetTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
4940
4937
|
slot: number(),
|
|
4941
4938
|
meta: ConfirmedTransactionMetaResult,
|
|
4942
4939
|
blockTime: optional(nullable(number())),
|
|
4943
4940
|
transaction: ConfirmedTransactionResult
|
|
4944
4941
|
})));
|
|
4945
4942
|
/**
|
|
4946
|
-
* Expected JSON RPC response for the "
|
|
4943
|
+
* Expected parsed JSON RPC response for the "getTransaction" message
|
|
4947
4944
|
*/
|
|
4948
4945
|
|
|
4949
|
-
const
|
|
4946
|
+
const GetParsedTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
4950
4947
|
slot: number(),
|
|
4951
4948
|
transaction: ParsedConfirmedTransactionResult,
|
|
4952
4949
|
meta: nullable(ParsedConfirmedTransactionMetaResult),
|
|
@@ -4954,6 +4951,8 @@ const GetParsedConfirmedTransactionRpcResult = jsonRpcResult(nullable(type({
|
|
|
4954
4951
|
})));
|
|
4955
4952
|
/**
|
|
4956
4953
|
* Expected JSON RPC response for the "getRecentBlockhash" message
|
|
4954
|
+
*
|
|
4955
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link GetLatestBlockhashRpcResult} instead.
|
|
4957
4956
|
*/
|
|
4958
4957
|
|
|
4959
4958
|
const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
|
|
@@ -4962,6 +4961,14 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(type({
|
|
|
4962
4961
|
lamportsPerSignature: number()
|
|
4963
4962
|
})
|
|
4964
4963
|
}));
|
|
4964
|
+
/**
|
|
4965
|
+
* Expected JSON RPC response for the "getLatestBlockhash" message
|
|
4966
|
+
*/
|
|
4967
|
+
|
|
4968
|
+
const GetLatestBlockhashRpcResult = jsonRpcResultAndContext(type({
|
|
4969
|
+
blockhash: string(),
|
|
4970
|
+
lastValidBlockHeight: number()
|
|
4971
|
+
}));
|
|
4965
4972
|
const PerfSampleResult = type({
|
|
4966
4973
|
slot: number(),
|
|
4967
4974
|
numTransactions: number(),
|
|
@@ -5086,67 +5093,39 @@ class Connection {
|
|
|
5086
5093
|
* @param commitmentOrConfig optional default commitment level or optional ConnectionConfig configuration object
|
|
5087
5094
|
*/
|
|
5088
5095
|
constructor(endpoint, commitmentOrConfig) {
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
_defineProperty(this, "_rpcWebSocket", void 0);
|
|
5104
|
-
|
|
5105
|
-
_defineProperty(this, "_rpcWebSocketConnected", false);
|
|
5106
|
-
|
|
5107
|
-
_defineProperty(this, "_rpcWebSocketHeartbeat", null);
|
|
5108
|
-
|
|
5109
|
-
_defineProperty(this, "_rpcWebSocketIdleTimeout", null);
|
|
5110
|
-
|
|
5111
|
-
_defineProperty(this, "_disableBlockhashCaching", false);
|
|
5112
|
-
|
|
5113
|
-
_defineProperty(this, "_pollingBlockhash", false);
|
|
5114
|
-
|
|
5115
|
-
_defineProperty(this, "_blockhashInfo", {
|
|
5096
|
+
this._commitment = void 0;
|
|
5097
|
+
this._confirmTransactionInitialTimeout = void 0;
|
|
5098
|
+
this._rpcEndpoint = void 0;
|
|
5099
|
+
this._rpcWsEndpoint = void 0;
|
|
5100
|
+
this._rpcClient = void 0;
|
|
5101
|
+
this._rpcRequest = void 0;
|
|
5102
|
+
this._rpcBatchRequest = void 0;
|
|
5103
|
+
this._rpcWebSocket = void 0;
|
|
5104
|
+
this._rpcWebSocketConnected = false;
|
|
5105
|
+
this._rpcWebSocketHeartbeat = null;
|
|
5106
|
+
this._rpcWebSocketIdleTimeout = null;
|
|
5107
|
+
this._disableBlockhashCaching = false;
|
|
5108
|
+
this._pollingBlockhash = false;
|
|
5109
|
+
this._blockhashInfo = {
|
|
5116
5110
|
recentBlockhash: null,
|
|
5117
5111
|
lastFetch: 0,
|
|
5118
5112
|
transactionSignatures: [],
|
|
5119
5113
|
simulatedSignatures: []
|
|
5120
|
-
}
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5128
|
-
|
|
5129
|
-
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
|
|
5134
|
-
|
|
5135
|
-
|
|
5136
|
-
_defineProperty(this, "_signatureSubscriptions", {});
|
|
5137
|
-
|
|
5138
|
-
_defineProperty(this, "_slotSubscriptionCounter", 0);
|
|
5139
|
-
|
|
5140
|
-
_defineProperty(this, "_slotSubscriptions", {});
|
|
5141
|
-
|
|
5142
|
-
_defineProperty(this, "_logsSubscriptionCounter", 0);
|
|
5143
|
-
|
|
5144
|
-
_defineProperty(this, "_logsSubscriptions", {});
|
|
5145
|
-
|
|
5146
|
-
_defineProperty(this, "_slotUpdateSubscriptionCounter", 0);
|
|
5147
|
-
|
|
5148
|
-
_defineProperty(this, "_slotUpdateSubscriptions", {});
|
|
5149
|
-
|
|
5114
|
+
};
|
|
5115
|
+
this._accountChangeSubscriptionCounter = 0;
|
|
5116
|
+
this._accountChangeSubscriptions = {};
|
|
5117
|
+
this._programAccountChangeSubscriptionCounter = 0;
|
|
5118
|
+
this._programAccountChangeSubscriptions = {};
|
|
5119
|
+
this._rootSubscriptionCounter = 0;
|
|
5120
|
+
this._rootSubscriptions = {};
|
|
5121
|
+
this._signatureSubscriptionCounter = 0;
|
|
5122
|
+
this._signatureSubscriptions = {};
|
|
5123
|
+
this._slotSubscriptionCounter = 0;
|
|
5124
|
+
this._slotSubscriptions = {};
|
|
5125
|
+
this._logsSubscriptionCounter = 0;
|
|
5126
|
+
this._logsSubscriptions = {};
|
|
5127
|
+
this._slotUpdateSubscriptionCounter = 0;
|
|
5128
|
+
this._slotUpdateSubscriptions = {};
|
|
5150
5129
|
let url = new URL(endpoint);
|
|
5151
5130
|
const useHttps = url.protocol === 'https:';
|
|
5152
5131
|
let wsEndpoint;
|
|
@@ -5492,13 +5471,25 @@ class Connection {
|
|
|
5492
5471
|
*/
|
|
5493
5472
|
|
|
5494
5473
|
|
|
5495
|
-
async getMultipleAccountsInfo(publicKeys,
|
|
5474
|
+
async getMultipleAccountsInfo(publicKeys, configOrCommitment) {
|
|
5496
5475
|
const keys = publicKeys.map(key => key.toBase58());
|
|
5476
|
+
let commitment;
|
|
5477
|
+
let encoding = 'base64';
|
|
5478
|
+
|
|
5479
|
+
if (configOrCommitment) {
|
|
5480
|
+
if (typeof configOrCommitment === 'string') {
|
|
5481
|
+
commitment = configOrCommitment;
|
|
5482
|
+
encoding = 'base64';
|
|
5483
|
+
} else {
|
|
5484
|
+
commitment = configOrCommitment.commitment;
|
|
5485
|
+
encoding = configOrCommitment.encoding || 'base64';
|
|
5486
|
+
}
|
|
5487
|
+
}
|
|
5497
5488
|
|
|
5498
|
-
const args = this._buildArgs([keys], commitment,
|
|
5489
|
+
const args = this._buildArgs([keys], commitment, encoding);
|
|
5499
5490
|
|
|
5500
5491
|
const unsafeRes = await this._rpcRequest('getMultipleAccounts', args);
|
|
5501
|
-
const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(
|
|
5492
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(array(nullable(ParsedAccountInfoResult))));
|
|
5502
5493
|
|
|
5503
5494
|
if ('error' in res) {
|
|
5504
5495
|
throw new Error('failed to get info for accounts ' + keys + ': ' + res.error.message);
|
|
@@ -5520,7 +5511,7 @@ class Connection {
|
|
|
5520
5511
|
const res = create(unsafeRes, jsonRpcResult(StakeActivationResult));
|
|
5521
5512
|
|
|
5522
5513
|
if ('error' in res) {
|
|
5523
|
-
throw new Error(
|
|
5514
|
+
throw new Error(`failed to get Stake Activation ${publicKey.toBase58()}: ${res.error.message}`);
|
|
5524
5515
|
}
|
|
5525
5516
|
|
|
5526
5517
|
return res.result;
|
|
@@ -5656,7 +5647,7 @@ class Connection {
|
|
|
5656
5647
|
|
|
5657
5648
|
if (response === null) {
|
|
5658
5649
|
const duration = (Date.now() - start) / 1000;
|
|
5659
|
-
throw new Error(
|
|
5650
|
+
throw new Error(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`);
|
|
5660
5651
|
}
|
|
5661
5652
|
|
|
5662
5653
|
return response;
|
|
@@ -5922,6 +5913,8 @@ class Connection {
|
|
|
5922
5913
|
/**
|
|
5923
5914
|
* Fetch a recent blockhash from the cluster, return with context
|
|
5924
5915
|
* @return {Promise<RpcResponseAndContext<{blockhash: Blockhash, feeCalculator: FeeCalculator}>>}
|
|
5916
|
+
*
|
|
5917
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
5925
5918
|
*/
|
|
5926
5919
|
|
|
5927
5920
|
|
|
@@ -5957,6 +5950,8 @@ class Connection {
|
|
|
5957
5950
|
}
|
|
5958
5951
|
/**
|
|
5959
5952
|
* Fetch the fee calculator for a recent blockhash from the cluster, return with context
|
|
5953
|
+
*
|
|
5954
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getFeeForMessage} instead.
|
|
5960
5955
|
*/
|
|
5961
5956
|
|
|
5962
5957
|
|
|
@@ -5979,9 +5974,34 @@ class Connection {
|
|
|
5979
5974
|
value: value !== null ? value.feeCalculator : null
|
|
5980
5975
|
};
|
|
5981
5976
|
}
|
|
5977
|
+
/**
|
|
5978
|
+
* Fetch the fee for a message from the cluster, return with context
|
|
5979
|
+
*/
|
|
5980
|
+
|
|
5981
|
+
|
|
5982
|
+
async getFeeForMessage(message, commitment) {
|
|
5983
|
+
const wireMessage = message.serialize().toString('base64');
|
|
5984
|
+
|
|
5985
|
+
const args = this._buildArgs([wireMessage], commitment);
|
|
5986
|
+
|
|
5987
|
+
const unsafeRes = await this._rpcRequest('getFeeForMessage', args);
|
|
5988
|
+
const res = create(unsafeRes, jsonRpcResultAndContext(nullable(number())));
|
|
5989
|
+
|
|
5990
|
+
if ('error' in res) {
|
|
5991
|
+
throw new Error('failed to get slot: ' + res.error.message);
|
|
5992
|
+
}
|
|
5993
|
+
|
|
5994
|
+
if (res.result === null) {
|
|
5995
|
+
throw new Error('invalid blockhash');
|
|
5996
|
+
}
|
|
5997
|
+
|
|
5998
|
+
return res.result;
|
|
5999
|
+
}
|
|
5982
6000
|
/**
|
|
5983
6001
|
* Fetch a recent blockhash from the cluster
|
|
5984
6002
|
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}
|
|
6003
|
+
*
|
|
6004
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getLatestBlockhash} instead.
|
|
5985
6005
|
*/
|
|
5986
6006
|
|
|
5987
6007
|
|
|
@@ -5993,6 +6013,38 @@ class Connection {
|
|
|
5993
6013
|
throw new Error('failed to get recent blockhash: ' + e);
|
|
5994
6014
|
}
|
|
5995
6015
|
}
|
|
6016
|
+
/**
|
|
6017
|
+
* Fetch the latest blockhash from the cluster
|
|
6018
|
+
* @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
|
|
6019
|
+
*/
|
|
6020
|
+
|
|
6021
|
+
|
|
6022
|
+
async getLatestBlockhash(commitment) {
|
|
6023
|
+
try {
|
|
6024
|
+
const res = await this.getLatestBlockhashAndContext(commitment);
|
|
6025
|
+
return res.value;
|
|
6026
|
+
} catch (e) {
|
|
6027
|
+
throw new Error('failed to get recent blockhash: ' + e);
|
|
6028
|
+
}
|
|
6029
|
+
}
|
|
6030
|
+
/**
|
|
6031
|
+
* Fetch the latest blockhash from the cluster
|
|
6032
|
+
* @return {Promise<{blockhash: Blockhash, lastValidBlockHeight: number}>}
|
|
6033
|
+
*/
|
|
6034
|
+
|
|
6035
|
+
|
|
6036
|
+
async getLatestBlockhashAndContext(commitment) {
|
|
6037
|
+
const args = this._buildArgs([], commitment);
|
|
6038
|
+
|
|
6039
|
+
const unsafeRes = await this._rpcRequest('getLatestBlockhash', args);
|
|
6040
|
+
const res = create(unsafeRes, GetLatestBlockhashRpcResult);
|
|
6041
|
+
|
|
6042
|
+
if ('error' in res) {
|
|
6043
|
+
throw new Error('failed to get latest blockhash: ' + res.error.message);
|
|
6044
|
+
}
|
|
6045
|
+
|
|
6046
|
+
return res.result;
|
|
6047
|
+
}
|
|
5996
6048
|
/**
|
|
5997
6049
|
* Fetch the node version
|
|
5998
6050
|
*/
|
|
@@ -6031,8 +6083,8 @@ class Connection {
|
|
|
6031
6083
|
async getBlock(slot, opts) {
|
|
6032
6084
|
const args = this._buildArgsAtLeastConfirmed([slot], opts && opts.commitment);
|
|
6033
6085
|
|
|
6034
|
-
const unsafeRes = await this._rpcRequest('
|
|
6035
|
-
const res = create(unsafeRes,
|
|
6086
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6087
|
+
const res = create(unsafeRes, GetBlockRpcResult);
|
|
6036
6088
|
|
|
6037
6089
|
if ('error' in res) {
|
|
6038
6090
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6056,18 +6108,18 @@ class Connection {
|
|
|
6056
6108
|
};
|
|
6057
6109
|
}
|
|
6058
6110
|
/**
|
|
6059
|
-
* Fetch a
|
|
6111
|
+
* Fetch a confirmed or finalized transaction from the cluster.
|
|
6060
6112
|
*/
|
|
6061
6113
|
|
|
6062
6114
|
|
|
6063
6115
|
async getTransaction(signature, opts) {
|
|
6064
6116
|
const args = this._buildArgsAtLeastConfirmed([signature], opts && opts.commitment);
|
|
6065
6117
|
|
|
6066
|
-
const unsafeRes = await this._rpcRequest('
|
|
6067
|
-
const res = create(unsafeRes,
|
|
6118
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6119
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
6068
6120
|
|
|
6069
6121
|
if ('error' in res) {
|
|
6070
|
-
throw new Error('failed to get
|
|
6122
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6071
6123
|
}
|
|
6072
6124
|
|
|
6073
6125
|
const result = res.result;
|
|
@@ -6078,6 +6130,49 @@ class Connection {
|
|
|
6078
6130
|
}
|
|
6079
6131
|
};
|
|
6080
6132
|
}
|
|
6133
|
+
/**
|
|
6134
|
+
* Fetch parsed transaction details for a confirmed or finalized transaction
|
|
6135
|
+
*/
|
|
6136
|
+
|
|
6137
|
+
|
|
6138
|
+
async getParsedTransaction(signature, commitment) {
|
|
6139
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6140
|
+
|
|
6141
|
+
const unsafeRes = await this._rpcRequest('getTransaction', args);
|
|
6142
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6143
|
+
|
|
6144
|
+
if ('error' in res) {
|
|
6145
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6146
|
+
}
|
|
6147
|
+
|
|
6148
|
+
return res.result;
|
|
6149
|
+
}
|
|
6150
|
+
/**
|
|
6151
|
+
* Fetch parsed transaction details for a batch of confirmed transactions
|
|
6152
|
+
*/
|
|
6153
|
+
|
|
6154
|
+
|
|
6155
|
+
async getParsedTransactions(signatures, commitment) {
|
|
6156
|
+
const batch = signatures.map(signature => {
|
|
6157
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6158
|
+
|
|
6159
|
+
return {
|
|
6160
|
+
methodName: 'getTransaction',
|
|
6161
|
+
args
|
|
6162
|
+
};
|
|
6163
|
+
});
|
|
6164
|
+
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
6165
|
+
const res = unsafeRes.map(unsafeRes => {
|
|
6166
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6167
|
+
|
|
6168
|
+
if ('error' in res) {
|
|
6169
|
+
throw new Error('failed to get transactions: ' + res.error.message);
|
|
6170
|
+
}
|
|
6171
|
+
|
|
6172
|
+
return res.result;
|
|
6173
|
+
});
|
|
6174
|
+
return res;
|
|
6175
|
+
}
|
|
6081
6176
|
/**
|
|
6082
6177
|
* Fetch a list of Transactions and transaction statuses from the cluster
|
|
6083
6178
|
* for a confirmed block.
|
|
@@ -6087,18 +6182,39 @@ class Connection {
|
|
|
6087
6182
|
|
|
6088
6183
|
|
|
6089
6184
|
async getConfirmedBlock(slot, commitment) {
|
|
6090
|
-
const
|
|
6091
|
-
|
|
6092
|
-
|
|
6185
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment);
|
|
6186
|
+
|
|
6187
|
+
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
6188
|
+
const res = create(unsafeRes, GetConfirmedBlockRpcResult);
|
|
6189
|
+
|
|
6190
|
+
if ('error' in res) {
|
|
6191
|
+
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
6192
|
+
}
|
|
6193
|
+
|
|
6194
|
+
const result = res.result;
|
|
6093
6195
|
|
|
6094
6196
|
if (!result) {
|
|
6095
6197
|
throw new Error('Confirmed block ' + slot + ' not found');
|
|
6096
6198
|
}
|
|
6097
6199
|
|
|
6098
|
-
|
|
6200
|
+
const block = { ...result,
|
|
6099
6201
|
transactions: result.transactions.map(({
|
|
6100
6202
|
transaction,
|
|
6101
6203
|
meta
|
|
6204
|
+
}) => {
|
|
6205
|
+
const message = new Message(transaction.message);
|
|
6206
|
+
return {
|
|
6207
|
+
meta,
|
|
6208
|
+
transaction: { ...transaction,
|
|
6209
|
+
message
|
|
6210
|
+
}
|
|
6211
|
+
};
|
|
6212
|
+
})
|
|
6213
|
+
};
|
|
6214
|
+
return { ...block,
|
|
6215
|
+
transactions: block.transactions.map(({
|
|
6216
|
+
transaction,
|
|
6217
|
+
meta
|
|
6102
6218
|
}) => {
|
|
6103
6219
|
return {
|
|
6104
6220
|
meta,
|
|
@@ -6115,7 +6231,7 @@ class Connection {
|
|
|
6115
6231
|
async getBlocks(startSlot, endSlot, commitment) {
|
|
6116
6232
|
const args = this._buildArgsAtLeastConfirmed(endSlot !== undefined ? [startSlot, endSlot] : [startSlot], commitment);
|
|
6117
6233
|
|
|
6118
|
-
const unsafeRes = await this._rpcRequest('
|
|
6234
|
+
const unsafeRes = await this._rpcRequest('getBlocks', args);
|
|
6119
6235
|
const res = create(unsafeRes, jsonRpcResult(array(number())));
|
|
6120
6236
|
|
|
6121
6237
|
if ('error' in res) {
|
|
@@ -6124,8 +6240,36 @@ class Connection {
|
|
|
6124
6240
|
|
|
6125
6241
|
return res.result;
|
|
6126
6242
|
}
|
|
6243
|
+
/**
|
|
6244
|
+
* Fetch a list of Signatures from the cluster for a block, excluding rewards
|
|
6245
|
+
*/
|
|
6246
|
+
|
|
6247
|
+
|
|
6248
|
+
async getBlockSignatures(slot, commitment) {
|
|
6249
|
+
const args = this._buildArgsAtLeastConfirmed([slot], commitment, undefined, {
|
|
6250
|
+
transactionDetails: 'signatures',
|
|
6251
|
+
rewards: false
|
|
6252
|
+
});
|
|
6253
|
+
|
|
6254
|
+
const unsafeRes = await this._rpcRequest('getBlock', args);
|
|
6255
|
+
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
6256
|
+
|
|
6257
|
+
if ('error' in res) {
|
|
6258
|
+
throw new Error('failed to get block: ' + res.error.message);
|
|
6259
|
+
}
|
|
6260
|
+
|
|
6261
|
+
const result = res.result;
|
|
6262
|
+
|
|
6263
|
+
if (!result) {
|
|
6264
|
+
throw new Error('Block ' + slot + ' not found');
|
|
6265
|
+
}
|
|
6266
|
+
|
|
6267
|
+
return result;
|
|
6268
|
+
}
|
|
6127
6269
|
/**
|
|
6128
6270
|
* Fetch a list of Signatures from the cluster for a confirmed block, excluding rewards
|
|
6271
|
+
*
|
|
6272
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getBlockSignatures} instead.
|
|
6129
6273
|
*/
|
|
6130
6274
|
|
|
6131
6275
|
|
|
@@ -6136,7 +6280,7 @@ class Connection {
|
|
|
6136
6280
|
});
|
|
6137
6281
|
|
|
6138
6282
|
const unsafeRes = await this._rpcRequest('getConfirmedBlock', args);
|
|
6139
|
-
const res = create(unsafeRes,
|
|
6283
|
+
const res = create(unsafeRes, GetBlockSignaturesRpcResult);
|
|
6140
6284
|
|
|
6141
6285
|
if ('error' in res) {
|
|
6142
6286
|
throw new Error('failed to get confirmed block: ' + res.error.message);
|
|
@@ -6152,24 +6296,33 @@ class Connection {
|
|
|
6152
6296
|
}
|
|
6153
6297
|
/**
|
|
6154
6298
|
* Fetch a transaction details for a confirmed transaction
|
|
6299
|
+
*
|
|
6300
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getTransaction} instead.
|
|
6155
6301
|
*/
|
|
6156
6302
|
|
|
6157
6303
|
|
|
6158
6304
|
async getConfirmedTransaction(signature, commitment) {
|
|
6159
|
-
const
|
|
6160
|
-
|
|
6161
|
-
|
|
6305
|
+
const args = this._buildArgsAtLeastConfirmed([signature], commitment);
|
|
6306
|
+
|
|
6307
|
+
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
6308
|
+
const res = create(unsafeRes, GetTransactionRpcResult);
|
|
6309
|
+
|
|
6310
|
+
if ('error' in res) {
|
|
6311
|
+
throw new Error('failed to get transaction: ' + res.error.message);
|
|
6312
|
+
}
|
|
6313
|
+
|
|
6314
|
+
const result = res.result;
|
|
6162
6315
|
if (!result) return result;
|
|
6163
|
-
const
|
|
6164
|
-
|
|
6165
|
-
signatures
|
|
6166
|
-
} = result.transaction;
|
|
6316
|
+
const message = new Message(result.transaction.message);
|
|
6317
|
+
const signatures = result.transaction.signatures;
|
|
6167
6318
|
return { ...result,
|
|
6168
6319
|
transaction: Transaction.populate(message, signatures)
|
|
6169
6320
|
};
|
|
6170
6321
|
}
|
|
6171
6322
|
/**
|
|
6172
6323
|
* Fetch parsed transaction details for a confirmed transaction
|
|
6324
|
+
*
|
|
6325
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransaction} instead.
|
|
6173
6326
|
*/
|
|
6174
6327
|
|
|
6175
6328
|
|
|
@@ -6177,7 +6330,7 @@ class Connection {
|
|
|
6177
6330
|
const args = this._buildArgsAtLeastConfirmed([signature], commitment, 'jsonParsed');
|
|
6178
6331
|
|
|
6179
6332
|
const unsafeRes = await this._rpcRequest('getConfirmedTransaction', args);
|
|
6180
|
-
const res = create(unsafeRes,
|
|
6333
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6181
6334
|
|
|
6182
6335
|
if ('error' in res) {
|
|
6183
6336
|
throw new Error('failed to get confirmed transaction: ' + res.error.message);
|
|
@@ -6187,6 +6340,8 @@ class Connection {
|
|
|
6187
6340
|
}
|
|
6188
6341
|
/**
|
|
6189
6342
|
* Fetch parsed transaction details for a batch of confirmed transactions
|
|
6343
|
+
*
|
|
6344
|
+
* @deprecated Deprecated since Solana v1.8.0. Please use {@link getParsedTransactions} instead.
|
|
6190
6345
|
*/
|
|
6191
6346
|
|
|
6192
6347
|
|
|
@@ -6201,7 +6356,7 @@ class Connection {
|
|
|
6201
6356
|
});
|
|
6202
6357
|
const unsafeRes = await this._rpcBatchRequest(batch);
|
|
6203
6358
|
const res = unsafeRes.map(unsafeRes => {
|
|
6204
|
-
const res = create(unsafeRes,
|
|
6359
|
+
const res = create(unsafeRes, GetParsedTransactionRpcResult);
|
|
6205
6360
|
|
|
6206
6361
|
if ('error' in res) {
|
|
6207
6362
|
throw new Error('failed to get confirmed transactions: ' + res.error.message);
|
|
@@ -6430,7 +6585,7 @@ class Connection {
|
|
|
6430
6585
|
await sleep(MS_PER_SLOT / 2);
|
|
6431
6586
|
}
|
|
6432
6587
|
|
|
6433
|
-
throw new Error(
|
|
6588
|
+
throw new Error(`Unable to obtain a new blockhash after ${Date.now() - startTime}ms`);
|
|
6434
6589
|
} finally {
|
|
6435
6590
|
this._pollingBlockhash = false;
|
|
6436
6591
|
}
|
|
@@ -6591,6 +6746,10 @@ class Connection {
|
|
|
6591
6746
|
const skipPreflight = options && options.skipPreflight;
|
|
6592
6747
|
const preflightCommitment = options && options.preflightCommitment || this.commitment;
|
|
6593
6748
|
|
|
6749
|
+
if (options && options.maxRetries) {
|
|
6750
|
+
config.maxRetries = options.maxRetries;
|
|
6751
|
+
}
|
|
6752
|
+
|
|
6594
6753
|
if (skipPreflight) {
|
|
6595
6754
|
config.skipPreflight = skipPreflight;
|
|
6596
6755
|
}
|
|
@@ -6687,7 +6846,7 @@ class Connection {
|
|
|
6687
6846
|
}
|
|
6688
6847
|
|
|
6689
6848
|
if (err instanceof Error) {
|
|
6690
|
-
console.error(
|
|
6849
|
+
console.error(`${rpcMethod} error for argument`, rpcArgs, err.message);
|
|
6691
6850
|
}
|
|
6692
6851
|
}
|
|
6693
6852
|
}
|
|
@@ -6707,7 +6866,7 @@ class Connection {
|
|
|
6707
6866
|
await this._rpcWebSocket.call(rpcMethod, [unsubscribeId]);
|
|
6708
6867
|
} catch (err) {
|
|
6709
6868
|
if (err instanceof Error) {
|
|
6710
|
-
console.error(
|
|
6869
|
+
console.error(`${rpcMethod} error:`, err.message);
|
|
6711
6870
|
}
|
|
6712
6871
|
}
|
|
6713
6872
|
}
|
|
@@ -6872,7 +7031,7 @@ class Connection {
|
|
|
6872
7031
|
|
|
6873
7032
|
this._updateSubscriptions();
|
|
6874
7033
|
} else {
|
|
6875
|
-
throw new Error(
|
|
7034
|
+
throw new Error(`Unknown account change id: ${id}`);
|
|
6876
7035
|
}
|
|
6877
7036
|
}
|
|
6878
7037
|
/**
|
|
@@ -6938,7 +7097,7 @@ class Connection {
|
|
|
6938
7097
|
|
|
6939
7098
|
this._updateSubscriptions();
|
|
6940
7099
|
} else {
|
|
6941
|
-
throw new Error(
|
|
7100
|
+
throw new Error(`Unknown program account change id: ${id}`);
|
|
6942
7101
|
}
|
|
6943
7102
|
}
|
|
6944
7103
|
/**
|
|
@@ -6968,7 +7127,7 @@ class Connection {
|
|
|
6968
7127
|
|
|
6969
7128
|
async removeOnLogsListener(id) {
|
|
6970
7129
|
if (!this._logsSubscriptions[id]) {
|
|
6971
|
-
throw new Error(
|
|
7130
|
+
throw new Error(`Unknown logs id: ${id}`);
|
|
6972
7131
|
}
|
|
6973
7132
|
|
|
6974
7133
|
const subInfo = this._logsSubscriptions[id];
|
|
@@ -7044,7 +7203,7 @@ class Connection {
|
|
|
7044
7203
|
|
|
7045
7204
|
this._updateSubscriptions();
|
|
7046
7205
|
} else {
|
|
7047
|
-
throw new Error(
|
|
7206
|
+
throw new Error(`Unknown slot change id: ${id}`);
|
|
7048
7207
|
}
|
|
7049
7208
|
}
|
|
7050
7209
|
/**
|
|
@@ -7097,7 +7256,7 @@ class Connection {
|
|
|
7097
7256
|
|
|
7098
7257
|
this._updateSubscriptions();
|
|
7099
7258
|
} else {
|
|
7100
|
-
throw new Error(
|
|
7259
|
+
throw new Error(`Unknown slot update id: ${id}`);
|
|
7101
7260
|
}
|
|
7102
7261
|
}
|
|
7103
7262
|
|
|
@@ -7238,7 +7397,7 @@ class Connection {
|
|
|
7238
7397
|
|
|
7239
7398
|
this._updateSubscriptions();
|
|
7240
7399
|
} else {
|
|
7241
|
-
throw new Error(
|
|
7400
|
+
throw new Error(`Unknown signature result id: ${id}`);
|
|
7242
7401
|
}
|
|
7243
7402
|
}
|
|
7244
7403
|
/**
|
|
@@ -7290,7 +7449,7 @@ class Connection {
|
|
|
7290
7449
|
|
|
7291
7450
|
this._updateSubscriptions();
|
|
7292
7451
|
} else {
|
|
7293
|
-
throw new Error(
|
|
7452
|
+
throw new Error(`Unknown root change id: ${id}`);
|
|
7294
7453
|
}
|
|
7295
7454
|
}
|
|
7296
7455
|
|
|
@@ -7311,7 +7470,7 @@ class Keypair {
|
|
|
7311
7470
|
* @param keypair ed25519 keypair
|
|
7312
7471
|
*/
|
|
7313
7472
|
constructor(keypair) {
|
|
7314
|
-
|
|
7473
|
+
this._keypair = void 0;
|
|
7315
7474
|
|
|
7316
7475
|
if (keypair) {
|
|
7317
7476
|
this._keypair = keypair;
|
|
@@ -7415,8 +7574,8 @@ class Ed25519Program {
|
|
|
7415
7574
|
signature,
|
|
7416
7575
|
instructionIndex
|
|
7417
7576
|
} = params;
|
|
7418
|
-
assert(publicKey.length === PUBLIC_KEY_BYTES$1,
|
|
7419
|
-
assert(signature.length === SIGNATURE_BYTES,
|
|
7577
|
+
assert(publicKey.length === PUBLIC_KEY_BYTES$1, `Public Key must be ${PUBLIC_KEY_BYTES$1} bytes but received ${publicKey.length} bytes`);
|
|
7578
|
+
assert(signature.length === SIGNATURE_BYTES, `Signature must be ${SIGNATURE_BYTES} bytes but received ${signature.length} bytes`);
|
|
7420
7579
|
const publicKeyOffset = ED25519_INSTRUCTION_LAYOUT.span;
|
|
7421
7580
|
const signatureOffset = publicKeyOffset + publicKey.length;
|
|
7422
7581
|
const messageDataOffset = signatureOffset + signature.length;
|
|
@@ -7454,12 +7613,12 @@ class Ed25519Program {
|
|
|
7454
7613
|
message,
|
|
7455
7614
|
instructionIndex
|
|
7456
7615
|
} = params;
|
|
7457
|
-
assert(privateKey.length === PRIVATE_KEY_BYTES$1,
|
|
7616
|
+
assert(privateKey.length === PRIVATE_KEY_BYTES$1, `Private key must be ${PRIVATE_KEY_BYTES$1} bytes but received ${privateKey.length} bytes`);
|
|
7458
7617
|
|
|
7459
7618
|
try {
|
|
7460
7619
|
const keypair = Keypair.fromSecretKey(privateKey);
|
|
7461
7620
|
const publicKey = keypair.publicKey.toBytes();
|
|
7462
|
-
const signature =
|
|
7621
|
+
const signature = nacl.sign.detached(message, keypair.secretKey);
|
|
7463
7622
|
return this.createInstructionWithPublicKey({
|
|
7464
7623
|
publicKey,
|
|
7465
7624
|
message,
|
|
@@ -7467,13 +7626,12 @@ class Ed25519Program {
|
|
|
7467
7626
|
instructionIndex
|
|
7468
7627
|
});
|
|
7469
7628
|
} catch (error) {
|
|
7470
|
-
throw new Error(
|
|
7629
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
7471
7630
|
}
|
|
7472
7631
|
}
|
|
7473
7632
|
|
|
7474
7633
|
}
|
|
7475
|
-
|
|
7476
|
-
_defineProperty(Ed25519Program, "programId", new PublicKey('Ed25519SigVerify111111111111111111111111111'));
|
|
7634
|
+
Ed25519Program.programId = new PublicKey('Ed25519SigVerify111111111111111111111111111');
|
|
7477
7635
|
|
|
7478
7636
|
/**
|
|
7479
7637
|
* Address of the stake config account which configures the rate
|
|
@@ -7496,10 +7654,8 @@ class Authorized {
|
|
|
7496
7654
|
* @param withdrawer the withdraw authority
|
|
7497
7655
|
*/
|
|
7498
7656
|
constructor(staker, withdrawer) {
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
_defineProperty(this, "withdrawer", void 0);
|
|
7502
|
-
|
|
7657
|
+
this.staker = void 0;
|
|
7658
|
+
this.withdrawer = void 0;
|
|
7503
7659
|
this.staker = staker;
|
|
7504
7660
|
this.withdrawer = withdrawer;
|
|
7505
7661
|
}
|
|
@@ -7520,12 +7676,9 @@ class Lockup {
|
|
|
7520
7676
|
* Create a new Lockup object
|
|
7521
7677
|
*/
|
|
7522
7678
|
constructor(unixTimestamp, epoch, custodian) {
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
_defineProperty(this, "custodian", void 0);
|
|
7528
|
-
|
|
7679
|
+
this.unixTimestamp = void 0;
|
|
7680
|
+
this.epoch = void 0;
|
|
7681
|
+
this.custodian = void 0;
|
|
7529
7682
|
this.unixTimestamp = unixTimestamp;
|
|
7530
7683
|
this.epoch = epoch;
|
|
7531
7684
|
this.custodian = custodian;
|
|
@@ -7540,7 +7693,7 @@ class Lockup {
|
|
|
7540
7693
|
* Create stake account transaction params
|
|
7541
7694
|
*/
|
|
7542
7695
|
|
|
7543
|
-
|
|
7696
|
+
Lockup.default = new Lockup(0, 0, PublicKey.default);
|
|
7544
7697
|
|
|
7545
7698
|
/**
|
|
7546
7699
|
* Stake Instruction class
|
|
@@ -7753,7 +7906,7 @@ class StakeInstruction {
|
|
|
7753
7906
|
|
|
7754
7907
|
static checkKeyLength(keys, expectedLength) {
|
|
7755
7908
|
if (keys.length < expectedLength) {
|
|
7756
|
-
throw new Error(
|
|
7909
|
+
throw new Error(`invalid instruction; found ${keys.length} keys, expected at least ${expectedLength}`);
|
|
7757
7910
|
}
|
|
7758
7911
|
}
|
|
7759
7912
|
|
|
@@ -8228,10 +8381,8 @@ class StakeProgram {
|
|
|
8228
8381
|
}
|
|
8229
8382
|
|
|
8230
8383
|
}
|
|
8231
|
-
|
|
8232
|
-
|
|
8233
|
-
|
|
8234
|
-
_defineProperty(StakeProgram, "space", 200);
|
|
8384
|
+
StakeProgram.programId = new PublicKey('Stake11111111111111111111111111111111111111');
|
|
8385
|
+
StakeProgram.space = 200;
|
|
8235
8386
|
|
|
8236
8387
|
const {
|
|
8237
8388
|
publicKeyCreate,
|
|
@@ -8261,12 +8412,12 @@ class Secp256k1Program {
|
|
|
8261
8412
|
* @param {Buffer} publicKey a 64 byte secp256k1 public key buffer
|
|
8262
8413
|
*/
|
|
8263
8414
|
static publicKeyToEthAddress(publicKey) {
|
|
8264
|
-
assert(publicKey.length === PUBLIC_KEY_BYTES,
|
|
8415
|
+
assert(publicKey.length === PUBLIC_KEY_BYTES, `Public key must be ${PUBLIC_KEY_BYTES} bytes but received ${publicKey.length} bytes`);
|
|
8265
8416
|
|
|
8266
8417
|
try {
|
|
8267
|
-
return Buffer.from(keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8418
|
+
return Buffer.from(sha3.keccak_256.update(toBuffer(publicKey)).digest()).slice(-ETHEREUM_ADDRESS_BYTES);
|
|
8268
8419
|
} catch (error) {
|
|
8269
|
-
throw new Error(
|
|
8420
|
+
throw new Error(`Error constructing Ethereum address: ${error}`);
|
|
8270
8421
|
}
|
|
8271
8422
|
}
|
|
8272
8423
|
/**
|
|
@@ -8317,7 +8468,7 @@ class Secp256k1Program {
|
|
|
8317
8468
|
ethAddress = rawAddress;
|
|
8318
8469
|
}
|
|
8319
8470
|
|
|
8320
|
-
assert(ethAddress.length === ETHEREUM_ADDRESS_BYTES,
|
|
8471
|
+
assert(ethAddress.length === ETHEREUM_ADDRESS_BYTES, `Address must be ${ETHEREUM_ADDRESS_BYTES} bytes but received ${ethAddress.length} bytes`);
|
|
8321
8472
|
const dataStart = 1 + SIGNATURE_OFFSETS_SERIALIZED_SIZE;
|
|
8322
8473
|
const ethAddressOffset = dataStart;
|
|
8323
8474
|
const signatureOffset = dataStart + ethAddress.length;
|
|
@@ -8356,13 +8507,13 @@ class Secp256k1Program {
|
|
|
8356
8507
|
message,
|
|
8357
8508
|
instructionIndex
|
|
8358
8509
|
} = params;
|
|
8359
|
-
assert(pkey.length === PRIVATE_KEY_BYTES,
|
|
8510
|
+
assert(pkey.length === PRIVATE_KEY_BYTES, `Private key must be ${PRIVATE_KEY_BYTES} bytes but received ${pkey.length} bytes`);
|
|
8360
8511
|
|
|
8361
8512
|
try {
|
|
8362
8513
|
const privateKey = toBuffer(pkey);
|
|
8363
8514
|
const publicKey = publicKeyCreate(privateKey, false).slice(1); // throw away leading byte
|
|
8364
8515
|
|
|
8365
|
-
const messageHash = Buffer.from(keccak_256.update(toBuffer(message)).digest());
|
|
8516
|
+
const messageHash = Buffer.from(sha3.keccak_256.update(toBuffer(message)).digest());
|
|
8366
8517
|
const {
|
|
8367
8518
|
signature,
|
|
8368
8519
|
recid: recoveryId
|
|
@@ -8375,13 +8526,12 @@ class Secp256k1Program {
|
|
|
8375
8526
|
instructionIndex
|
|
8376
8527
|
});
|
|
8377
8528
|
} catch (error) {
|
|
8378
|
-
throw new Error(
|
|
8529
|
+
throw new Error(`Error creating instruction; ${error}`);
|
|
8379
8530
|
}
|
|
8380
8531
|
}
|
|
8381
8532
|
|
|
8382
8533
|
}
|
|
8383
|
-
|
|
8384
|
-
_defineProperty(Secp256k1Program, "programId", new PublicKey('KeccakSecp256k11111111111111111111111111111'));
|
|
8534
|
+
Secp256k1Program.programId = new PublicKey('KeccakSecp256k11111111111111111111111111111');
|
|
8385
8535
|
|
|
8386
8536
|
const VALIDATOR_INFO_KEY = new PublicKey('Va1idator1nfo111111111111111111111111111111');
|
|
8387
8537
|
/**
|
|
@@ -8414,10 +8564,8 @@ class ValidatorInfo {
|
|
|
8414
8564
|
* @param info validator information
|
|
8415
8565
|
*/
|
|
8416
8566
|
constructor(key, info) {
|
|
8417
|
-
|
|
8418
|
-
|
|
8419
|
-
_defineProperty(this, "info", void 0);
|
|
8420
|
-
|
|
8567
|
+
this.key = void 0;
|
|
8568
|
+
this.info = void 0;
|
|
8421
8569
|
this.key = key;
|
|
8422
8570
|
this.info = info;
|
|
8423
8571
|
}
|
|
@@ -8469,9 +8617,10 @@ const VOTE_PROGRAM_ID = new PublicKey('Vote1111111111111111111111111111111111111
|
|
|
8469
8617
|
*
|
|
8470
8618
|
* @internal
|
|
8471
8619
|
*/
|
|
8472
|
-
const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('
|
|
8473
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('slot'), BufferLayout.u32('confirmationCount')]), BufferLayout.offset(BufferLayout.u32(), -8), 'votes'), BufferLayout.u8('rootSlotValid'), BufferLayout.nu64('rootSlot'), BufferLayout.nu64(
|
|
8474
|
-
BufferLayout.seq(BufferLayout.struct([BufferLayout.nu64('epoch'), BufferLayout.nu64('
|
|
8620
|
+
const VoteAccountLayout = BufferLayout.struct([publicKey('nodePubkey'), publicKey('authorizedWithdrawer'), BufferLayout.u8('commission'), BufferLayout.nu64(), // votes.length
|
|
8621
|
+
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
|
|
8622
|
+
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
|
|
8623
|
+
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')]);
|
|
8475
8624
|
|
|
8476
8625
|
/**
|
|
8477
8626
|
* VoteAccount class
|
|
@@ -8481,36 +8630,24 @@ class VoteAccount {
|
|
|
8481
8630
|
* @internal
|
|
8482
8631
|
*/
|
|
8483
8632
|
constructor(args) {
|
|
8484
|
-
|
|
8485
|
-
|
|
8486
|
-
|
|
8487
|
-
|
|
8488
|
-
|
|
8489
|
-
|
|
8490
|
-
|
|
8491
|
-
|
|
8492
|
-
|
|
8493
|
-
|
|
8494
|
-
_defineProperty(this, "rootSlot", void 0);
|
|
8495
|
-
|
|
8496
|
-
_defineProperty(this, "epoch", void 0);
|
|
8497
|
-
|
|
8498
|
-
_defineProperty(this, "credits", void 0);
|
|
8499
|
-
|
|
8500
|
-
_defineProperty(this, "lastEpochCredits", void 0);
|
|
8501
|
-
|
|
8502
|
-
_defineProperty(this, "epochCredits", void 0);
|
|
8503
|
-
|
|
8633
|
+
this.nodePubkey = void 0;
|
|
8634
|
+
this.authorizedWithdrawer = void 0;
|
|
8635
|
+
this.commission = void 0;
|
|
8636
|
+
this.rootSlot = void 0;
|
|
8637
|
+
this.votes = void 0;
|
|
8638
|
+
this.authorizedVoters = void 0;
|
|
8639
|
+
this.priorVoters = void 0;
|
|
8640
|
+
this.epochCredits = void 0;
|
|
8641
|
+
this.lastTimestamp = void 0;
|
|
8504
8642
|
this.nodePubkey = args.nodePubkey;
|
|
8505
|
-
this.
|
|
8506
|
-
this.authorizedWithdrawerPubkey = args.authorizedWithdrawerPubkey;
|
|
8643
|
+
this.authorizedWithdrawer = args.authorizedWithdrawer;
|
|
8507
8644
|
this.commission = args.commission;
|
|
8508
|
-
this.votes = args.votes;
|
|
8509
8645
|
this.rootSlot = args.rootSlot;
|
|
8510
|
-
this.
|
|
8511
|
-
this.
|
|
8512
|
-
this.
|
|
8646
|
+
this.votes = args.votes;
|
|
8647
|
+
this.authorizedVoters = args.authorizedVoters;
|
|
8648
|
+
this.priorVoters = args.priorVoters;
|
|
8513
8649
|
this.epochCredits = args.epochCredits;
|
|
8650
|
+
this.lastTimestamp = args.lastTimestamp;
|
|
8514
8651
|
}
|
|
8515
8652
|
/**
|
|
8516
8653
|
* Deserialize VoteAccount from the account data.
|
|
@@ -8521,7 +8658,8 @@ class VoteAccount {
|
|
|
8521
8658
|
|
|
8522
8659
|
|
|
8523
8660
|
static fromAccountData(buffer) {
|
|
8524
|
-
const
|
|
8661
|
+
const versionOffset = 4;
|
|
8662
|
+
const va = VoteAccountLayout.decode(toBuffer(buffer), versionOffset);
|
|
8525
8663
|
let rootSlot = va.rootSlot;
|
|
8526
8664
|
|
|
8527
8665
|
if (!va.rootSlotValid) {
|
|
@@ -8530,20 +8668,53 @@ class VoteAccount {
|
|
|
8530
8668
|
|
|
8531
8669
|
return new VoteAccount({
|
|
8532
8670
|
nodePubkey: new PublicKey(va.nodePubkey),
|
|
8533
|
-
|
|
8534
|
-
authorizedWithdrawerPubkey: new PublicKey(va.authorizedWithdrawerPubkey),
|
|
8671
|
+
authorizedWithdrawer: new PublicKey(va.authorizedWithdrawer),
|
|
8535
8672
|
commission: va.commission,
|
|
8536
8673
|
votes: va.votes,
|
|
8537
8674
|
rootSlot,
|
|
8538
|
-
|
|
8539
|
-
|
|
8540
|
-
|
|
8541
|
-
|
|
8675
|
+
authorizedVoters: va.authorizedVoters.map(parseAuthorizedVoter),
|
|
8676
|
+
priorVoters: getPriorVoters(va.priorVoters),
|
|
8677
|
+
epochCredits: va.epochCredits,
|
|
8678
|
+
lastTimestamp: va.lastTimestamp
|
|
8542
8679
|
});
|
|
8543
8680
|
}
|
|
8544
8681
|
|
|
8545
8682
|
}
|
|
8546
8683
|
|
|
8684
|
+
function parseAuthorizedVoter({
|
|
8685
|
+
epoch,
|
|
8686
|
+
authorizedVoter
|
|
8687
|
+
}) {
|
|
8688
|
+
return {
|
|
8689
|
+
epoch,
|
|
8690
|
+
authorizedVoter: new PublicKey(authorizedVoter)
|
|
8691
|
+
};
|
|
8692
|
+
}
|
|
8693
|
+
|
|
8694
|
+
function parsePriorVoters({
|
|
8695
|
+
authorizedPubkey,
|
|
8696
|
+
epochOfLastAuthorizedSwitch,
|
|
8697
|
+
targetEpoch
|
|
8698
|
+
}) {
|
|
8699
|
+
return {
|
|
8700
|
+
authorizedPubkey: new PublicKey(authorizedPubkey),
|
|
8701
|
+
epochOfLastAuthorizedSwitch,
|
|
8702
|
+
targetEpoch
|
|
8703
|
+
};
|
|
8704
|
+
}
|
|
8705
|
+
|
|
8706
|
+
function getPriorVoters({
|
|
8707
|
+
buf,
|
|
8708
|
+
idx,
|
|
8709
|
+
isEmpty
|
|
8710
|
+
}) {
|
|
8711
|
+
if (isEmpty) {
|
|
8712
|
+
return [];
|
|
8713
|
+
}
|
|
8714
|
+
|
|
8715
|
+
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
8716
|
+
}
|
|
8717
|
+
|
|
8547
8718
|
/**
|
|
8548
8719
|
* Send and confirm a raw transaction
|
|
8549
8720
|
*
|
|
@@ -8563,7 +8734,7 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, options)
|
|
|
8563
8734
|
const status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
8564
8735
|
|
|
8565
8736
|
if (status.err) {
|
|
8566
|
-
throw new Error(
|
|
8737
|
+
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
8567
8738
|
}
|
|
8568
8739
|
|
|
8569
8740
|
return signature;
|
|
@@ -8573,12 +8744,12 @@ const endpoint = {
|
|
|
8573
8744
|
http: {
|
|
8574
8745
|
devnet: 'http://api.devnet.solana.com',
|
|
8575
8746
|
testnet: 'http://api.testnet.solana.com',
|
|
8576
|
-
'mainnet-beta': 'http://api.mainnet-beta.solana.com'
|
|
8747
|
+
'mainnet-beta': 'http://api.mainnet-beta.solana.com/'
|
|
8577
8748
|
},
|
|
8578
8749
|
https: {
|
|
8579
8750
|
devnet: 'https://api.devnet.solana.com',
|
|
8580
8751
|
testnet: 'https://api.testnet.solana.com',
|
|
8581
|
-
'mainnet-beta': 'https://api.mainnet-beta.solana.com'
|
|
8752
|
+
'mainnet-beta': 'https://api.mainnet-beta.solana.com/'
|
|
8582
8753
|
}
|
|
8583
8754
|
};
|
|
8584
8755
|
|
|
@@ -8595,7 +8766,7 @@ function clusterApiUrl(cluster, tls) {
|
|
|
8595
8766
|
const url = endpoint[key][cluster];
|
|
8596
8767
|
|
|
8597
8768
|
if (!url) {
|
|
8598
|
-
throw new Error(
|
|
8769
|
+
throw new Error(`Unknown ${key} cluster: ${cluster}`);
|
|
8599
8770
|
}
|
|
8600
8771
|
|
|
8601
8772
|
return url;
|
|
@@ -8607,5 +8778,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
8607
8778
|
|
|
8608
8779
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
8609
8780
|
|
|
8610
|
-
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 };
|
|
8781
|
+
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 };
|
|
8611
8782
|
//# sourceMappingURL=index.esm.js.map
|