@solana/web3.js 1.36.0 → 1.37.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.browser.cjs.js +9848 -0
- package/lib/index.browser.cjs.js.map +1 -0
- package/lib/index.browser.esm.js +168 -52
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +169 -51
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +52 -13
- package/lib/index.esm.js +169 -51
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +1593 -1238
- 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 +106 -8
- 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
|
*/
|
|
@@ -6638,7 +6756,14 @@ class Connection {
|
|
|
6638
6756
|
let transaction;
|
|
6639
6757
|
|
|
6640
6758
|
if (transactionOrMessage instanceof Transaction) {
|
|
6641
|
-
|
|
6759
|
+
let originalTx = transactionOrMessage;
|
|
6760
|
+
transaction = new Transaction({
|
|
6761
|
+
recentBlockhash: originalTx.recentBlockhash,
|
|
6762
|
+
nonceInfo: originalTx.nonceInfo,
|
|
6763
|
+
feePayer: originalTx.feePayer,
|
|
6764
|
+
signatures: [...originalTx.signatures]
|
|
6765
|
+
});
|
|
6766
|
+
transaction.instructions = transactionOrMessage.instructions;
|
|
6642
6767
|
} else {
|
|
6643
6768
|
transaction = Transaction.populate(transactionOrMessage);
|
|
6644
6769
|
}
|
|
@@ -6806,12 +6931,6 @@ class Connection {
|
|
|
6806
6931
|
|
|
6807
6932
|
if ('data' in res.error) {
|
|
6808
6933
|
logs = res.error.data.logs;
|
|
6809
|
-
|
|
6810
|
-
if (logs && Array.isArray(logs)) {
|
|
6811
|
-
const traceIndent = '\n ';
|
|
6812
|
-
const logTrace = traceIndent + logs.join(traceIndent);
|
|
6813
|
-
console.error(res.error.message, logTrace);
|
|
6814
|
-
}
|
|
6815
6934
|
}
|
|
6816
6935
|
|
|
6817
6936
|
throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
|
|
@@ -6917,6 +7036,7 @@ class Connection {
|
|
|
6917
7036
|
|
|
6918
7037
|
_resetSubscriptions() {
|
|
6919
7038
|
Object.values(this._accountChangeSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7039
|
+
Object.values(this._logsSubscriptions).forEach(s => s.subscriptionId = null);
|
|
6920
7040
|
Object.values(this._programAccountChangeSubscriptions).forEach(s => s.subscriptionId = null);
|
|
6921
7041
|
Object.values(this._rootSubscriptions).forEach(s => s.subscriptionId = null);
|
|
6922
7042
|
Object.values(this._signatureSubscriptions).forEach(s => s.subscriptionId = null);
|
|
@@ -7627,16 +7747,18 @@ class Ed25519Program {
|
|
|
7627
7747
|
const messageDataOffset = signatureOffset + signature.length;
|
|
7628
7748
|
const numSignatures = 1;
|
|
7629
7749
|
const instructionData = buffer.Buffer.alloc(messageDataOffset + message.length);
|
|
7750
|
+
const index = instructionIndex == null ? 0xffff // An index of `u16::MAX` makes it default to the current instruction.
|
|
7751
|
+
: instructionIndex;
|
|
7630
7752
|
ED25519_INSTRUCTION_LAYOUT.encode({
|
|
7631
7753
|
numSignatures,
|
|
7632
7754
|
padding: 0,
|
|
7633
7755
|
signatureOffset,
|
|
7634
|
-
signatureInstructionIndex:
|
|
7756
|
+
signatureInstructionIndex: index,
|
|
7635
7757
|
publicKeyOffset,
|
|
7636
|
-
publicKeyInstructionIndex:
|
|
7758
|
+
publicKeyInstructionIndex: index,
|
|
7637
7759
|
messageDataOffset,
|
|
7638
7760
|
messageDataSize: message.length,
|
|
7639
|
-
messageInstructionIndex:
|
|
7761
|
+
messageInstructionIndex: index
|
|
7640
7762
|
}, instructionData);
|
|
7641
7763
|
instructionData.fill(publicKey, publicKeyOffset);
|
|
7642
7764
|
instructionData.fill(signature, signatureOffset);
|
|
@@ -7707,10 +7829,10 @@ class Authorized {
|
|
|
7707
7829
|
}
|
|
7708
7830
|
|
|
7709
7831
|
}
|
|
7832
|
+
|
|
7710
7833
|
/**
|
|
7711
7834
|
* Stake account lockup info
|
|
7712
7835
|
*/
|
|
7713
|
-
|
|
7714
7836
|
class Lockup {
|
|
7715
7837
|
/** Unix timestamp of lockup expiration */
|
|
7716
7838
|
|
|
@@ -7735,10 +7857,6 @@ class Lockup {
|
|
|
7735
7857
|
|
|
7736
7858
|
|
|
7737
7859
|
}
|
|
7738
|
-
/**
|
|
7739
|
-
* Create stake account transaction params
|
|
7740
|
-
*/
|
|
7741
|
-
|
|
7742
7860
|
Lockup.default = new Lockup(0, 0, PublicKey.default);
|
|
7743
7861
|
|
|
7744
7862
|
/**
|
|
@@ -8766,8 +8884,8 @@ class VoteAccount {
|
|
|
8766
8884
|
}
|
|
8767
8885
|
|
|
8768
8886
|
function parseAuthorizedVoter({
|
|
8769
|
-
|
|
8770
|
-
|
|
8887
|
+
authorizedVoter,
|
|
8888
|
+
epoch
|
|
8771
8889
|
}) {
|
|
8772
8890
|
return {
|
|
8773
8891
|
epoch,
|
|
@@ -8796,7 +8914,7 @@ function getPriorVoters({
|
|
|
8796
8914
|
return [];
|
|
8797
8915
|
}
|
|
8798
8916
|
|
|
8799
|
-
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx)];
|
|
8917
|
+
return [...buf.slice(idx + 1).map(parsePriorVoters), ...buf.slice(0, idx).map(parsePriorVoters)];
|
|
8800
8918
|
}
|
|
8801
8919
|
|
|
8802
8920
|
/**
|