@solana/web3.js 1.36.0 → 1.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.cjs.js +9846 -0
- package/lib/index.browser.cjs.js.map +1 -0
- package/lib/index.browser.esm.js +159 -45
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +160 -44
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +52 -13
- package/lib/index.esm.js +160 -44
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +1584 -1231
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +5 -4
- package/lib/index.iife.min.js.map +1 -1
- package/module.flow.js +83 -14
- package/package.json +5 -4
- package/src/connection.ts +95 -2
- package/src/ed25519-program.ts +21 -4
- package/src/instruction.ts +15 -5
- package/src/layout.ts +59 -19
- package/src/loader.ts +16 -3
- package/src/message.ts +21 -4
- package/src/nonce-account.ts +15 -2
- package/src/secp256k1-program.ts +15 -1
- package/src/stake-program.ts +83 -21
- package/src/system-program.ts +100 -36
- package/src/transaction.ts +8 -0
- package/src/vote-account.ts +55 -27
- package/src/vote-program.ts +37 -10
package/lib/index.cjs.js
CHANGED
|
@@ -81,32 +81,38 @@ var inherits_browser = {exports: {}};
|
|
|
81
81
|
if (typeof Object.create === 'function') {
|
|
82
82
|
// implementation from standard node.js 'util' module
|
|
83
83
|
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
if (superCtor) {
|
|
85
|
+
ctor.super_ = superCtor;
|
|
86
|
+
ctor.prototype = Object.create(superCtor.prototype, {
|
|
87
|
+
constructor: {
|
|
88
|
+
value: ctor,
|
|
89
|
+
enumerable: false,
|
|
90
|
+
writable: true,
|
|
91
|
+
configurable: true
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
93
95
|
};
|
|
94
96
|
} else {
|
|
95
97
|
// old school shim for old browsers
|
|
96
98
|
inherits_browser.exports = function inherits(ctor, superCtor) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
if (superCtor) {
|
|
100
|
+
ctor.super_ = superCtor;
|
|
101
|
+
var TempCtor = function () {};
|
|
102
|
+
TempCtor.prototype = superCtor.prototype;
|
|
103
|
+
ctor.prototype = new TempCtor();
|
|
104
|
+
ctor.prototype.constructor = ctor;
|
|
105
|
+
}
|
|
102
106
|
};
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
try {
|
|
106
110
|
var util = require('util');
|
|
111
|
+
/* istanbul ignore next */
|
|
107
112
|
if (typeof util.inherits !== 'function') throw '';
|
|
108
113
|
inherits$1.exports = util.inherits;
|
|
109
114
|
} catch (e) {
|
|
115
|
+
/* istanbul ignore next */
|
|
110
116
|
inherits$1.exports = inherits_browser.exports;
|
|
111
117
|
}
|
|
112
118
|
|
|
@@ -1319,7 +1325,7 @@ hash.ripemd160 = hash.ripemd.ripemd160;
|
|
|
1319
1325
|
|
|
1320
1326
|
var hash = hash$1;
|
|
1321
1327
|
|
|
1322
|
-
const version$2 = "logger/5.
|
|
1328
|
+
const version$2 = "logger/5.6.0";
|
|
1323
1329
|
|
|
1324
1330
|
let _permanentCensorErrors = false;
|
|
1325
1331
|
let _censorErrors = false;
|
|
@@ -1498,6 +1504,40 @@ class Logger {
|
|
|
1498
1504
|
messageDetails.push(`code=${code}`);
|
|
1499
1505
|
messageDetails.push(`version=${this.version}`);
|
|
1500
1506
|
const reason = message;
|
|
1507
|
+
let url = "";
|
|
1508
|
+
switch (code) {
|
|
1509
|
+
case ErrorCode.NUMERIC_FAULT: {
|
|
1510
|
+
url = "NUMERIC_FAULT";
|
|
1511
|
+
const fault = message;
|
|
1512
|
+
switch (fault) {
|
|
1513
|
+
case "overflow":
|
|
1514
|
+
case "underflow":
|
|
1515
|
+
case "division-by-zero":
|
|
1516
|
+
url += "-" + fault;
|
|
1517
|
+
break;
|
|
1518
|
+
case "negative-power":
|
|
1519
|
+
case "negative-width":
|
|
1520
|
+
url += "-unsupported";
|
|
1521
|
+
break;
|
|
1522
|
+
case "unbound-bitwise-result":
|
|
1523
|
+
url += "-unbound-result";
|
|
1524
|
+
break;
|
|
1525
|
+
}
|
|
1526
|
+
break;
|
|
1527
|
+
}
|
|
1528
|
+
case ErrorCode.CALL_EXCEPTION:
|
|
1529
|
+
case ErrorCode.INSUFFICIENT_FUNDS:
|
|
1530
|
+
case ErrorCode.MISSING_NEW:
|
|
1531
|
+
case ErrorCode.NONCE_EXPIRED:
|
|
1532
|
+
case ErrorCode.REPLACEMENT_UNDERPRICED:
|
|
1533
|
+
case ErrorCode.TRANSACTION_REPLACED:
|
|
1534
|
+
case ErrorCode.UNPREDICTABLE_GAS_LIMIT:
|
|
1535
|
+
url = code;
|
|
1536
|
+
break;
|
|
1537
|
+
}
|
|
1538
|
+
if (url) {
|
|
1539
|
+
message += " [ See: https:/\/links.ethers.org/v5-errors-" + url + " ]";
|
|
1540
|
+
}
|
|
1501
1541
|
if (messageDetails.length) {
|
|
1502
1542
|
message += " (" + messageDetails.join(", ") + ")";
|
|
1503
1543
|
}
|
|
@@ -1631,7 +1671,7 @@ class Logger {
|
|
|
1631
1671
|
Logger.errors = ErrorCode;
|
|
1632
1672
|
Logger.levels = LogLevel;
|
|
1633
1673
|
|
|
1634
|
-
const version$1 = "bytes/5.
|
|
1674
|
+
const version$1 = "bytes/5.6.0";
|
|
1635
1675
|
|
|
1636
1676
|
const logger = new Logger(version$1);
|
|
1637
1677
|
///////////////////////////////
|
|
@@ -1728,7 +1768,7 @@ function isHexString(value, length) {
|
|
|
1728
1768
|
return true;
|
|
1729
1769
|
}
|
|
1730
1770
|
|
|
1731
|
-
const version = "sha2/5.
|
|
1771
|
+
const version = "sha2/5.6.0";
|
|
1732
1772
|
|
|
1733
1773
|
new Logger(version);
|
|
1734
1774
|
function sha256(data) {
|
|
@@ -2066,10 +2106,10 @@ const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader111111111111111
|
|
|
2066
2106
|
const publicKey = (property = 'publicKey') => {
|
|
2067
2107
|
return BufferLayout__namespace.blob(32, property);
|
|
2068
2108
|
};
|
|
2109
|
+
|
|
2069
2110
|
/**
|
|
2070
2111
|
* Layout for a Rust String type
|
|
2071
2112
|
*/
|
|
2072
|
-
|
|
2073
2113
|
const rustString = (property = 'string') => {
|
|
2074
2114
|
const rsl = BufferLayout__namespace.struct([BufferLayout__namespace.u32('length'), BufferLayout__namespace.u32('lengthPadding'), BufferLayout__namespace.blob(BufferLayout__namespace.offset(BufferLayout__namespace.u32(), -8), 'chars')], property);
|
|
2075
2115
|
|
|
@@ -2077,24 +2117,26 @@ const rustString = (property = 'string') => {
|
|
|
2077
2117
|
|
|
2078
2118
|
const _encode = rsl.encode.bind(rsl);
|
|
2079
2119
|
|
|
2080
|
-
|
|
2081
|
-
|
|
2120
|
+
const rslShim = rsl;
|
|
2121
|
+
|
|
2122
|
+
rslShim.decode = (b, offset) => {
|
|
2123
|
+
const data = _decode(b, offset);
|
|
2082
2124
|
|
|
2083
|
-
return data['chars'].toString(
|
|
2125
|
+
return data['chars'].toString();
|
|
2084
2126
|
};
|
|
2085
2127
|
|
|
2086
|
-
|
|
2128
|
+
rslShim.encode = (str, b, offset) => {
|
|
2087
2129
|
const data = {
|
|
2088
2130
|
chars: buffer.Buffer.from(str, 'utf8')
|
|
2089
2131
|
};
|
|
2090
|
-
return _encode(data,
|
|
2132
|
+
return _encode(data, b, offset);
|
|
2091
2133
|
};
|
|
2092
2134
|
|
|
2093
|
-
|
|
2135
|
+
rslShim.alloc = str => {
|
|
2094
2136
|
return BufferLayout__namespace.u32().span + BufferLayout__namespace.u32().span + buffer.Buffer.from(str, 'utf8').length;
|
|
2095
2137
|
};
|
|
2096
2138
|
|
|
2097
|
-
return
|
|
2139
|
+
return rslShim;
|
|
2098
2140
|
};
|
|
2099
2141
|
/**
|
|
2100
2142
|
* Layout for an Authorized object
|
|
@@ -2214,7 +2256,7 @@ class Message {
|
|
|
2214
2256
|
accounts,
|
|
2215
2257
|
programIdIndex
|
|
2216
2258
|
} = instruction;
|
|
2217
|
-
const data = bs58__default["default"].decode(instruction.data);
|
|
2259
|
+
const data = Array.from(bs58__default["default"].decode(instruction.data));
|
|
2218
2260
|
let keyIndicesCount = [];
|
|
2219
2261
|
encodeLength(keyIndicesCount, accounts.length);
|
|
2220
2262
|
let dataCount = [];
|
|
@@ -2222,7 +2264,7 @@ class Message {
|
|
|
2222
2264
|
return {
|
|
2223
2265
|
programIdIndex,
|
|
2224
2266
|
keyIndicesCount: buffer.Buffer.from(keyIndicesCount),
|
|
2225
|
-
keyIndices:
|
|
2267
|
+
keyIndices: accounts,
|
|
2226
2268
|
dataLength: buffer.Buffer.from(dataCount),
|
|
2227
2269
|
data
|
|
2228
2270
|
};
|
|
@@ -2626,6 +2668,14 @@ class Transaction {
|
|
|
2626
2668
|
serializeMessage() {
|
|
2627
2669
|
return this._compile().serialize();
|
|
2628
2670
|
}
|
|
2671
|
+
/**
|
|
2672
|
+
* Get the estimated fee associated with a transaction
|
|
2673
|
+
*/
|
|
2674
|
+
|
|
2675
|
+
|
|
2676
|
+
async getEstimatedFee(connection) {
|
|
2677
|
+
return (await connection.getFeeForMessage(this.compileMessage())).value;
|
|
2678
|
+
}
|
|
2629
2679
|
/**
|
|
2630
2680
|
* Specify the public keys which will be used to sign the Transaction.
|
|
2631
2681
|
* The first signer will be used as the transaction fee payer account.
|
|
@@ -2989,10 +3039,6 @@ function sleep(ms) {
|
|
|
2989
3039
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
2990
3040
|
}
|
|
2991
3041
|
|
|
2992
|
-
/**
|
|
2993
|
-
* @internal
|
|
2994
|
-
*/
|
|
2995
|
-
|
|
2996
3042
|
/**
|
|
2997
3043
|
* Populate a buffer of instruction data using an InstructionType
|
|
2998
3044
|
* @internal
|
|
@@ -3792,11 +3838,11 @@ class SystemProgram {
|
|
|
3792
3838
|
}
|
|
3793
3839
|
SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
|
|
3794
3840
|
|
|
3841
|
+
// Keep program chunks under PACKET_DATA_SIZE, leaving enough room for the
|
|
3795
3842
|
// rest of the Transaction fields
|
|
3796
3843
|
//
|
|
3797
3844
|
// TODO: replace 300 with a proper constant for the size of the other
|
|
3798
3845
|
// Transaction fields
|
|
3799
|
-
|
|
3800
3846
|
const CHUNK_SIZE = PACKET_DATA_SIZE - 300;
|
|
3801
3847
|
/**
|
|
3802
3848
|
* Program loader interface
|
|
@@ -3904,7 +3950,9 @@ class Loader {
|
|
|
3904
3950
|
instruction: 0,
|
|
3905
3951
|
// Load instruction
|
|
3906
3952
|
offset,
|
|
3907
|
-
bytes
|
|
3953
|
+
bytes: bytes,
|
|
3954
|
+
bytesLength: 0,
|
|
3955
|
+
bytesLengthPadding: 0
|
|
3908
3956
|
}, data);
|
|
3909
3957
|
const transaction = new Transaction().add({
|
|
3910
3958
|
keys: [{
|
|
@@ -4364,6 +4412,20 @@ const SimulatedTransactionResponseStruct = jsonRpcResultAndContext(superstruct.t
|
|
|
4364
4412
|
unitsConsumed: superstruct.optional(superstruct.number())
|
|
4365
4413
|
}));
|
|
4366
4414
|
|
|
4415
|
+
/**
|
|
4416
|
+
* Expected JSON RPC response for the "getBlockProduction" message
|
|
4417
|
+
*/
|
|
4418
|
+
const BlockProductionResponseStruct = jsonRpcResultAndContext(superstruct.type({
|
|
4419
|
+
byIdentity: superstruct.record(superstruct.string(), superstruct.array(superstruct.number())),
|
|
4420
|
+
range: superstruct.type({
|
|
4421
|
+
firstSlot: superstruct.number(),
|
|
4422
|
+
lastSlot: superstruct.number()
|
|
4423
|
+
})
|
|
4424
|
+
}));
|
|
4425
|
+
/**
|
|
4426
|
+
* A performance sample
|
|
4427
|
+
*/
|
|
4428
|
+
|
|
4367
4429
|
function createRpcClient(url, useHttps, httpHeaders, fetchMiddleware, disableRetryOnRateLimit) {
|
|
4368
4430
|
let agentManager;
|
|
4369
4431
|
|
|
@@ -5224,6 +5286,14 @@ class Connection {
|
|
|
5224
5286
|
get commitment() {
|
|
5225
5287
|
return this._commitment;
|
|
5226
5288
|
}
|
|
5289
|
+
/**
|
|
5290
|
+
* The RPC endpoint
|
|
5291
|
+
*/
|
|
5292
|
+
|
|
5293
|
+
|
|
5294
|
+
get rpcEndpoint() {
|
|
5295
|
+
return this._rpcEndpoint;
|
|
5296
|
+
}
|
|
5227
5297
|
/**
|
|
5228
5298
|
* Fetch the balance for the specified public key, return with context
|
|
5229
5299
|
*/
|
|
@@ -6146,6 +6216,54 @@ class Connection {
|
|
|
6146
6216
|
})
|
|
6147
6217
|
};
|
|
6148
6218
|
}
|
|
6219
|
+
/*
|
|
6220
|
+
* Returns the current block height of the node
|
|
6221
|
+
*/
|
|
6222
|
+
|
|
6223
|
+
|
|
6224
|
+
async getBlockHeight(commitment) {
|
|
6225
|
+
const args = this._buildArgs([], commitment);
|
|
6226
|
+
|
|
6227
|
+
const unsafeRes = await this._rpcRequest('getBlockHeight', args);
|
|
6228
|
+
const res = superstruct.create(unsafeRes, jsonRpcResult(superstruct.number()));
|
|
6229
|
+
|
|
6230
|
+
if ('error' in res) {
|
|
6231
|
+
throw new Error('failed to get block height information: ' + res.error.message);
|
|
6232
|
+
}
|
|
6233
|
+
|
|
6234
|
+
return res.result;
|
|
6235
|
+
}
|
|
6236
|
+
/*
|
|
6237
|
+
* Returns recent block production information from the current or previous epoch
|
|
6238
|
+
*/
|
|
6239
|
+
|
|
6240
|
+
|
|
6241
|
+
async getBlockProduction(configOrCommitment) {
|
|
6242
|
+
let extra;
|
|
6243
|
+
let commitment;
|
|
6244
|
+
|
|
6245
|
+
if (typeof configOrCommitment === 'string') {
|
|
6246
|
+
commitment = configOrCommitment;
|
|
6247
|
+
} else if (configOrCommitment) {
|
|
6248
|
+
const {
|
|
6249
|
+
commitment: c,
|
|
6250
|
+
...rest
|
|
6251
|
+
} = configOrCommitment;
|
|
6252
|
+
commitment = c;
|
|
6253
|
+
extra = rest;
|
|
6254
|
+
}
|
|
6255
|
+
|
|
6256
|
+
const args = this._buildArgs([], commitment, 'base64', extra);
|
|
6257
|
+
|
|
6258
|
+
const unsafeRes = await this._rpcRequest('getBlockProduction', args);
|
|
6259
|
+
const res = superstruct.create(unsafeRes, BlockProductionResponseStruct);
|
|
6260
|
+
|
|
6261
|
+
if ('error' in res) {
|
|
6262
|
+
throw new Error('failed to get block production information: ' + res.error.message);
|
|
6263
|
+
}
|
|
6264
|
+
|
|
6265
|
+
return res.result;
|
|
6266
|
+
}
|
|
6149
6267
|
/**
|
|
6150
6268
|
* Fetch a confirmed or finalized transaction from the cluster.
|
|
6151
6269
|
*/
|
|
@@ -7627,16 +7745,18 @@ class Ed25519Program {
|
|
|
7627
7745
|
const messageDataOffset = signatureOffset + signature.length;
|
|
7628
7746
|
const numSignatures = 1;
|
|
7629
7747
|
const instructionData = buffer.Buffer.alloc(messageDataOffset + message.length);
|
|
7748
|
+
const index = instructionIndex == null ? 0xffff // An index of `u16::MAX` makes it default to the current instruction.
|
|
7749
|
+
: instructionIndex;
|
|
7630
7750
|
ED25519_INSTRUCTION_LAYOUT.encode({
|
|
7631
7751
|
numSignatures,
|
|
7632
7752
|
padding: 0,
|
|
7633
7753
|
signatureOffset,
|
|
7634
|
-
signatureInstructionIndex:
|
|
7754
|
+
signatureInstructionIndex: index,
|
|
7635
7755
|
publicKeyOffset,
|
|
7636
|
-
publicKeyInstructionIndex:
|
|
7756
|
+
publicKeyInstructionIndex: index,
|
|
7637
7757
|
messageDataOffset,
|
|
7638
7758
|
messageDataSize: message.length,
|
|
7639
|
-
messageInstructionIndex:
|
|
7759
|
+
messageInstructionIndex: index
|
|
7640
7760
|
}, instructionData);
|
|
7641
7761
|
instructionData.fill(publicKey, publicKeyOffset);
|
|
7642
7762
|
instructionData.fill(signature, signatureOffset);
|
|
@@ -7707,10 +7827,10 @@ class Authorized {
|
|
|
7707
7827
|
}
|
|
7708
7828
|
|
|
7709
7829
|
}
|
|
7830
|
+
|
|
7710
7831
|
/**
|
|
7711
7832
|
* Stake account lockup info
|
|
7712
7833
|
*/
|
|
7713
|
-
|
|
7714
7834
|
class Lockup {
|
|
7715
7835
|
/** Unix timestamp of lockup expiration */
|
|
7716
7836
|
|
|
@@ -7735,10 +7855,6 @@ class Lockup {
|
|
|
7735
7855
|
|
|
7736
7856
|
|
|
7737
7857
|
}
|
|
7738
|
-
/**
|
|
7739
|
-
* Create stake account transaction params
|
|
7740
|
-
*/
|
|
7741
|
-
|
|
7742
7858
|
Lockup.default = new Lockup(0, 0, PublicKey.default);
|
|
7743
7859
|
|
|
7744
7860
|
/**
|
|
@@ -8766,8 +8882,8 @@ class VoteAccount {
|
|
|
8766
8882
|
}
|
|
8767
8883
|
|
|
8768
8884
|
function parseAuthorizedVoter({
|
|
8769
|
-
|
|
8770
|
-
|
|
8885
|
+
authorizedVoter,
|
|
8886
|
+
epoch
|
|
8771
8887
|
}) {
|
|
8772
8888
|
return {
|
|
8773
8889
|
epoch,
|
|
@@ -8796,7 +8912,7 @@ function getPriorVoters({
|
|
|
8796
8912
|
return [];
|
|
8797
8913
|
}
|
|
8798
8914
|
|
|
8799
|
-
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
8915
|
+
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx).map(parsePriorVoters)];
|
|
8800
8916
|
}
|
|
8801
8917
|
|
|
8802
8918
|
/**
|