@solana/web3.js 1.91.8 → 1.92.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 +118 -49
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +118 -49
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +118 -49
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +15 -2
- package/lib/index.esm.js +118 -49
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +487 -485
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +3 -3
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +118 -49
- package/lib/index.native.js.map +1 -1
- package/package.json +4 -4
- package/src/__forks__/browser/rpc-websocket-factory.ts +1 -1
- package/src/__forks__/react-native/rpc-websocket-factory.ts +1 -1
- package/src/connection.ts +15 -9
- package/src/errors.ts +70 -3
- package/src/rpc-websocket-factory.ts +2 -2
- package/src/rpc-websocket.ts +6 -6
- package/src/utils/makeWebsocketUrl.ts +1 -1
- package/src/utils/send-and-confirm-raw-transaction.ts +8 -0
- package/src/utils/send-and-confirm-transaction.ts +8 -0
package/lib/index.iife.js
CHANGED
|
@@ -2171,15 +2171,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
2171
2171
|
if (value > max || value < min) {
|
|
2172
2172
|
const n = typeof min === 'bigint' ? 'n' : '';
|
|
2173
2173
|
let range;
|
|
2174
|
-
|
|
2174
|
+
{
|
|
2175
2175
|
if (min === 0 || min === BigInt(0)) {
|
|
2176
2176
|
range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`;
|
|
2177
2177
|
} else {
|
|
2178
2178
|
range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` +
|
|
2179
2179
|
`${(byteLength + 1) * 8 - 1}${n}`;
|
|
2180
2180
|
}
|
|
2181
|
-
} else {
|
|
2182
|
-
range = `>= ${min}${n} and <= ${max}${n}`;
|
|
2183
2181
|
}
|
|
2184
2182
|
throw new errors.ERR_OUT_OF_RANGE('value', range, value)
|
|
2185
2183
|
}
|
|
@@ -2195,15 +2193,15 @@ var solanaWeb3 = (function (exports) {
|
|
|
2195
2193
|
function boundsError (value, length, type) {
|
|
2196
2194
|
if (Math.floor(value) !== value) {
|
|
2197
2195
|
validateNumber(value, type);
|
|
2198
|
-
throw new errors.ERR_OUT_OF_RANGE(
|
|
2196
|
+
throw new errors.ERR_OUT_OF_RANGE('offset', 'an integer', value)
|
|
2199
2197
|
}
|
|
2200
2198
|
|
|
2201
2199
|
if (length < 0) {
|
|
2202
2200
|
throw new errors.ERR_BUFFER_OUT_OF_BOUNDS()
|
|
2203
2201
|
}
|
|
2204
2202
|
|
|
2205
|
-
throw new errors.ERR_OUT_OF_RANGE(
|
|
2206
|
-
`>= ${
|
|
2203
|
+
throw new errors.ERR_OUT_OF_RANGE('offset',
|
|
2204
|
+
`>= ${0} and <= ${length}`,
|
|
2207
2205
|
value)
|
|
2208
2206
|
}
|
|
2209
2207
|
|
|
@@ -13354,6 +13352,94 @@ var solanaWeb3 = (function (exports) {
|
|
|
13354
13352
|
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
13355
13353
|
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
13356
13354
|
|
|
13355
|
+
class SendTransactionError extends Error {
|
|
13356
|
+
constructor({
|
|
13357
|
+
action,
|
|
13358
|
+
signature,
|
|
13359
|
+
transactionMessage,
|
|
13360
|
+
transactionLogs
|
|
13361
|
+
}) {
|
|
13362
|
+
let message;
|
|
13363
|
+
switch (action) {
|
|
13364
|
+
case 'send':
|
|
13365
|
+
message = `Transaction ${signature} resulted in an error. \n` + `${transactionMessage}. ` + (transactionLogs ? `Logs: \n${JSON.stringify(transactionLogs.slice(-10), null, 2)}. ` : '') + '\nCatch the SendTransactionError and call `getLogs()` on it for full details.';
|
|
13366
|
+
break;
|
|
13367
|
+
case 'simulate':
|
|
13368
|
+
message = `Simulation failed. \nMessage: ${transactionMessage}. \n` + (transactionLogs ? `Logs: \n${JSON.stringify(transactionLogs.slice(-10), null, 2)}. ` : '') + '\nCatch the SendTransactionError and call `getLogs()` on it for full details.';
|
|
13369
|
+
break;
|
|
13370
|
+
default:
|
|
13371
|
+
message = 'Unknown action';
|
|
13372
|
+
}
|
|
13373
|
+
super(message);
|
|
13374
|
+
this.signature = void 0;
|
|
13375
|
+
this.transactionMessage = void 0;
|
|
13376
|
+
this.transactionLogs = void 0;
|
|
13377
|
+
this.resolvedLogs = void 0;
|
|
13378
|
+
this.signature = signature;
|
|
13379
|
+
this.transactionMessage = transactionMessage;
|
|
13380
|
+
this.transactionLogs = transactionLogs;
|
|
13381
|
+
this.resolvedLogs = transactionLogs ? transactionLogs : undefined;
|
|
13382
|
+
}
|
|
13383
|
+
get transactionError() {
|
|
13384
|
+
return {
|
|
13385
|
+
message: this.transactionMessage,
|
|
13386
|
+
logs: this.transactionLogs
|
|
13387
|
+
};
|
|
13388
|
+
}
|
|
13389
|
+
async getLogs(connection) {
|
|
13390
|
+
if (this.resolvedLogs === undefined) {
|
|
13391
|
+
this.resolvedLogs = new Promise((resolve, reject) => {
|
|
13392
|
+
connection.getTransaction(this.signature).then(tx => {
|
|
13393
|
+
if (tx && tx.meta && tx.meta.logMessages) {
|
|
13394
|
+
const logs = tx.meta.logMessages;
|
|
13395
|
+
this.resolvedLogs = logs;
|
|
13396
|
+
this.transactionLogs = logs;
|
|
13397
|
+
resolve(logs);
|
|
13398
|
+
} else {
|
|
13399
|
+
reject(new Error('Log messages not found'));
|
|
13400
|
+
}
|
|
13401
|
+
}).catch(reject);
|
|
13402
|
+
});
|
|
13403
|
+
}
|
|
13404
|
+
return await this.resolvedLogs;
|
|
13405
|
+
}
|
|
13406
|
+
}
|
|
13407
|
+
|
|
13408
|
+
// Keep in sync with client/src/rpc_custom_errors.rs
|
|
13409
|
+
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
13410
|
+
const SolanaJSONRPCErrorCode = {
|
|
13411
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
13412
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
13413
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
13414
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
13415
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
13416
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
13417
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
13418
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
13419
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
13420
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
13421
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
13422
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
13423
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
13424
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
13425
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
|
|
13426
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
|
|
13427
|
+
};
|
|
13428
|
+
class SolanaJSONRPCError extends Error {
|
|
13429
|
+
constructor({
|
|
13430
|
+
code,
|
|
13431
|
+
message,
|
|
13432
|
+
data
|
|
13433
|
+
}, customMessage) {
|
|
13434
|
+
super(customMessage != null ? `${customMessage}: ${message}` : message);
|
|
13435
|
+
this.code = void 0;
|
|
13436
|
+
this.data = void 0;
|
|
13437
|
+
this.code = code;
|
|
13438
|
+
this.data = data;
|
|
13439
|
+
this.name = 'SolanaJSONRPCError';
|
|
13440
|
+
}
|
|
13441
|
+
}
|
|
13442
|
+
|
|
13357
13443
|
/**
|
|
13358
13444
|
* Sign, send and confirm a transaction.
|
|
13359
13445
|
*
|
|
@@ -13400,6 +13486,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
13400
13486
|
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
13401
13487
|
}
|
|
13402
13488
|
if (status.err) {
|
|
13489
|
+
if (signature != null) {
|
|
13490
|
+
throw new SendTransactionError({
|
|
13491
|
+
action: 'send',
|
|
13492
|
+
signature: signature,
|
|
13493
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
13494
|
+
});
|
|
13495
|
+
}
|
|
13403
13496
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
13404
13497
|
}
|
|
13405
13498
|
return signature;
|
|
@@ -14636,7 +14729,6 @@ var solanaWeb3 = (function (exports) {
|
|
|
14636
14729
|
/**
|
|
14637
14730
|
* A `StructFailure` represents a single specific failure in validation.
|
|
14638
14731
|
*/
|
|
14639
|
-
|
|
14640
14732
|
/**
|
|
14641
14733
|
* `StructError` objects are thrown (or returned) when validation fails.
|
|
14642
14734
|
*
|
|
@@ -14646,190 +14738,160 @@ var solanaWeb3 = (function (exports) {
|
|
|
14646
14738
|
* continue validation and receive all the failures in the data.
|
|
14647
14739
|
*/
|
|
14648
14740
|
class StructError extends TypeError {
|
|
14649
|
-
|
|
14650
|
-
|
|
14651
|
-
|
|
14652
|
-
|
|
14653
|
-
|
|
14654
|
-
|
|
14655
|
-
|
|
14656
|
-
|
|
14657
|
-
|
|
14658
|
-
|
|
14659
|
-
|
|
14660
|
-
|
|
14661
|
-
|
|
14662
|
-
|
|
14663
|
-
this.failures = () => {
|
|
14664
|
-
var _cached;
|
|
14665
|
-
|
|
14666
|
-
return (_cached = cached) != null ? _cached : cached = [failure, ...failures()];
|
|
14667
|
-
};
|
|
14668
|
-
}
|
|
14669
|
-
|
|
14741
|
+
constructor(failure, failures) {
|
|
14742
|
+
let cached;
|
|
14743
|
+
const { message, explanation, ...rest } = failure;
|
|
14744
|
+
const { path } = failure;
|
|
14745
|
+
const msg = path.length === 0 ? message : `At path: ${path.join('.')} -- ${message}`;
|
|
14746
|
+
super(explanation ?? msg);
|
|
14747
|
+
if (explanation != null)
|
|
14748
|
+
this.cause = msg;
|
|
14749
|
+
Object.assign(this, rest);
|
|
14750
|
+
this.name = this.constructor.name;
|
|
14751
|
+
this.failures = () => {
|
|
14752
|
+
return (cached ?? (cached = [failure, ...failures()]));
|
|
14753
|
+
};
|
|
14754
|
+
}
|
|
14670
14755
|
}
|
|
14671
14756
|
|
|
14672
14757
|
/**
|
|
14673
14758
|
* Check if a value is an iterator.
|
|
14674
14759
|
*/
|
|
14675
14760
|
function isIterable(x) {
|
|
14676
|
-
|
|
14761
|
+
return isObject(x) && typeof x[Symbol.iterator] === 'function';
|
|
14677
14762
|
}
|
|
14678
14763
|
/**
|
|
14679
14764
|
* Check if a value is a plain object.
|
|
14680
14765
|
*/
|
|
14681
|
-
|
|
14682
|
-
|
|
14683
14766
|
function isObject(x) {
|
|
14684
|
-
|
|
14767
|
+
return typeof x === 'object' && x != null;
|
|
14685
14768
|
}
|
|
14686
14769
|
/**
|
|
14687
14770
|
* Return a value as a printable string.
|
|
14688
14771
|
*/
|
|
14689
|
-
|
|
14690
14772
|
function print(value) {
|
|
14691
|
-
|
|
14773
|
+
if (typeof value === 'symbol') {
|
|
14774
|
+
return value.toString();
|
|
14775
|
+
}
|
|
14776
|
+
return typeof value === 'string' ? JSON.stringify(value) : `${value}`;
|
|
14692
14777
|
}
|
|
14693
14778
|
/**
|
|
14694
14779
|
* Shifts (removes and returns) the first value from the `input` iterator.
|
|
14695
14780
|
* Like `Array.prototype.shift()` but for an `Iterator`.
|
|
14696
14781
|
*/
|
|
14697
|
-
|
|
14698
14782
|
function shiftIterator(input) {
|
|
14699
|
-
|
|
14700
|
-
done
|
|
14701
|
-
value
|
|
14702
|
-
} = input.next();
|
|
14703
|
-
return done ? undefined : value;
|
|
14783
|
+
const { done, value } = input.next();
|
|
14784
|
+
return done ? undefined : value;
|
|
14704
14785
|
}
|
|
14705
14786
|
/**
|
|
14706
14787
|
* Convert a single validation result to a failure.
|
|
14707
14788
|
*/
|
|
14708
|
-
|
|
14709
14789
|
function toFailure(result, context, struct, value) {
|
|
14710
|
-
|
|
14711
|
-
|
|
14712
|
-
|
|
14713
|
-
result
|
|
14714
|
-
|
|
14715
|
-
|
|
14716
|
-
|
|
14790
|
+
if (result === true) {
|
|
14791
|
+
return;
|
|
14792
|
+
}
|
|
14793
|
+
else if (result === false) {
|
|
14794
|
+
result = {};
|
|
14795
|
+
}
|
|
14796
|
+
else if (typeof result === 'string') {
|
|
14797
|
+
result = { message: result };
|
|
14798
|
+
}
|
|
14799
|
+
const { path, branch } = context;
|
|
14800
|
+
const { type } = struct;
|
|
14801
|
+
const { refinement, message = `Expected a value of type \`${type}\`${refinement ? ` with refinement \`${refinement}\`` : ''}, but received: \`${print(value)}\``, } = result;
|
|
14802
|
+
return {
|
|
14803
|
+
value,
|
|
14804
|
+
type,
|
|
14805
|
+
refinement,
|
|
14806
|
+
key: path[path.length - 1],
|
|
14807
|
+
path,
|
|
14808
|
+
branch,
|
|
14809
|
+
...result,
|
|
14810
|
+
message,
|
|
14717
14811
|
};
|
|
14718
|
-
}
|
|
14719
|
-
|
|
14720
|
-
const {
|
|
14721
|
-
path,
|
|
14722
|
-
branch
|
|
14723
|
-
} = context;
|
|
14724
|
-
const {
|
|
14725
|
-
type
|
|
14726
|
-
} = struct;
|
|
14727
|
-
const {
|
|
14728
|
-
refinement,
|
|
14729
|
-
message = "Expected a value of type `" + type + "`" + (refinement ? " with refinement `" + refinement + "`" : '') + ", but received: `" + print(value) + "`"
|
|
14730
|
-
} = result;
|
|
14731
|
-
return {
|
|
14732
|
-
value,
|
|
14733
|
-
type,
|
|
14734
|
-
refinement,
|
|
14735
|
-
key: path[path.length - 1],
|
|
14736
|
-
path,
|
|
14737
|
-
branch,
|
|
14738
|
-
...result,
|
|
14739
|
-
message
|
|
14740
|
-
};
|
|
14741
14812
|
}
|
|
14742
14813
|
/**
|
|
14743
14814
|
* Convert a validation result to an iterable of failures.
|
|
14744
14815
|
*/
|
|
14745
|
-
|
|
14746
14816
|
function* toFailures(result, context, struct, value) {
|
|
14747
|
-
|
|
14748
|
-
|
|
14749
|
-
|
|
14750
|
-
|
|
14751
|
-
|
|
14752
|
-
|
|
14753
|
-
|
|
14754
|
-
|
|
14755
|
-
yield failure;
|
|
14817
|
+
if (!isIterable(result)) {
|
|
14818
|
+
result = [result];
|
|
14819
|
+
}
|
|
14820
|
+
for (const r of result) {
|
|
14821
|
+
const failure = toFailure(r, context, struct, value);
|
|
14822
|
+
if (failure) {
|
|
14823
|
+
yield failure;
|
|
14824
|
+
}
|
|
14756
14825
|
}
|
|
14757
|
-
}
|
|
14758
14826
|
}
|
|
14759
14827
|
/**
|
|
14760
14828
|
* Check a value against a struct, traversing deeply into nested values, and
|
|
14761
14829
|
* returning an iterator of failures or success.
|
|
14762
14830
|
*/
|
|
14763
|
-
|
|
14764
14831
|
function* run(value, struct, options = {}) {
|
|
14765
|
-
|
|
14766
|
-
|
|
14767
|
-
|
|
14768
|
-
|
|
14769
|
-
|
|
14770
|
-
|
|
14771
|
-
|
|
14772
|
-
|
|
14773
|
-
|
|
14774
|
-
|
|
14775
|
-
|
|
14776
|
-
|
|
14777
|
-
|
|
14778
|
-
|
|
14779
|
-
if (mask && struct.type !== 'type' && isObject(struct.schema) && isObject(value) && !Array.isArray(value)) {
|
|
14780
|
-
for (const key in value) {
|
|
14781
|
-
if (struct.schema[key] === undefined) {
|
|
14782
|
-
delete value[key];
|
|
14832
|
+
const { path = [], branch = [value], coerce = false, mask = false } = options;
|
|
14833
|
+
const ctx = { path, branch };
|
|
14834
|
+
if (coerce) {
|
|
14835
|
+
value = struct.coercer(value, ctx);
|
|
14836
|
+
if (mask &&
|
|
14837
|
+
struct.type !== 'type' &&
|
|
14838
|
+
isObject(struct.schema) &&
|
|
14839
|
+
isObject(value) &&
|
|
14840
|
+
!Array.isArray(value)) {
|
|
14841
|
+
for (const key in value) {
|
|
14842
|
+
if (struct.schema[key] === undefined) {
|
|
14843
|
+
delete value[key];
|
|
14844
|
+
}
|
|
14845
|
+
}
|
|
14783
14846
|
}
|
|
14784
|
-
}
|
|
14785
14847
|
}
|
|
14786
|
-
|
|
14787
|
-
|
|
14788
|
-
|
|
14789
|
-
|
|
14790
|
-
|
|
14791
|
-
|
|
14792
|
-
|
|
14793
|
-
|
|
14794
|
-
|
|
14795
|
-
|
|
14796
|
-
|
|
14797
|
-
|
|
14798
|
-
|
|
14799
|
-
|
|
14800
|
-
|
|
14801
|
-
|
|
14802
|
-
|
|
14803
|
-
|
|
14804
|
-
|
|
14805
|
-
|
|
14806
|
-
|
|
14807
|
-
|
|
14808
|
-
|
|
14809
|
-
|
|
14810
|
-
|
|
14811
|
-
|
|
14812
|
-
|
|
14813
|
-
|
|
14814
|
-
|
|
14815
|
-
|
|
14816
|
-
|
|
14817
|
-
|
|
14848
|
+
let status = 'valid';
|
|
14849
|
+
for (const failure of struct.validator(value, ctx)) {
|
|
14850
|
+
failure.explanation = options.message;
|
|
14851
|
+
status = 'not_valid';
|
|
14852
|
+
yield [failure, undefined];
|
|
14853
|
+
}
|
|
14854
|
+
for (let [k, v, s] of struct.entries(value, ctx)) {
|
|
14855
|
+
const ts = run(v, s, {
|
|
14856
|
+
path: k === undefined ? path : [...path, k],
|
|
14857
|
+
branch: k === undefined ? branch : [...branch, v],
|
|
14858
|
+
coerce,
|
|
14859
|
+
mask,
|
|
14860
|
+
message: options.message,
|
|
14861
|
+
});
|
|
14862
|
+
for (const t of ts) {
|
|
14863
|
+
if (t[0]) {
|
|
14864
|
+
status = t[0].refinement != null ? 'not_refined' : 'not_valid';
|
|
14865
|
+
yield [t[0], undefined];
|
|
14866
|
+
}
|
|
14867
|
+
else if (coerce) {
|
|
14868
|
+
v = t[1];
|
|
14869
|
+
if (k === undefined) {
|
|
14870
|
+
value = v;
|
|
14871
|
+
}
|
|
14872
|
+
else if (value instanceof Map) {
|
|
14873
|
+
value.set(k, v);
|
|
14874
|
+
}
|
|
14875
|
+
else if (value instanceof Set) {
|
|
14876
|
+
value.add(v);
|
|
14877
|
+
}
|
|
14878
|
+
else if (isObject(value)) {
|
|
14879
|
+
if (v !== undefined || k in value)
|
|
14880
|
+
value[k] = v;
|
|
14881
|
+
}
|
|
14882
|
+
}
|
|
14818
14883
|
}
|
|
14819
|
-
}
|
|
14820
14884
|
}
|
|
14821
|
-
|
|
14822
|
-
|
|
14823
|
-
|
|
14824
|
-
|
|
14825
|
-
|
|
14826
|
-
|
|
14885
|
+
if (status !== 'not_valid') {
|
|
14886
|
+
for (const failure of struct.refiner(value, ctx)) {
|
|
14887
|
+
failure.explanation = options.message;
|
|
14888
|
+
status = 'not_refined';
|
|
14889
|
+
yield [failure, undefined];
|
|
14890
|
+
}
|
|
14891
|
+
}
|
|
14892
|
+
if (status === 'valid') {
|
|
14893
|
+
yield [undefined, value];
|
|
14827
14894
|
}
|
|
14828
|
-
}
|
|
14829
|
-
|
|
14830
|
-
if (valid) {
|
|
14831
|
-
yield [undefined, value];
|
|
14832
|
-
}
|
|
14833
14895
|
}
|
|
14834
14896
|
|
|
14835
14897
|
/**
|
|
@@ -14837,269 +14899,227 @@ var solanaWeb3 = (function (exports) {
|
|
|
14837
14899
|
* values. Once constructed, you use the `assert`, `is` or `validate` helpers to
|
|
14838
14900
|
* validate unknown input data against the struct.
|
|
14839
14901
|
*/
|
|
14840
|
-
|
|
14841
14902
|
class Struct {
|
|
14842
|
-
|
|
14843
|
-
|
|
14844
|
-
|
|
14845
|
-
|
|
14846
|
-
|
|
14847
|
-
|
|
14848
|
-
|
|
14849
|
-
|
|
14850
|
-
|
|
14851
|
-
|
|
14852
|
-
|
|
14853
|
-
|
|
14854
|
-
|
|
14855
|
-
|
|
14856
|
-
|
|
14857
|
-
|
|
14858
|
-
|
|
14859
|
-
|
|
14860
|
-
|
|
14861
|
-
|
|
14862
|
-
|
|
14903
|
+
constructor(props) {
|
|
14904
|
+
const { type, schema, validator, refiner, coercer = (value) => value, entries = function* () { }, } = props;
|
|
14905
|
+
this.type = type;
|
|
14906
|
+
this.schema = schema;
|
|
14907
|
+
this.entries = entries;
|
|
14908
|
+
this.coercer = coercer;
|
|
14909
|
+
if (validator) {
|
|
14910
|
+
this.validator = (value, context) => {
|
|
14911
|
+
const result = validator(value, context);
|
|
14912
|
+
return toFailures(result, context, this, value);
|
|
14913
|
+
};
|
|
14914
|
+
}
|
|
14915
|
+
else {
|
|
14916
|
+
this.validator = () => [];
|
|
14917
|
+
}
|
|
14918
|
+
if (refiner) {
|
|
14919
|
+
this.refiner = (value, context) => {
|
|
14920
|
+
const result = refiner(value, context);
|
|
14921
|
+
return toFailures(result, context, this, value);
|
|
14922
|
+
};
|
|
14923
|
+
}
|
|
14924
|
+
else {
|
|
14925
|
+
this.refiner = () => [];
|
|
14926
|
+
}
|
|
14863
14927
|
}
|
|
14864
|
-
|
|
14865
|
-
|
|
14866
|
-
|
|
14867
|
-
|
|
14868
|
-
return
|
|
14869
|
-
|
|
14870
|
-
|
|
14871
|
-
|
|
14928
|
+
/**
|
|
14929
|
+
* Assert that a value passes the struct's validation, throwing if it doesn't.
|
|
14930
|
+
*/
|
|
14931
|
+
assert(value, message) {
|
|
14932
|
+
return assert(value, this, message);
|
|
14933
|
+
}
|
|
14934
|
+
/**
|
|
14935
|
+
* Create a value with the struct's coercion logic, then validate it.
|
|
14936
|
+
*/
|
|
14937
|
+
create(value, message) {
|
|
14938
|
+
return create(value, this, message);
|
|
14939
|
+
}
|
|
14940
|
+
/**
|
|
14941
|
+
* Check if a value passes the struct's validation.
|
|
14942
|
+
*/
|
|
14943
|
+
is(value) {
|
|
14944
|
+
return is(value, this);
|
|
14945
|
+
}
|
|
14946
|
+
/**
|
|
14947
|
+
* Mask a value, coercing and validating it, but returning only the subset of
|
|
14948
|
+
* properties defined by the struct's schema.
|
|
14949
|
+
*/
|
|
14950
|
+
mask(value, message) {
|
|
14951
|
+
return mask(value, this, message);
|
|
14952
|
+
}
|
|
14953
|
+
/**
|
|
14954
|
+
* Validate a value with the struct's validation logic, returning a tuple
|
|
14955
|
+
* representing the result.
|
|
14956
|
+
*
|
|
14957
|
+
* You may optionally pass `true` for the `withCoercion` argument to coerce
|
|
14958
|
+
* the value before attempting to validate it. If you do, the result will
|
|
14959
|
+
* contain the coerced result when successful.
|
|
14960
|
+
*/
|
|
14961
|
+
validate(value, options = {}) {
|
|
14962
|
+
return validate$1(value, this, options);
|
|
14872
14963
|
}
|
|
14873
|
-
}
|
|
14874
|
-
/**
|
|
14875
|
-
* Assert that a value passes the struct's validation, throwing if it doesn't.
|
|
14876
|
-
*/
|
|
14877
|
-
|
|
14878
|
-
|
|
14879
|
-
assert(value) {
|
|
14880
|
-
return assert(value, this);
|
|
14881
|
-
}
|
|
14882
|
-
/**
|
|
14883
|
-
* Create a value with the struct's coercion logic, then validate it.
|
|
14884
|
-
*/
|
|
14885
|
-
|
|
14886
|
-
|
|
14887
|
-
create(value) {
|
|
14888
|
-
return create(value, this);
|
|
14889
|
-
}
|
|
14890
|
-
/**
|
|
14891
|
-
* Check if a value passes the struct's validation.
|
|
14892
|
-
*/
|
|
14893
|
-
|
|
14894
|
-
|
|
14895
|
-
is(value) {
|
|
14896
|
-
return is(value, this);
|
|
14897
|
-
}
|
|
14898
|
-
/**
|
|
14899
|
-
* Mask a value, coercing and validating it, but returning only the subset of
|
|
14900
|
-
* properties defined by the struct's schema.
|
|
14901
|
-
*/
|
|
14902
|
-
|
|
14903
|
-
|
|
14904
|
-
mask(value) {
|
|
14905
|
-
return mask(value, this);
|
|
14906
|
-
}
|
|
14907
|
-
/**
|
|
14908
|
-
* Validate a value with the struct's validation logic, returning a tuple
|
|
14909
|
-
* representing the result.
|
|
14910
|
-
*
|
|
14911
|
-
* You may optionally pass `true` for the `withCoercion` argument to coerce
|
|
14912
|
-
* the value before attempting to validate it. If you do, the result will
|
|
14913
|
-
* contain the coerced result when successful.
|
|
14914
|
-
*/
|
|
14915
|
-
|
|
14916
|
-
|
|
14917
|
-
validate(value, options = {}) {
|
|
14918
|
-
return validate$1(value, this, options);
|
|
14919
|
-
}
|
|
14920
|
-
|
|
14921
14964
|
}
|
|
14922
14965
|
/**
|
|
14923
14966
|
* Assert that a value passes a struct, throwing if it doesn't.
|
|
14924
14967
|
*/
|
|
14925
|
-
|
|
14926
|
-
|
|
14927
|
-
|
|
14928
|
-
|
|
14929
|
-
|
|
14930
|
-
throw result[0];
|
|
14931
|
-
}
|
|
14968
|
+
function assert(value, struct, message) {
|
|
14969
|
+
const result = validate$1(value, struct, { message });
|
|
14970
|
+
if (result[0]) {
|
|
14971
|
+
throw result[0];
|
|
14972
|
+
}
|
|
14932
14973
|
}
|
|
14933
14974
|
/**
|
|
14934
14975
|
* Create a value with the coercion logic of struct and validate it.
|
|
14935
14976
|
*/
|
|
14936
|
-
|
|
14937
|
-
|
|
14938
|
-
|
|
14939
|
-
|
|
14940
|
-
|
|
14941
|
-
|
|
14942
|
-
|
|
14943
|
-
|
|
14944
|
-
} else {
|
|
14945
|
-
return result[1];
|
|
14946
|
-
}
|
|
14977
|
+
function create(value, struct, message) {
|
|
14978
|
+
const result = validate$1(value, struct, { coerce: true, message });
|
|
14979
|
+
if (result[0]) {
|
|
14980
|
+
throw result[0];
|
|
14981
|
+
}
|
|
14982
|
+
else {
|
|
14983
|
+
return result[1];
|
|
14984
|
+
}
|
|
14947
14985
|
}
|
|
14948
14986
|
/**
|
|
14949
14987
|
* Mask a value, returning only the subset of properties defined by a struct.
|
|
14950
14988
|
*/
|
|
14951
|
-
|
|
14952
|
-
|
|
14953
|
-
|
|
14954
|
-
|
|
14955
|
-
|
|
14956
|
-
|
|
14957
|
-
|
|
14958
|
-
|
|
14959
|
-
throw result[0];
|
|
14960
|
-
} else {
|
|
14961
|
-
return result[1];
|
|
14962
|
-
}
|
|
14989
|
+
function mask(value, struct, message) {
|
|
14990
|
+
const result = validate$1(value, struct, { coerce: true, mask: true, message });
|
|
14991
|
+
if (result[0]) {
|
|
14992
|
+
throw result[0];
|
|
14993
|
+
}
|
|
14994
|
+
else {
|
|
14995
|
+
return result[1];
|
|
14996
|
+
}
|
|
14963
14997
|
}
|
|
14964
14998
|
/**
|
|
14965
14999
|
* Check if a value passes a struct.
|
|
14966
15000
|
*/
|
|
14967
|
-
|
|
14968
15001
|
function is(value, struct) {
|
|
14969
|
-
|
|
14970
|
-
|
|
15002
|
+
const result = validate$1(value, struct);
|
|
15003
|
+
return !result[0];
|
|
14971
15004
|
}
|
|
14972
15005
|
/**
|
|
14973
15006
|
* Validate a value against a struct, returning an error if invalid, or the
|
|
14974
15007
|
* value (with potential coercion) if valid.
|
|
14975
15008
|
*/
|
|
14976
|
-
|
|
14977
15009
|
function validate$1(value, struct, options = {}) {
|
|
14978
|
-
|
|
14979
|
-
|
|
14980
|
-
|
|
14981
|
-
|
|
14982
|
-
|
|
14983
|
-
|
|
14984
|
-
|
|
14985
|
-
|
|
14986
|
-
|
|
14987
|
-
|
|
14988
|
-
|
|
14989
|
-
|
|
14990
|
-
|
|
14991
|
-
|
|
14992
|
-
|
|
14993
|
-
|
|
15010
|
+
const tuples = run(value, struct, options);
|
|
15011
|
+
const tuple = shiftIterator(tuples);
|
|
15012
|
+
if (tuple[0]) {
|
|
15013
|
+
const error = new StructError(tuple[0], function* () {
|
|
15014
|
+
for (const t of tuples) {
|
|
15015
|
+
if (t[0]) {
|
|
15016
|
+
yield t[0];
|
|
15017
|
+
}
|
|
15018
|
+
}
|
|
15019
|
+
});
|
|
15020
|
+
return [error, undefined];
|
|
15021
|
+
}
|
|
15022
|
+
else {
|
|
15023
|
+
const v = tuple[1];
|
|
15024
|
+
return [undefined, v];
|
|
15025
|
+
}
|
|
14994
15026
|
}
|
|
14995
15027
|
/**
|
|
14996
15028
|
* Define a new struct type with a custom validation function.
|
|
14997
15029
|
*/
|
|
14998
|
-
|
|
14999
15030
|
function define(name, validator) {
|
|
15000
|
-
|
|
15001
|
-
type: name,
|
|
15002
|
-
schema: null,
|
|
15003
|
-
validator
|
|
15004
|
-
});
|
|
15031
|
+
return new Struct({ type: name, schema: null, validator });
|
|
15005
15032
|
}
|
|
15006
15033
|
|
|
15007
15034
|
/**
|
|
15008
15035
|
* Ensure that any value passes validation.
|
|
15009
15036
|
*/
|
|
15010
|
-
|
|
15011
15037
|
function any() {
|
|
15012
|
-
|
|
15038
|
+
return define('any', () => true);
|
|
15013
15039
|
}
|
|
15014
15040
|
function array(Element) {
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15018
|
-
|
|
15019
|
-
|
|
15020
|
-
|
|
15021
|
-
|
|
15022
|
-
|
|
15023
|
-
|
|
15024
|
-
|
|
15025
|
-
|
|
15026
|
-
|
|
15027
|
-
|
|
15028
|
-
|
|
15029
|
-
|
|
15030
|
-
|
|
15031
|
-
|
|
15032
|
-
|
|
15033
|
-
}
|
|
15034
|
-
|
|
15035
|
-
});
|
|
15041
|
+
return new Struct({
|
|
15042
|
+
type: 'array',
|
|
15043
|
+
schema: Element,
|
|
15044
|
+
*entries(value) {
|
|
15045
|
+
if (Element && Array.isArray(value)) {
|
|
15046
|
+
for (const [i, v] of value.entries()) {
|
|
15047
|
+
yield [i, v, Element];
|
|
15048
|
+
}
|
|
15049
|
+
}
|
|
15050
|
+
},
|
|
15051
|
+
coercer(value) {
|
|
15052
|
+
return Array.isArray(value) ? value.slice() : value;
|
|
15053
|
+
},
|
|
15054
|
+
validator(value) {
|
|
15055
|
+
return (Array.isArray(value) ||
|
|
15056
|
+
`Expected an array value, but received: ${print(value)}`);
|
|
15057
|
+
},
|
|
15058
|
+
});
|
|
15036
15059
|
}
|
|
15037
15060
|
/**
|
|
15038
15061
|
* Ensure that a value is a boolean.
|
|
15039
15062
|
*/
|
|
15040
|
-
|
|
15041
15063
|
function boolean() {
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
|
|
15064
|
+
return define('boolean', (value) => {
|
|
15065
|
+
return typeof value === 'boolean';
|
|
15066
|
+
});
|
|
15045
15067
|
}
|
|
15046
15068
|
/**
|
|
15047
15069
|
* Ensure that a value is an instance of a specific class.
|
|
15048
15070
|
*/
|
|
15049
|
-
|
|
15050
15071
|
function instance(Class) {
|
|
15051
|
-
|
|
15052
|
-
|
|
15053
|
-
|
|
15072
|
+
return define('instance', (value) => {
|
|
15073
|
+
return (value instanceof Class ||
|
|
15074
|
+
`Expected a \`${Class.name}\` instance, but received: ${print(value)}`);
|
|
15075
|
+
});
|
|
15054
15076
|
}
|
|
15055
15077
|
function literal(constant) {
|
|
15056
|
-
|
|
15057
|
-
|
|
15058
|
-
|
|
15059
|
-
|
|
15060
|
-
|
|
15061
|
-
|
|
15062
|
-
|
|
15063
|
-
|
|
15064
|
-
|
|
15065
|
-
|
|
15066
|
-
});
|
|
15078
|
+
const description = print(constant);
|
|
15079
|
+
const t = typeof constant;
|
|
15080
|
+
return new Struct({
|
|
15081
|
+
type: 'literal',
|
|
15082
|
+
schema: t === 'string' || t === 'number' || t === 'boolean' ? constant : null,
|
|
15083
|
+
validator(value) {
|
|
15084
|
+
return (value === constant ||
|
|
15085
|
+
`Expected the literal \`${description}\`, but received: ${print(value)}`);
|
|
15086
|
+
},
|
|
15087
|
+
});
|
|
15067
15088
|
}
|
|
15068
15089
|
/**
|
|
15069
15090
|
* Ensure that no value ever passes validation.
|
|
15070
15091
|
*/
|
|
15071
|
-
|
|
15072
15092
|
function never() {
|
|
15073
|
-
|
|
15093
|
+
return define('never', () => false);
|
|
15074
15094
|
}
|
|
15075
15095
|
/**
|
|
15076
15096
|
* Augment an existing struct to allow `null` values.
|
|
15077
15097
|
*/
|
|
15078
|
-
|
|
15079
15098
|
function nullable(struct) {
|
|
15080
|
-
|
|
15081
|
-
|
|
15082
|
-
|
|
15083
|
-
|
|
15099
|
+
return new Struct({
|
|
15100
|
+
...struct,
|
|
15101
|
+
validator: (value, ctx) => value === null || struct.validator(value, ctx),
|
|
15102
|
+
refiner: (value, ctx) => value === null || struct.refiner(value, ctx),
|
|
15103
|
+
});
|
|
15084
15104
|
}
|
|
15085
15105
|
/**
|
|
15086
15106
|
* Ensure that a value is a number.
|
|
15087
15107
|
*/
|
|
15088
|
-
|
|
15089
15108
|
function number() {
|
|
15090
|
-
|
|
15091
|
-
|
|
15092
|
-
|
|
15109
|
+
return define('number', (value) => {
|
|
15110
|
+
return ((typeof value === 'number' && !isNaN(value)) ||
|
|
15111
|
+
`Expected a number, but received: ${print(value)}`);
|
|
15112
|
+
});
|
|
15093
15113
|
}
|
|
15094
15114
|
/**
|
|
15095
15115
|
* Augment a struct to allow `undefined` values.
|
|
15096
15116
|
*/
|
|
15097
|
-
|
|
15098
15117
|
function optional(struct) {
|
|
15099
|
-
|
|
15100
|
-
|
|
15101
|
-
|
|
15102
|
-
|
|
15118
|
+
return new Struct({
|
|
15119
|
+
...struct,
|
|
15120
|
+
validator: (value, ctx) => value === undefined || struct.validator(value, ctx),
|
|
15121
|
+
refiner: (value, ctx) => value === undefined || struct.refiner(value, ctx),
|
|
15122
|
+
});
|
|
15103
15123
|
}
|
|
15104
15124
|
/**
|
|
15105
15125
|
* Ensure that a value is an object with keys and values of specific types, but
|
|
@@ -15107,58 +15127,55 @@ var solanaWeb3 = (function (exports) {
|
|
|
15107
15127
|
*
|
|
15108
15128
|
* Like TypeScript's `Record` utility.
|
|
15109
15129
|
*/
|
|
15110
|
-
|
|
15111
15130
|
function record(Key, Value) {
|
|
15112
|
-
|
|
15113
|
-
|
|
15114
|
-
|
|
15115
|
-
|
|
15116
|
-
|
|
15117
|
-
|
|
15118
|
-
|
|
15119
|
-
|
|
15120
|
-
|
|
15121
|
-
|
|
15122
|
-
|
|
15123
|
-
|
|
15124
|
-
|
|
15125
|
-
|
|
15126
|
-
|
|
15127
|
-
|
|
15128
|
-
}
|
|
15129
|
-
|
|
15130
|
-
});
|
|
15131
|
+
return new Struct({
|
|
15132
|
+
type: 'record',
|
|
15133
|
+
schema: null,
|
|
15134
|
+
*entries(value) {
|
|
15135
|
+
if (isObject(value)) {
|
|
15136
|
+
for (const k in value) {
|
|
15137
|
+
const v = value[k];
|
|
15138
|
+
yield [k, k, Key];
|
|
15139
|
+
yield [k, v, Value];
|
|
15140
|
+
}
|
|
15141
|
+
}
|
|
15142
|
+
},
|
|
15143
|
+
validator(value) {
|
|
15144
|
+
return (isObject(value) || `Expected an object, but received: ${print(value)}`);
|
|
15145
|
+
},
|
|
15146
|
+
});
|
|
15131
15147
|
}
|
|
15132
15148
|
/**
|
|
15133
15149
|
* Ensure that a value is a string.
|
|
15134
15150
|
*/
|
|
15135
|
-
|
|
15136
15151
|
function string() {
|
|
15137
|
-
|
|
15138
|
-
|
|
15139
|
-
|
|
15152
|
+
return define('string', (value) => {
|
|
15153
|
+
return (typeof value === 'string' ||
|
|
15154
|
+
`Expected a string, but received: ${print(value)}`);
|
|
15155
|
+
});
|
|
15140
15156
|
}
|
|
15141
|
-
|
|
15142
|
-
|
|
15143
|
-
|
|
15144
|
-
|
|
15145
|
-
|
|
15146
|
-
|
|
15147
|
-
|
|
15148
|
-
|
|
15149
|
-
|
|
15150
|
-
|
|
15151
|
-
|
|
15152
|
-
|
|
15153
|
-
|
|
15154
|
-
|
|
15155
|
-
|
|
15156
|
-
|
|
15157
|
-
|
|
15158
|
-
|
|
15159
|
-
|
|
15160
|
-
|
|
15161
|
-
|
|
15157
|
+
/**
|
|
15158
|
+
* Ensure that a value is a tuple of a specific length, and that each of its
|
|
15159
|
+
* elements is of a specific type.
|
|
15160
|
+
*/
|
|
15161
|
+
function tuple(Structs) {
|
|
15162
|
+
const Never = never();
|
|
15163
|
+
return new Struct({
|
|
15164
|
+
type: 'tuple',
|
|
15165
|
+
schema: null,
|
|
15166
|
+
*entries(value) {
|
|
15167
|
+
if (Array.isArray(value)) {
|
|
15168
|
+
const length = Math.max(Structs.length, value.length);
|
|
15169
|
+
for (let i = 0; i < length; i++) {
|
|
15170
|
+
yield [i, value[i], Structs[i] || Never];
|
|
15171
|
+
}
|
|
15172
|
+
}
|
|
15173
|
+
},
|
|
15174
|
+
validator(value) {
|
|
15175
|
+
return (Array.isArray(value) ||
|
|
15176
|
+
`Expected an array, but received: ${print(value)}`);
|
|
15177
|
+
},
|
|
15178
|
+
});
|
|
15162
15179
|
}
|
|
15163
15180
|
/**
|
|
15164
15181
|
* Ensure that a value has a set of known properties of specific types.
|
|
@@ -15166,62 +15183,71 @@ var solanaWeb3 = (function (exports) {
|
|
|
15166
15183
|
* Note: Unrecognized properties are allowed and untouched. This is similar to
|
|
15167
15184
|
* how TypeScript's structural typing works.
|
|
15168
15185
|
*/
|
|
15169
|
-
|
|
15170
15186
|
function type(schema) {
|
|
15171
|
-
|
|
15172
|
-
|
|
15173
|
-
|
|
15174
|
-
|
|
15175
|
-
|
|
15176
|
-
|
|
15177
|
-
|
|
15178
|
-
|
|
15179
|
-
|
|
15180
|
-
|
|
15181
|
-
|
|
15182
|
-
|
|
15183
|
-
|
|
15184
|
-
|
|
15185
|
-
|
|
15186
|
-
|
|
15187
|
-
|
|
15188
|
-
|
|
15187
|
+
const keys = Object.keys(schema);
|
|
15188
|
+
return new Struct({
|
|
15189
|
+
type: 'type',
|
|
15190
|
+
schema,
|
|
15191
|
+
*entries(value) {
|
|
15192
|
+
if (isObject(value)) {
|
|
15193
|
+
for (const k of keys) {
|
|
15194
|
+
yield [k, value[k], schema[k]];
|
|
15195
|
+
}
|
|
15196
|
+
}
|
|
15197
|
+
},
|
|
15198
|
+
validator(value) {
|
|
15199
|
+
return (isObject(value) || `Expected an object, but received: ${print(value)}`);
|
|
15200
|
+
},
|
|
15201
|
+
coercer(value) {
|
|
15202
|
+
return isObject(value) ? { ...value } : value;
|
|
15203
|
+
},
|
|
15204
|
+
});
|
|
15189
15205
|
}
|
|
15206
|
+
/**
|
|
15207
|
+
* Ensure that a value matches one of a set of types.
|
|
15208
|
+
*/
|
|
15190
15209
|
function union(Structs) {
|
|
15191
|
-
|
|
15192
|
-
|
|
15193
|
-
|
|
15194
|
-
|
|
15195
|
-
|
|
15196
|
-
|
|
15197
|
-
|
|
15198
|
-
|
|
15199
|
-
|
|
15200
|
-
|
|
15201
|
-
const [first] = tuples;
|
|
15202
|
-
|
|
15203
|
-
if (!first[0]) {
|
|
15204
|
-
return [];
|
|
15205
|
-
} else {
|
|
15206
|
-
for (const [failure] of tuples) {
|
|
15207
|
-
if (failure) {
|
|
15208
|
-
failures.push(failure);
|
|
15210
|
+
const description = Structs.map((s) => s.type).join(' | ');
|
|
15211
|
+
return new Struct({
|
|
15212
|
+
type: 'union',
|
|
15213
|
+
schema: null,
|
|
15214
|
+
coercer(value) {
|
|
15215
|
+
for (const S of Structs) {
|
|
15216
|
+
const [error, coerced] = S.validate(value, { coerce: true });
|
|
15217
|
+
if (!error) {
|
|
15218
|
+
return coerced;
|
|
15219
|
+
}
|
|
15209
15220
|
}
|
|
15210
|
-
|
|
15211
|
-
}
|
|
15212
|
-
|
|
15213
|
-
|
|
15214
|
-
|
|
15215
|
-
|
|
15216
|
-
|
|
15217
|
-
|
|
15221
|
+
return value;
|
|
15222
|
+
},
|
|
15223
|
+
validator(value, ctx) {
|
|
15224
|
+
const failures = [];
|
|
15225
|
+
for (const S of Structs) {
|
|
15226
|
+
const [...tuples] = run(value, S, ctx);
|
|
15227
|
+
const [first] = tuples;
|
|
15228
|
+
if (!first[0]) {
|
|
15229
|
+
return [];
|
|
15230
|
+
}
|
|
15231
|
+
else {
|
|
15232
|
+
for (const [failure] of tuples) {
|
|
15233
|
+
if (failure) {
|
|
15234
|
+
failures.push(failure);
|
|
15235
|
+
}
|
|
15236
|
+
}
|
|
15237
|
+
}
|
|
15238
|
+
}
|
|
15239
|
+
return [
|
|
15240
|
+
`Expected the value to satisfy a union of \`${description}\`, but received: ${print(value)}`,
|
|
15241
|
+
...failures,
|
|
15242
|
+
];
|
|
15243
|
+
},
|
|
15244
|
+
});
|
|
15218
15245
|
}
|
|
15219
15246
|
/**
|
|
15220
15247
|
* Ensure that any value passes validation, without widening its type to `any`.
|
|
15221
15248
|
*/
|
|
15222
|
-
|
|
15223
15249
|
function unknown() {
|
|
15224
|
-
|
|
15250
|
+
return define('unknown', () => true);
|
|
15225
15251
|
}
|
|
15226
15252
|
|
|
15227
15253
|
/**
|
|
@@ -15234,13 +15260,15 @@ var solanaWeb3 = (function (exports) {
|
|
|
15234
15260
|
* Note: You must use `create(value, Struct)` on the value to have the coercion
|
|
15235
15261
|
* take effect! Using simply `assert()` or `is()` will not use coercion.
|
|
15236
15262
|
*/
|
|
15237
|
-
|
|
15238
15263
|
function coerce(struct, condition, coercer) {
|
|
15239
|
-
|
|
15240
|
-
|
|
15241
|
-
|
|
15242
|
-
|
|
15243
|
-
|
|
15264
|
+
return new Struct({
|
|
15265
|
+
...struct,
|
|
15266
|
+
coercer: (value, ctx) => {
|
|
15267
|
+
return is(value, condition)
|
|
15268
|
+
? struct.coercer(coercer(value, ctx), ctx)
|
|
15269
|
+
: struct.coercer(value, ctx);
|
|
15270
|
+
},
|
|
15271
|
+
});
|
|
15244
15272
|
}
|
|
15245
15273
|
|
|
15246
15274
|
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
@@ -16153,49 +16181,6 @@ var solanaWeb3 = (function (exports) {
|
|
|
16153
16181
|
}
|
|
16154
16182
|
}
|
|
16155
16183
|
|
|
16156
|
-
class SendTransactionError extends Error {
|
|
16157
|
-
constructor(message, logs) {
|
|
16158
|
-
super(message);
|
|
16159
|
-
this.logs = void 0;
|
|
16160
|
-
this.logs = logs;
|
|
16161
|
-
}
|
|
16162
|
-
}
|
|
16163
|
-
|
|
16164
|
-
// Keep in sync with client/src/rpc_custom_errors.rs
|
|
16165
|
-
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
16166
|
-
const SolanaJSONRPCErrorCode = {
|
|
16167
|
-
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
16168
|
-
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
16169
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
16170
|
-
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
16171
|
-
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
16172
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
16173
|
-
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
16174
|
-
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
16175
|
-
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
16176
|
-
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
16177
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
16178
|
-
JSON_RPC_SCAN_ERROR: -32012,
|
|
16179
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
16180
|
-
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
16181
|
-
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
|
|
16182
|
-
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
|
|
16183
|
-
};
|
|
16184
|
-
class SolanaJSONRPCError extends Error {
|
|
16185
|
-
constructor({
|
|
16186
|
-
code,
|
|
16187
|
-
message,
|
|
16188
|
-
data
|
|
16189
|
-
}, customMessage) {
|
|
16190
|
-
super(customMessage != null ? `${customMessage}: ${message}` : message);
|
|
16191
|
-
this.code = void 0;
|
|
16192
|
-
this.data = void 0;
|
|
16193
|
-
this.code = code;
|
|
16194
|
-
this.data = data;
|
|
16195
|
-
this.name = 'SolanaJSONRPCError';
|
|
16196
|
-
}
|
|
16197
|
-
}
|
|
16198
|
-
|
|
16199
16184
|
var fetchImpl = globalThis.fetch;
|
|
16200
16185
|
|
|
16201
16186
|
var client = {};
|
|
@@ -16591,7 +16576,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
16591
16576
|
Object.defineProperty(client, "__esModule", { value: true });
|
|
16592
16577
|
// @ts-ignore
|
|
16593
16578
|
const eventemitter3_1$1 = eventemitter3Exports;
|
|
16594
|
-
const
|
|
16579
|
+
const utils_cjs_1 = utils;
|
|
16595
16580
|
class CommonClient extends eventemitter3_1$1.EventEmitter {
|
|
16596
16581
|
address;
|
|
16597
16582
|
rpc_id;
|
|
@@ -16635,7 +16620,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
16635
16620
|
this.current_reconnects = 0;
|
|
16636
16621
|
this.generate_request_id = generate_request_id || (() => ++this.rpc_id);
|
|
16637
16622
|
if (!dataPack)
|
|
16638
|
-
this.dataPack = new
|
|
16623
|
+
this.dataPack = new utils_cjs_1.DefaultDataPack();
|
|
16639
16624
|
else
|
|
16640
16625
|
this.dataPack = dataPack;
|
|
16641
16626
|
if (this.autoconnect)
|
|
@@ -17070,7 +17055,7 @@ var solanaWeb3 = (function (exports) {
|
|
|
17070
17055
|
const websocketPort =
|
|
17071
17056
|
// Only shift the port by +1 as a convention for ws(s) only if given endpoint
|
|
17072
17057
|
// is explicitly specifying the endpoint port (HTTP-based RPC), assuming
|
|
17073
|
-
// we're directly trying to connect to
|
|
17058
|
+
// we're directly trying to connect to agave-validator's ws listening port.
|
|
17074
17059
|
// When the endpoint omits the port, we're connecting to the protocol
|
|
17075
17060
|
// default ports: http(80) or https(443) and it's assumed we're behind a reverse
|
|
17076
17061
|
// proxy which manages WebSocket upgrade and backend port redirection.
|
|
@@ -20709,7 +20694,12 @@ var solanaWeb3 = (function (exports) {
|
|
|
20709
20694
|
console.error(res.error.message, logTrace);
|
|
20710
20695
|
}
|
|
20711
20696
|
}
|
|
20712
|
-
throw new SendTransactionError(
|
|
20697
|
+
throw new SendTransactionError({
|
|
20698
|
+
action: 'simulate',
|
|
20699
|
+
signature: '',
|
|
20700
|
+
transactionMessage: res.error.message,
|
|
20701
|
+
transactionLogs: logs
|
|
20702
|
+
});
|
|
20713
20703
|
}
|
|
20714
20704
|
return res.result;
|
|
20715
20705
|
}
|
|
@@ -20810,11 +20800,16 @@ var solanaWeb3 = (function (exports) {
|
|
|
20810
20800
|
const unsafeRes = await this._rpcRequest('sendTransaction', args);
|
|
20811
20801
|
const res = create(unsafeRes, SendTransactionRpcResult);
|
|
20812
20802
|
if ('error' in res) {
|
|
20813
|
-
let logs;
|
|
20803
|
+
let logs = undefined;
|
|
20814
20804
|
if ('data' in res.error) {
|
|
20815
20805
|
logs = res.error.data.logs;
|
|
20816
20806
|
}
|
|
20817
|
-
throw new SendTransactionError(
|
|
20807
|
+
throw new SendTransactionError({
|
|
20808
|
+
action: skipPreflight ? 'send' : 'simulate',
|
|
20809
|
+
signature: '',
|
|
20810
|
+
transactionMessage: res.error.message,
|
|
20811
|
+
transactionLogs: logs
|
|
20812
|
+
});
|
|
20818
20813
|
}
|
|
20819
20814
|
return res.result;
|
|
20820
20815
|
}
|
|
@@ -25106,6 +25101,13 @@ var solanaWeb3 = (function (exports) {
|
|
|
25106
25101
|
const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
|
|
25107
25102
|
const status = (await confirmationPromise).value;
|
|
25108
25103
|
if (status.err) {
|
|
25104
|
+
if (signature != null) {
|
|
25105
|
+
throw new SendTransactionError({
|
|
25106
|
+
action: sendOptions?.skipPreflight ? 'send' : 'simulate',
|
|
25107
|
+
signature: signature,
|
|
25108
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
25109
|
+
});
|
|
25110
|
+
}
|
|
25109
25111
|
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
25110
25112
|
}
|
|
25111
25113
|
return signature;
|