@solana/web3.js 2.0.0-experimental.b9c1a94 → 2.0.0-experimental.ba46ce1
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/dist/index.browser.cjs +314 -8
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +315 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.development.js +763 -29
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.js +304 -11
- package/dist/index.native.js.map +1 -1
- package/dist/index.node.cjs +303 -8
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +304 -11
- package/dist/index.node.js.map +1 -1
- package/dist/index.production.min.js +35 -31
- package/dist/types/cached-abortable-iterable.d.ts +11 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/rpc-subscription-coalescer.d.ts +10 -0
- package/dist/types/rpc-websocket-autopinger.d.ts +8 -0
- package/dist/types/rpc-websocket-connection-sharding.d.ts +13 -0
- package/dist/types/rpc-websocket-transport.d.ts +13 -0
- package/dist/types/rpc.d.ts +4 -3
- package/package.json +12 -11
|
@@ -715,6 +715,21 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
715
715
|
throw new Error("No signature verification implementation could be found");
|
|
716
716
|
}
|
|
717
717
|
}
|
|
718
|
+
function isBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
719
|
+
if (
|
|
720
|
+
// Lowest address (32 bytes of zeroes)
|
|
721
|
+
putativeBase58EncodedAddress.length < 32 || // Highest address (32 bytes of 255)
|
|
722
|
+
putativeBase58EncodedAddress.length > 44
|
|
723
|
+
) {
|
|
724
|
+
return false;
|
|
725
|
+
}
|
|
726
|
+
const bytes2 = base58.serialize(putativeBase58EncodedAddress);
|
|
727
|
+
const numBytes = bytes2.byteLength;
|
|
728
|
+
if (numBytes !== 32) {
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
return true;
|
|
732
|
+
}
|
|
718
733
|
function assertIsBase58EncodedAddress(putativeBase58EncodedAddress) {
|
|
719
734
|
try {
|
|
720
735
|
if (
|
|
@@ -735,6 +750,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
735
750
|
});
|
|
736
751
|
}
|
|
737
752
|
}
|
|
753
|
+
function address(putativeBase58EncodedAddress) {
|
|
754
|
+
assertIsBase58EncodedAddress(putativeBase58EncodedAddress);
|
|
755
|
+
return putativeBase58EncodedAddress;
|
|
756
|
+
}
|
|
738
757
|
function getBase58EncodedAddressCodec(config) {
|
|
739
758
|
return string({
|
|
740
759
|
description: config?.description ?? ("A 32-byte account address" ),
|
|
@@ -1167,8 +1186,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1167
1186
|
Object.freeze(out);
|
|
1168
1187
|
return out;
|
|
1169
1188
|
}
|
|
1170
|
-
function upsert(addressMap,
|
|
1171
|
-
addressMap[
|
|
1189
|
+
function upsert(addressMap, address2, update) {
|
|
1190
|
+
addressMap[address2] = update(addressMap[address2] ?? { role: AccountRole2.READONLY });
|
|
1172
1191
|
}
|
|
1173
1192
|
var TYPE = Symbol("AddressMapTypeProperty");
|
|
1174
1193
|
function getAddressMapFromInstructions(feePayer, instructions) {
|
|
@@ -1333,8 +1352,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1333
1352
|
} else {
|
|
1334
1353
|
return addressComparator(leftAddress, rightAddress);
|
|
1335
1354
|
}
|
|
1336
|
-
}).map(([
|
|
1337
|
-
address,
|
|
1355
|
+
}).map(([address2, addressMeta]) => ({
|
|
1356
|
+
address: address2,
|
|
1338
1357
|
...addressMeta
|
|
1339
1358
|
}));
|
|
1340
1359
|
return orderedAccounts;
|
|
@@ -1397,7 +1416,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1397
1416
|
return instructions.map(({ accounts, data, programAddress }) => {
|
|
1398
1417
|
return {
|
|
1399
1418
|
programAddressIndex: accountIndex[programAddress],
|
|
1400
|
-
...accounts ? { accountIndices: accounts.map(({ address }) => accountIndex[
|
|
1419
|
+
...accounts ? { accountIndices: accounts.map(({ address: address2 }) => accountIndex[address2]) } : null,
|
|
1401
1420
|
...data ? { data } : null
|
|
1402
1421
|
};
|
|
1403
1422
|
});
|
|
@@ -1411,7 +1430,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1411
1430
|
function getCompiledStaticAccounts(orderedAccounts) {
|
|
1412
1431
|
const firstLookupTableAccountIndex = orderedAccounts.findIndex((account) => "lookupTableAddress" in account);
|
|
1413
1432
|
const orderedStaticAccounts = firstLookupTableAccountIndex === -1 ? orderedAccounts : orderedAccounts.slice(0, firstLookupTableAccountIndex);
|
|
1414
|
-
return orderedStaticAccounts.map(({ address }) =>
|
|
1433
|
+
return orderedStaticAccounts.map(({ address: address2 }) => address2);
|
|
1415
1434
|
}
|
|
1416
1435
|
function compileMessage(transaction) {
|
|
1417
1436
|
const addressMap = getAddressMapFromInstructions(transaction.feePayer, transaction.instructions);
|
|
@@ -1661,16 +1680,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1661
1680
|
const signature = await signBytes(secretKey, wireMessageBytes);
|
|
1662
1681
|
return signature;
|
|
1663
1682
|
}
|
|
1664
|
-
async function signTransaction(
|
|
1683
|
+
async function signTransaction(keyPairs, transaction) {
|
|
1665
1684
|
const compiledMessage = compileMessage(transaction);
|
|
1666
|
-
const
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1685
|
+
const nextSignatures = "signatures" in transaction ? { ...transaction.signatures } : {};
|
|
1686
|
+
const publicKeySignaturePairs = await Promise.all(
|
|
1687
|
+
keyPairs.map(
|
|
1688
|
+
(keyPair) => Promise.all([
|
|
1689
|
+
getAddressFromPublicKey(keyPair.publicKey),
|
|
1690
|
+
getCompiledMessageSignature(compiledMessage, keyPair.privateKey)
|
|
1691
|
+
])
|
|
1692
|
+
)
|
|
1693
|
+
);
|
|
1694
|
+
for (const [signerPublicKey, signature] of publicKeySignaturePairs) {
|
|
1695
|
+
nextSignatures[signerPublicKey] = signature;
|
|
1696
|
+
}
|
|
1674
1697
|
const out = {
|
|
1675
1698
|
...transaction,
|
|
1676
1699
|
signatures: nextSignatures
|
|
@@ -1729,6 +1752,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1729
1752
|
// src/rpc.ts
|
|
1730
1753
|
init_env_shim();
|
|
1731
1754
|
|
|
1755
|
+
// ../functional/dist/index.browser.js
|
|
1756
|
+
init_env_shim();
|
|
1757
|
+
function pipe(init, ...fns) {
|
|
1758
|
+
return fns.reduce((acc, fn) => fn(acc), init);
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1732
1761
|
// ../rpc-core/dist/index.browser.js
|
|
1733
1762
|
init_env_shim();
|
|
1734
1763
|
function visitNode(value, keyPath, onIntegerOverflow) {
|
|
@@ -1757,9 +1786,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1757
1786
|
return visitNode(params, [], onIntegerOverflow);
|
|
1758
1787
|
}
|
|
1759
1788
|
var KEYPATH_WILDCARD = {};
|
|
1760
|
-
var
|
|
1761
|
-
|
|
1762
|
-
|
|
1789
|
+
var memoizedNotificationKeypaths;
|
|
1790
|
+
var memoizedResponseKeypaths;
|
|
1791
|
+
function getAllowedNumericKeypathsForNotification() {
|
|
1792
|
+
if (!memoizedNotificationKeypaths) {
|
|
1793
|
+
memoizedNotificationKeypaths = {};
|
|
1794
|
+
}
|
|
1795
|
+
return memoizedNotificationKeypaths;
|
|
1796
|
+
}
|
|
1797
|
+
function getAllowedNumericKeypathsForResponse() {
|
|
1798
|
+
if (!memoizedResponseKeypaths) {
|
|
1763
1799
|
const jsonParsedTokenAccountsConfigs = [
|
|
1764
1800
|
// parsed Token/Token22 token account
|
|
1765
1801
|
["data", "parsed", "info", "tokenAmount", "decimals"],
|
|
@@ -1812,8 +1848,97 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1812
1848
|
["data", "parsed", "info", "commission"],
|
|
1813
1849
|
["data", "parsed", "info", "votes", KEYPATH_WILDCARD, "confirmationCount"]
|
|
1814
1850
|
];
|
|
1815
|
-
|
|
1851
|
+
memoizedResponseKeypaths = {
|
|
1816
1852
|
getAccountInfo: jsonParsedAccountsConfigs.map((c) => ["value", ...c]),
|
|
1853
|
+
getBlock: [
|
|
1854
|
+
["blockTime"],
|
|
1855
|
+
["transactions", KEYPATH_WILDCARD, "meta", "preTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
1856
|
+
[
|
|
1857
|
+
"transactions",
|
|
1858
|
+
KEYPATH_WILDCARD,
|
|
1859
|
+
"meta",
|
|
1860
|
+
"preTokenBalances",
|
|
1861
|
+
KEYPATH_WILDCARD,
|
|
1862
|
+
"uiTokenAmount",
|
|
1863
|
+
"decimals"
|
|
1864
|
+
],
|
|
1865
|
+
["transactions", KEYPATH_WILDCARD, "meta", "postTokenBalances", KEYPATH_WILDCARD, "accountIndex"],
|
|
1866
|
+
[
|
|
1867
|
+
"transactions",
|
|
1868
|
+
KEYPATH_WILDCARD,
|
|
1869
|
+
"meta",
|
|
1870
|
+
"postTokenBalances",
|
|
1871
|
+
KEYPATH_WILDCARD,
|
|
1872
|
+
"uiTokenAmount",
|
|
1873
|
+
"decimals"
|
|
1874
|
+
],
|
|
1875
|
+
["transactions", KEYPATH_WILDCARD, "meta", "rewards", KEYPATH_WILDCARD, "commission"],
|
|
1876
|
+
["transactions", KEYPATH_WILDCARD, "meta", "innerInstructions", KEYPATH_WILDCARD, "index"],
|
|
1877
|
+
[
|
|
1878
|
+
"transactions",
|
|
1879
|
+
KEYPATH_WILDCARD,
|
|
1880
|
+
"meta",
|
|
1881
|
+
"innerInstructions",
|
|
1882
|
+
KEYPATH_WILDCARD,
|
|
1883
|
+
"instructions",
|
|
1884
|
+
KEYPATH_WILDCARD,
|
|
1885
|
+
"programIdIndex"
|
|
1886
|
+
],
|
|
1887
|
+
[
|
|
1888
|
+
"transactions",
|
|
1889
|
+
KEYPATH_WILDCARD,
|
|
1890
|
+
"meta",
|
|
1891
|
+
"innerInstructions",
|
|
1892
|
+
KEYPATH_WILDCARD,
|
|
1893
|
+
"instructions",
|
|
1894
|
+
KEYPATH_WILDCARD,
|
|
1895
|
+
"accounts",
|
|
1896
|
+
KEYPATH_WILDCARD
|
|
1897
|
+
],
|
|
1898
|
+
[
|
|
1899
|
+
"transactions",
|
|
1900
|
+
KEYPATH_WILDCARD,
|
|
1901
|
+
"transaction",
|
|
1902
|
+
"message",
|
|
1903
|
+
"addressTableLookups",
|
|
1904
|
+
KEYPATH_WILDCARD,
|
|
1905
|
+
"writableIndexes",
|
|
1906
|
+
KEYPATH_WILDCARD
|
|
1907
|
+
],
|
|
1908
|
+
[
|
|
1909
|
+
"transactions",
|
|
1910
|
+
KEYPATH_WILDCARD,
|
|
1911
|
+
"transaction",
|
|
1912
|
+
"message",
|
|
1913
|
+
"addressTableLookups",
|
|
1914
|
+
KEYPATH_WILDCARD,
|
|
1915
|
+
"readonlyIndexes",
|
|
1916
|
+
KEYPATH_WILDCARD
|
|
1917
|
+
],
|
|
1918
|
+
[
|
|
1919
|
+
"transactions",
|
|
1920
|
+
KEYPATH_WILDCARD,
|
|
1921
|
+
"transaction",
|
|
1922
|
+
"message",
|
|
1923
|
+
"instructions",
|
|
1924
|
+
KEYPATH_WILDCARD,
|
|
1925
|
+
"programIdIndex"
|
|
1926
|
+
],
|
|
1927
|
+
[
|
|
1928
|
+
"transactions",
|
|
1929
|
+
KEYPATH_WILDCARD,
|
|
1930
|
+
"transaction",
|
|
1931
|
+
"message",
|
|
1932
|
+
"instructions",
|
|
1933
|
+
KEYPATH_WILDCARD,
|
|
1934
|
+
"accounts",
|
|
1935
|
+
KEYPATH_WILDCARD
|
|
1936
|
+
],
|
|
1937
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlySignedAccounts"],
|
|
1938
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numReadonlyUnsignedAccounts"],
|
|
1939
|
+
["transactions", KEYPATH_WILDCARD, "transaction", "message", "header", "numRequiredSignatures"],
|
|
1940
|
+
["rewards", KEYPATH_WILDCARD, "commission"]
|
|
1941
|
+
],
|
|
1817
1942
|
getBlockTime: [[]],
|
|
1818
1943
|
getClusterNodes: [
|
|
1819
1944
|
[KEYPATH_WILDCARD, "featureSet"],
|
|
@@ -1899,7 +2024,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1899
2024
|
simulateTransaction: jsonParsedAccountsConfigs.map((c) => ["value", "accounts", KEYPATH_WILDCARD, ...c])
|
|
1900
2025
|
};
|
|
1901
2026
|
}
|
|
1902
|
-
return
|
|
2027
|
+
return memoizedResponseKeypaths;
|
|
1903
2028
|
}
|
|
1904
2029
|
function getNextAllowedKeypaths(keyPaths, property) {
|
|
1905
2030
|
return keyPaths.filter((keyPath) => keyPath[0] === KEYPATH_WILDCARD && typeof property === "number" || keyPath[0] === property).map((keyPath) => keyPath.slice(1));
|
|
@@ -1927,7 +2052,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1927
2052
|
}
|
|
1928
2053
|
}
|
|
1929
2054
|
function patchResponseForSolanaLabsRpc(rawResponse, methodName) {
|
|
1930
|
-
const allowedKeypaths = methodName ?
|
|
2055
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForResponse()[methodName] : void 0;
|
|
2056
|
+
return visitNode2(rawResponse, allowedKeypaths ?? []);
|
|
2057
|
+
}
|
|
2058
|
+
function patchResponseForSolanaLabsRpcSubscriptions(rawResponse, methodName) {
|
|
2059
|
+
const allowedKeypaths = methodName ? getAllowedNumericKeypathsForNotification()[methodName] : void 0;
|
|
1931
2060
|
return visitNode2(rawResponse, allowedKeypaths ?? []);
|
|
1932
2061
|
}
|
|
1933
2062
|
function createSolanaRpcApi(config) {
|
|
@@ -1956,6 +2085,33 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
1956
2085
|
}
|
|
1957
2086
|
});
|
|
1958
2087
|
}
|
|
2088
|
+
function createSolanaRpcSubscriptionsApi(config) {
|
|
2089
|
+
return new Proxy({}, {
|
|
2090
|
+
defineProperty() {
|
|
2091
|
+
return false;
|
|
2092
|
+
},
|
|
2093
|
+
deleteProperty() {
|
|
2094
|
+
return false;
|
|
2095
|
+
},
|
|
2096
|
+
get(...args) {
|
|
2097
|
+
const [_, p] = args;
|
|
2098
|
+
const notificationName = p.toString();
|
|
2099
|
+
return function(...rawParams) {
|
|
2100
|
+
const handleIntegerOverflow = config?.onIntegerOverflow;
|
|
2101
|
+
const params = patchParamsForSolanaLabsRpc(
|
|
2102
|
+
rawParams,
|
|
2103
|
+
handleIntegerOverflow ? (keyPath, value) => handleIntegerOverflow(notificationName, keyPath, value) : void 0
|
|
2104
|
+
);
|
|
2105
|
+
return {
|
|
2106
|
+
params,
|
|
2107
|
+
responseProcessor: (rawResponse) => patchResponseForSolanaLabsRpcSubscriptions(rawResponse, notificationName),
|
|
2108
|
+
subscribeMethodName: notificationName.replace(/Notifications$/, "Subscribe"),
|
|
2109
|
+
unsubscribeMethodName: notificationName.replace(/Notifications$/, "Unsubscribe")
|
|
2110
|
+
};
|
|
2111
|
+
};
|
|
2112
|
+
}
|
|
2113
|
+
});
|
|
2114
|
+
}
|
|
1959
2115
|
|
|
1960
2116
|
// ../rpc-transport/dist/index.browser.js
|
|
1961
2117
|
init_env_shim();
|
|
@@ -2022,6 +2178,100 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2022
2178
|
function createJsonRpc(rpcConfig) {
|
|
2023
2179
|
return makeProxy(rpcConfig);
|
|
2024
2180
|
}
|
|
2181
|
+
function registerIterableCleanup(iterable, cleanupFn) {
|
|
2182
|
+
(async () => {
|
|
2183
|
+
try {
|
|
2184
|
+
for await (const _ of iterable)
|
|
2185
|
+
;
|
|
2186
|
+
} catch {
|
|
2187
|
+
} finally {
|
|
2188
|
+
cleanupFn();
|
|
2189
|
+
}
|
|
2190
|
+
})();
|
|
2191
|
+
}
|
|
2192
|
+
function createPendingRpcSubscription(rpcConfig, { params, subscribeMethodName, unsubscribeMethodName, responseProcessor }) {
|
|
2193
|
+
return {
|
|
2194
|
+
async subscribe({ abortSignal }) {
|
|
2195
|
+
abortSignal.throwIfAborted();
|
|
2196
|
+
let subscriptionId;
|
|
2197
|
+
function handleCleanup() {
|
|
2198
|
+
if (subscriptionId !== void 0) {
|
|
2199
|
+
const payload = createJsonRpcMessage(unsubscribeMethodName, [subscriptionId]);
|
|
2200
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload).finally(() => {
|
|
2201
|
+
connectionAbortController.abort();
|
|
2202
|
+
});
|
|
2203
|
+
} else {
|
|
2204
|
+
connectionAbortController.abort();
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
abortSignal.addEventListener("abort", handleCleanup);
|
|
2208
|
+
const connectionAbortController = new AbortController();
|
|
2209
|
+
const subscribeMessage = createJsonRpcMessage(subscribeMethodName, params);
|
|
2210
|
+
const connection = await rpcConfig.transport({
|
|
2211
|
+
payload: subscribeMessage,
|
|
2212
|
+
signal: connectionAbortController.signal
|
|
2213
|
+
});
|
|
2214
|
+
function handleConnectionCleanup() {
|
|
2215
|
+
abortSignal.removeEventListener("abort", handleCleanup);
|
|
2216
|
+
}
|
|
2217
|
+
registerIterableCleanup(connection, handleConnectionCleanup);
|
|
2218
|
+
for await (const message of connection) {
|
|
2219
|
+
if ("id" in message && message.id === subscribeMessage.id) {
|
|
2220
|
+
if ("error" in message) {
|
|
2221
|
+
throw new SolanaJsonRpcError(message.error);
|
|
2222
|
+
} else {
|
|
2223
|
+
subscriptionId = message.result;
|
|
2224
|
+
break;
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
if (subscriptionId == null) {
|
|
2229
|
+
throw new Error("Failed to obtain a subscription id from the server");
|
|
2230
|
+
}
|
|
2231
|
+
return {
|
|
2232
|
+
async *[Symbol.asyncIterator]() {
|
|
2233
|
+
for await (const message of connection) {
|
|
2234
|
+
if (!("params" in message) || message.params.subscription !== subscriptionId) {
|
|
2235
|
+
continue;
|
|
2236
|
+
}
|
|
2237
|
+
const notification = message.params.result;
|
|
2238
|
+
yield responseProcessor ? responseProcessor(notification) : notification;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2244
|
+
}
|
|
2245
|
+
function makeProxy2(rpcConfig) {
|
|
2246
|
+
return new Proxy(rpcConfig.api, {
|
|
2247
|
+
defineProperty() {
|
|
2248
|
+
return false;
|
|
2249
|
+
},
|
|
2250
|
+
deleteProperty() {
|
|
2251
|
+
return false;
|
|
2252
|
+
},
|
|
2253
|
+
get(target, p, receiver) {
|
|
2254
|
+
return function(...rawParams) {
|
|
2255
|
+
const methodName = p.toString();
|
|
2256
|
+
const createRpcSubscription = Reflect.get(target, methodName, receiver);
|
|
2257
|
+
if (p.toString().endsWith("Notifications") === false && !createRpcSubscription) {
|
|
2258
|
+
throw new Error(
|
|
2259
|
+
"Either the notification name must end in 'Notifications' or the API must supply a subscription creator function to map between the notification name and the subscribe/unsubscribe method names."
|
|
2260
|
+
);
|
|
2261
|
+
}
|
|
2262
|
+
const newRequest = createRpcSubscription ? createRpcSubscription(...rawParams) : {
|
|
2263
|
+
params: rawParams,
|
|
2264
|
+
subscribeMethodName: methodName.replace(/Notifications$/, "Subscribe"),
|
|
2265
|
+
unsubscribeMethodName: methodName.replace(/Notifications$/, "Unsubscribe")
|
|
2266
|
+
};
|
|
2267
|
+
return createPendingRpcSubscription(rpcConfig, newRequest);
|
|
2268
|
+
};
|
|
2269
|
+
}
|
|
2270
|
+
});
|
|
2271
|
+
}
|
|
2272
|
+
function createJsonSubscriptionRpc(rpcConfig) {
|
|
2273
|
+
return makeProxy2(rpcConfig);
|
|
2274
|
+
}
|
|
2025
2275
|
var e = globalThis.fetch;
|
|
2026
2276
|
var SolanaHttpError = class extends Error {
|
|
2027
2277
|
constructor(details) {
|
|
@@ -2120,6 +2370,175 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2120
2370
|
return await response.json();
|
|
2121
2371
|
};
|
|
2122
2372
|
}
|
|
2373
|
+
var e2 = globalThis.WebSocket;
|
|
2374
|
+
var EXPLICIT_ABORT_TOKEN = Symbol(
|
|
2375
|
+
"This symbol is thrown from a socket's iterator when the connection is explicity aborted by the user"
|
|
2376
|
+
);
|
|
2377
|
+
async function createWebSocketConnection({
|
|
2378
|
+
sendBufferHighWatermark,
|
|
2379
|
+
signal,
|
|
2380
|
+
url
|
|
2381
|
+
}) {
|
|
2382
|
+
return new Promise((resolve, reject) => {
|
|
2383
|
+
signal.addEventListener("abort", handleAbort, { once: true });
|
|
2384
|
+
const iteratorState = /* @__PURE__ */ new Map();
|
|
2385
|
+
function errorAndClearAllIteratorStates(reason) {
|
|
2386
|
+
const errorCallbacks = [...iteratorState.values()].filter((state) => state.__hasPolled).map(({ onError }) => onError);
|
|
2387
|
+
iteratorState.clear();
|
|
2388
|
+
errorCallbacks.forEach((cb) => {
|
|
2389
|
+
try {
|
|
2390
|
+
cb(reason);
|
|
2391
|
+
} catch {
|
|
2392
|
+
}
|
|
2393
|
+
});
|
|
2394
|
+
}
|
|
2395
|
+
function handleAbort() {
|
|
2396
|
+
errorAndClearAllIteratorStates(EXPLICIT_ABORT_TOKEN);
|
|
2397
|
+
if (webSocket.readyState !== e2.CLOSED && webSocket.readyState !== e2.CLOSING) {
|
|
2398
|
+
webSocket.close(1e3);
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
function handleClose(ev) {
|
|
2402
|
+
bufferDrainWatcher?.onCancel();
|
|
2403
|
+
signal.removeEventListener("abort", handleAbort);
|
|
2404
|
+
webSocket.removeEventListener("close", handleClose);
|
|
2405
|
+
webSocket.removeEventListener("error", handleError);
|
|
2406
|
+
webSocket.removeEventListener("open", handleOpen);
|
|
2407
|
+
webSocket.removeEventListener("message", handleMessage);
|
|
2408
|
+
errorAndClearAllIteratorStates(ev);
|
|
2409
|
+
}
|
|
2410
|
+
function handleError(ev) {
|
|
2411
|
+
if (!hasConnected) {
|
|
2412
|
+
reject(
|
|
2413
|
+
// TODO: Coded error
|
|
2414
|
+
new Error("WebSocket failed to connect", { cause: ev })
|
|
2415
|
+
);
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
let hasConnected = false;
|
|
2419
|
+
let bufferDrainWatcher;
|
|
2420
|
+
function handleOpen() {
|
|
2421
|
+
hasConnected = true;
|
|
2422
|
+
resolve({
|
|
2423
|
+
async send(payload) {
|
|
2424
|
+
const message = JSON.stringify(payload);
|
|
2425
|
+
if (!bufferDrainWatcher && webSocket.readyState === e2.OPEN && webSocket.bufferedAmount > sendBufferHighWatermark) {
|
|
2426
|
+
let onCancel;
|
|
2427
|
+
const promise = new Promise((resolve2, reject2) => {
|
|
2428
|
+
const intervalId = setInterval(() => {
|
|
2429
|
+
if (webSocket.readyState !== e2.OPEN || !(webSocket.bufferedAmount > sendBufferHighWatermark)) {
|
|
2430
|
+
clearInterval(intervalId);
|
|
2431
|
+
bufferDrainWatcher = void 0;
|
|
2432
|
+
resolve2();
|
|
2433
|
+
}
|
|
2434
|
+
}, 16);
|
|
2435
|
+
onCancel = () => {
|
|
2436
|
+
bufferDrainWatcher = void 0;
|
|
2437
|
+
clearInterval(intervalId);
|
|
2438
|
+
reject2(
|
|
2439
|
+
// TODO: Coded error
|
|
2440
|
+
new Error("WebSocket was closed before payload could be sent")
|
|
2441
|
+
);
|
|
2442
|
+
};
|
|
2443
|
+
});
|
|
2444
|
+
bufferDrainWatcher = {
|
|
2445
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2446
|
+
// @ts-ignore
|
|
2447
|
+
onCancel,
|
|
2448
|
+
promise
|
|
2449
|
+
};
|
|
2450
|
+
}
|
|
2451
|
+
if (bufferDrainWatcher) {
|
|
2452
|
+
await bufferDrainWatcher.promise;
|
|
2453
|
+
}
|
|
2454
|
+
webSocket.send(message);
|
|
2455
|
+
},
|
|
2456
|
+
async *[Symbol.asyncIterator]() {
|
|
2457
|
+
const iteratorKey = Symbol();
|
|
2458
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
2459
|
+
try {
|
|
2460
|
+
while (true) {
|
|
2461
|
+
const state = iteratorState.get(iteratorKey);
|
|
2462
|
+
if (!state) {
|
|
2463
|
+
throw new Error("Invariant: WebSocket message iterator is missing state storage");
|
|
2464
|
+
}
|
|
2465
|
+
if (state.__hasPolled) {
|
|
2466
|
+
throw new Error(
|
|
2467
|
+
"Invariant: WebSocket message iterator state is corrupt; iterated without first resolving existing message promise"
|
|
2468
|
+
);
|
|
2469
|
+
}
|
|
2470
|
+
const queuedMessages = state.queuedMessages;
|
|
2471
|
+
if (queuedMessages.length) {
|
|
2472
|
+
state.queuedMessages = [];
|
|
2473
|
+
yield* queuedMessages;
|
|
2474
|
+
} else {
|
|
2475
|
+
try {
|
|
2476
|
+
yield await new Promise((resolve2, reject2) => {
|
|
2477
|
+
iteratorState.set(iteratorKey, {
|
|
2478
|
+
__hasPolled: true,
|
|
2479
|
+
onError: reject2,
|
|
2480
|
+
onMessage: resolve2
|
|
2481
|
+
});
|
|
2482
|
+
});
|
|
2483
|
+
} catch (e3) {
|
|
2484
|
+
if (e3 === EXPLICIT_ABORT_TOKEN) {
|
|
2485
|
+
return;
|
|
2486
|
+
} else {
|
|
2487
|
+
throw new Error("WebSocket connection closed", { cause: e3 });
|
|
2488
|
+
}
|
|
2489
|
+
}
|
|
2490
|
+
}
|
|
2491
|
+
}
|
|
2492
|
+
} finally {
|
|
2493
|
+
iteratorState.delete(iteratorKey);
|
|
2494
|
+
}
|
|
2495
|
+
}
|
|
2496
|
+
});
|
|
2497
|
+
}
|
|
2498
|
+
function handleMessage({ data }) {
|
|
2499
|
+
const message = JSON.parse(data);
|
|
2500
|
+
iteratorState.forEach((state, iteratorKey) => {
|
|
2501
|
+
if (state.__hasPolled) {
|
|
2502
|
+
const { onMessage } = state;
|
|
2503
|
+
iteratorState.set(iteratorKey, { __hasPolled: false, queuedMessages: [] });
|
|
2504
|
+
onMessage(message);
|
|
2505
|
+
} else {
|
|
2506
|
+
state.queuedMessages.push(message);
|
|
2507
|
+
}
|
|
2508
|
+
});
|
|
2509
|
+
}
|
|
2510
|
+
const webSocket = new e2(url);
|
|
2511
|
+
webSocket.addEventListener("close", handleClose);
|
|
2512
|
+
webSocket.addEventListener("error", handleError);
|
|
2513
|
+
webSocket.addEventListener("open", handleOpen);
|
|
2514
|
+
webSocket.addEventListener("message", handleMessage);
|
|
2515
|
+
});
|
|
2516
|
+
}
|
|
2517
|
+
function createWebSocketTransport({ sendBufferHighWatermark, url }) {
|
|
2518
|
+
if (/^wss?:/i.test(url) === false) {
|
|
2519
|
+
const protocolMatch = url.match(/^([^:]+):/);
|
|
2520
|
+
throw new DOMException(
|
|
2521
|
+
protocolMatch ? `Failed to construct 'WebSocket': The URL's scheme must be either 'ws' or 'wss'. '${protocolMatch[1]}:' is not allowed.` : `Failed to construct 'WebSocket': The URL '${url}' is invalid.`
|
|
2522
|
+
);
|
|
2523
|
+
}
|
|
2524
|
+
return async function sendWebSocketMessage({ payload, signal }) {
|
|
2525
|
+
signal?.throwIfAborted();
|
|
2526
|
+
const connection = await createWebSocketConnection({
|
|
2527
|
+
sendBufferHighWatermark,
|
|
2528
|
+
signal,
|
|
2529
|
+
url
|
|
2530
|
+
});
|
|
2531
|
+
signal?.throwIfAborted();
|
|
2532
|
+
await connection.send(payload);
|
|
2533
|
+
return {
|
|
2534
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
2535
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: connection.send.bind(connection)
|
|
2536
|
+
};
|
|
2537
|
+
};
|
|
2538
|
+
}
|
|
2539
|
+
|
|
2540
|
+
// src/rpc.ts
|
|
2541
|
+
var import_fast_stable_stringify = __toESM(require_fast_stable_stringify(), 1);
|
|
2123
2542
|
|
|
2124
2543
|
// src/rpc-default-config.ts
|
|
2125
2544
|
init_env_shim();
|
|
@@ -2161,6 +2580,197 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2161
2580
|
}
|
|
2162
2581
|
};
|
|
2163
2582
|
|
|
2583
|
+
// src/rpc-subscription-coalescer.ts
|
|
2584
|
+
init_env_shim();
|
|
2585
|
+
|
|
2586
|
+
// src/cached-abortable-iterable.ts
|
|
2587
|
+
init_env_shim();
|
|
2588
|
+
function registerIterableCleanup2(iterable, cleanupFn) {
|
|
2589
|
+
(async () => {
|
|
2590
|
+
try {
|
|
2591
|
+
for await (const _ of iterable)
|
|
2592
|
+
;
|
|
2593
|
+
} catch {
|
|
2594
|
+
} finally {
|
|
2595
|
+
cleanupFn();
|
|
2596
|
+
}
|
|
2597
|
+
})();
|
|
2598
|
+
}
|
|
2599
|
+
function getCachedAbortableIterableFactory({
|
|
2600
|
+
getAbortSignalFromInputArgs,
|
|
2601
|
+
getCacheEntryMissingError,
|
|
2602
|
+
getCacheKeyFromInputArgs,
|
|
2603
|
+
onCacheHit,
|
|
2604
|
+
onCreateIterable
|
|
2605
|
+
}) {
|
|
2606
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2607
|
+
function getCacheEntryOrThrow(cacheKey) {
|
|
2608
|
+
const currentCacheEntry = cache.get(cacheKey);
|
|
2609
|
+
if (!currentCacheEntry) {
|
|
2610
|
+
throw getCacheEntryMissingError(cacheKey);
|
|
2611
|
+
}
|
|
2612
|
+
return currentCacheEntry;
|
|
2613
|
+
}
|
|
2614
|
+
return async (...args) => {
|
|
2615
|
+
const cacheKey = getCacheKeyFromInputArgs(...args);
|
|
2616
|
+
const signal = getAbortSignalFromInputArgs(...args);
|
|
2617
|
+
if (cacheKey === void 0) {
|
|
2618
|
+
return await onCreateIterable(signal, ...args);
|
|
2619
|
+
}
|
|
2620
|
+
const cleanup = () => {
|
|
2621
|
+
cache.delete(cacheKey);
|
|
2622
|
+
signal.removeEventListener("abort", handleAbort);
|
|
2623
|
+
};
|
|
2624
|
+
const handleAbort = () => {
|
|
2625
|
+
const cacheEntry = getCacheEntryOrThrow(cacheKey);
|
|
2626
|
+
if (cacheEntry.purgeScheduled !== true) {
|
|
2627
|
+
cacheEntry.purgeScheduled = true;
|
|
2628
|
+
globalThis.queueMicrotask(() => {
|
|
2629
|
+
cacheEntry.purgeScheduled = false;
|
|
2630
|
+
if (cacheEntry.referenceCount === 0) {
|
|
2631
|
+
cacheEntry.abortController.abort();
|
|
2632
|
+
cleanup();
|
|
2633
|
+
}
|
|
2634
|
+
});
|
|
2635
|
+
}
|
|
2636
|
+
cacheEntry.referenceCount--;
|
|
2637
|
+
};
|
|
2638
|
+
signal.addEventListener("abort", handleAbort);
|
|
2639
|
+
try {
|
|
2640
|
+
const cacheEntry = cache.get(cacheKey);
|
|
2641
|
+
if (!cacheEntry) {
|
|
2642
|
+
const singletonAbortController = new AbortController();
|
|
2643
|
+
const newIterablePromise = onCreateIterable(singletonAbortController.signal, ...args);
|
|
2644
|
+
const newCacheEntry = {
|
|
2645
|
+
abortController: singletonAbortController,
|
|
2646
|
+
iterable: newIterablePromise,
|
|
2647
|
+
purgeScheduled: false,
|
|
2648
|
+
referenceCount: 1
|
|
2649
|
+
};
|
|
2650
|
+
cache.set(cacheKey, newCacheEntry);
|
|
2651
|
+
const newIterable = await newIterablePromise;
|
|
2652
|
+
registerIterableCleanup2(newIterable, cleanup);
|
|
2653
|
+
newCacheEntry.iterable = newIterable;
|
|
2654
|
+
return newIterable;
|
|
2655
|
+
} else {
|
|
2656
|
+
cacheEntry.referenceCount++;
|
|
2657
|
+
const iterableOrIterablePromise = cacheEntry.iterable;
|
|
2658
|
+
const cachedIterable = "then" in iterableOrIterablePromise ? await iterableOrIterablePromise : iterableOrIterablePromise;
|
|
2659
|
+
await onCacheHit(cachedIterable, ...args);
|
|
2660
|
+
return cachedIterable;
|
|
2661
|
+
}
|
|
2662
|
+
} catch (e3) {
|
|
2663
|
+
cleanup();
|
|
2664
|
+
throw e3;
|
|
2665
|
+
}
|
|
2666
|
+
};
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2669
|
+
// src/rpc-subscription-coalescer.ts
|
|
2670
|
+
var EXPLICIT_ABORT_TOKEN2 = Symbol(
|
|
2671
|
+
"This symbol is thrown from a subscription's iterator when the subscription is explicitly aborted by the user"
|
|
2672
|
+
);
|
|
2673
|
+
function registerIterableCleanup3(iterable, cleanupFn) {
|
|
2674
|
+
(async () => {
|
|
2675
|
+
try {
|
|
2676
|
+
for await (const _ of iterable)
|
|
2677
|
+
;
|
|
2678
|
+
} catch {
|
|
2679
|
+
} finally {
|
|
2680
|
+
cleanupFn();
|
|
2681
|
+
}
|
|
2682
|
+
})();
|
|
2683
|
+
}
|
|
2684
|
+
function getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
2685
|
+
getDeduplicationKey,
|
|
2686
|
+
rpcSubscriptions
|
|
2687
|
+
}) {
|
|
2688
|
+
const cache = /* @__PURE__ */ new Map();
|
|
2689
|
+
return new Proxy(rpcSubscriptions, {
|
|
2690
|
+
defineProperty() {
|
|
2691
|
+
return false;
|
|
2692
|
+
},
|
|
2693
|
+
deleteProperty() {
|
|
2694
|
+
return false;
|
|
2695
|
+
},
|
|
2696
|
+
get(target, p, receiver) {
|
|
2697
|
+
const subscriptionMethod = Reflect.get(target, p, receiver);
|
|
2698
|
+
if (typeof subscriptionMethod !== "function") {
|
|
2699
|
+
return subscriptionMethod;
|
|
2700
|
+
}
|
|
2701
|
+
return function(...rawParams) {
|
|
2702
|
+
const deduplicationKey = getDeduplicationKey(p, rawParams);
|
|
2703
|
+
if (deduplicationKey === void 0) {
|
|
2704
|
+
return subscriptionMethod(...rawParams);
|
|
2705
|
+
}
|
|
2706
|
+
if (cache.has(deduplicationKey)) {
|
|
2707
|
+
return cache.get(deduplicationKey);
|
|
2708
|
+
}
|
|
2709
|
+
const iterableFactory = getCachedAbortableIterableFactory({
|
|
2710
|
+
getAbortSignalFromInputArgs: ({ abortSignal }) => abortSignal,
|
|
2711
|
+
getCacheEntryMissingError(deduplicationKey2) {
|
|
2712
|
+
return new Error(
|
|
2713
|
+
`Found no cache entry for subscription with deduplication key \`${deduplicationKey2?.toString()}\``
|
|
2714
|
+
);
|
|
2715
|
+
},
|
|
2716
|
+
getCacheKeyFromInputArgs: () => deduplicationKey,
|
|
2717
|
+
async onCacheHit(_iterable, _config) {
|
|
2718
|
+
},
|
|
2719
|
+
async onCreateIterable(abortSignal, config) {
|
|
2720
|
+
const pendingSubscription2 = subscriptionMethod(
|
|
2721
|
+
...rawParams
|
|
2722
|
+
);
|
|
2723
|
+
const iterable = await pendingSubscription2.subscribe({
|
|
2724
|
+
...config,
|
|
2725
|
+
abortSignal
|
|
2726
|
+
});
|
|
2727
|
+
registerIterableCleanup3(iterable, () => {
|
|
2728
|
+
cache.delete(deduplicationKey);
|
|
2729
|
+
});
|
|
2730
|
+
return iterable;
|
|
2731
|
+
}
|
|
2732
|
+
});
|
|
2733
|
+
const pendingSubscription = {
|
|
2734
|
+
async subscribe(...args) {
|
|
2735
|
+
const iterable = await iterableFactory(...args);
|
|
2736
|
+
const { abortSignal } = args[0];
|
|
2737
|
+
let abortPromise;
|
|
2738
|
+
return {
|
|
2739
|
+
...iterable,
|
|
2740
|
+
async *[Symbol.asyncIterator]() {
|
|
2741
|
+
abortPromise || (abortPromise = abortSignal.aborted ? Promise.reject(EXPLICIT_ABORT_TOKEN2) : new Promise((_, reject) => {
|
|
2742
|
+
abortSignal.addEventListener("abort", () => {
|
|
2743
|
+
reject(EXPLICIT_ABORT_TOKEN2);
|
|
2744
|
+
});
|
|
2745
|
+
}));
|
|
2746
|
+
try {
|
|
2747
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
2748
|
+
while (true) {
|
|
2749
|
+
const iteratorResult = await Promise.race([iterator.next(), abortPromise]);
|
|
2750
|
+
if (iteratorResult.done) {
|
|
2751
|
+
return;
|
|
2752
|
+
} else {
|
|
2753
|
+
yield iteratorResult.value;
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
} catch (e3) {
|
|
2757
|
+
if (e3 === EXPLICIT_ABORT_TOKEN2) {
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2760
|
+
cache.delete(deduplicationKey);
|
|
2761
|
+
throw e3;
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
};
|
|
2765
|
+
}
|
|
2766
|
+
};
|
|
2767
|
+
cache.set(deduplicationKey, pendingSubscription);
|
|
2768
|
+
return pendingSubscription;
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2773
|
+
|
|
2164
2774
|
// src/rpc.ts
|
|
2165
2775
|
function createSolanaRpc(config) {
|
|
2166
2776
|
return createJsonRpc({
|
|
@@ -2168,6 +2778,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2168
2778
|
api: createSolanaRpcApi(DEFAULT_RPC_CONFIG)
|
|
2169
2779
|
});
|
|
2170
2780
|
}
|
|
2781
|
+
function createSolanaRpcSubscriptions(config) {
|
|
2782
|
+
return pipe(
|
|
2783
|
+
createJsonSubscriptionRpc({
|
|
2784
|
+
...config,
|
|
2785
|
+
api: createSolanaRpcSubscriptionsApi(DEFAULT_RPC_CONFIG)
|
|
2786
|
+
}),
|
|
2787
|
+
(rpcSubscriptions) => getRpcSubscriptionsWithSubscriptionCoalescing({
|
|
2788
|
+
getDeduplicationKey: (...args) => (0, import_fast_stable_stringify.default)(args),
|
|
2789
|
+
rpcSubscriptions
|
|
2790
|
+
})
|
|
2791
|
+
);
|
|
2792
|
+
}
|
|
2171
2793
|
|
|
2172
2794
|
// src/rpc-transport.ts
|
|
2173
2795
|
init_env_shim();
|
|
@@ -2227,14 +2849,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2227
2849
|
|
|
2228
2850
|
// src/rpc-request-deduplication.ts
|
|
2229
2851
|
init_env_shim();
|
|
2230
|
-
var
|
|
2231
|
-
function
|
|
2852
|
+
var import_fast_stable_stringify2 = __toESM(require_fast_stable_stringify(), 1);
|
|
2853
|
+
function isJsonRpcPayload(payload) {
|
|
2232
2854
|
if (payload == null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
2233
|
-
return;
|
|
2234
|
-
}
|
|
2235
|
-
if ("jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && "params" in payload) {
|
|
2236
|
-
return (0, import_fast_stable_stringify.default)([payload.method, payload.params]);
|
|
2855
|
+
return false;
|
|
2237
2856
|
}
|
|
2857
|
+
return "jsonrpc" in payload && payload.jsonrpc === "2.0" && "method" in payload && typeof payload.method === "string" && "params" in payload;
|
|
2858
|
+
}
|
|
2859
|
+
function getSolanaRpcPayloadDeduplicationKey(payload) {
|
|
2860
|
+
return isJsonRpcPayload(payload) ? (0, import_fast_stable_stringify2.default)([payload.method, payload.params]) : void 0;
|
|
2238
2861
|
}
|
|
2239
2862
|
|
|
2240
2863
|
// src/rpc-transport.ts
|
|
@@ -2246,7 +2869,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2246
2869
|
return out;
|
|
2247
2870
|
}
|
|
2248
2871
|
function createDefaultRpcTransport(config) {
|
|
2249
|
-
return
|
|
2872
|
+
return pipe(
|
|
2250
2873
|
createHttpTransport({
|
|
2251
2874
|
...config,
|
|
2252
2875
|
headers: {
|
|
@@ -2257,18 +2880,128 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2257
2880
|
}
|
|
2258
2881
|
}
|
|
2259
2882
|
}),
|
|
2260
|
-
getSolanaRpcPayloadDeduplicationKey
|
|
2883
|
+
(transport) => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
|
|
2884
|
+
);
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
// src/rpc-websocket-transport.ts
|
|
2888
|
+
init_env_shim();
|
|
2889
|
+
|
|
2890
|
+
// src/rpc-websocket-autopinger.ts
|
|
2891
|
+
init_env_shim();
|
|
2892
|
+
var PING_PAYLOAD = {
|
|
2893
|
+
jsonrpc: "2.0",
|
|
2894
|
+
method: "ping"
|
|
2895
|
+
};
|
|
2896
|
+
function getWebSocketTransportWithAutoping({ intervalMs, transport }) {
|
|
2897
|
+
const pingableConnections = /* @__PURE__ */ new Map();
|
|
2898
|
+
return async (...args) => {
|
|
2899
|
+
const connection = await transport(...args);
|
|
2900
|
+
let intervalId;
|
|
2901
|
+
function sendPing() {
|
|
2902
|
+
connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(PING_PAYLOAD);
|
|
2903
|
+
}
|
|
2904
|
+
function restartPingTimer() {
|
|
2905
|
+
clearInterval(intervalId);
|
|
2906
|
+
intervalId = setInterval(sendPing, intervalMs);
|
|
2907
|
+
}
|
|
2908
|
+
if (pingableConnections.has(connection) === false) {
|
|
2909
|
+
pingableConnections.set(connection, {
|
|
2910
|
+
[Symbol.asyncIterator]: connection[Symbol.asyncIterator].bind(connection),
|
|
2911
|
+
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: (...args2) => {
|
|
2912
|
+
restartPingTimer();
|
|
2913
|
+
return connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(...args2);
|
|
2914
|
+
}
|
|
2915
|
+
});
|
|
2916
|
+
(async () => {
|
|
2917
|
+
try {
|
|
2918
|
+
for await (const _ of connection) {
|
|
2919
|
+
restartPingTimer();
|
|
2920
|
+
}
|
|
2921
|
+
} catch {
|
|
2922
|
+
} finally {
|
|
2923
|
+
pingableConnections.delete(connection);
|
|
2924
|
+
clearInterval(intervalId);
|
|
2925
|
+
if (handleOffline) {
|
|
2926
|
+
globalThis.window.removeEventListener("offline", handleOffline);
|
|
2927
|
+
}
|
|
2928
|
+
if (handleOnline) {
|
|
2929
|
+
globalThis.window.removeEventListener("online", handleOnline);
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
})();
|
|
2933
|
+
if (globalThis.navigator.onLine) {
|
|
2934
|
+
restartPingTimer();
|
|
2935
|
+
}
|
|
2936
|
+
let handleOffline;
|
|
2937
|
+
let handleOnline;
|
|
2938
|
+
{
|
|
2939
|
+
handleOffline = () => {
|
|
2940
|
+
clearInterval(intervalId);
|
|
2941
|
+
};
|
|
2942
|
+
handleOnline = () => {
|
|
2943
|
+
sendPing();
|
|
2944
|
+
restartPingTimer();
|
|
2945
|
+
};
|
|
2946
|
+
globalThis.window.addEventListener("offline", handleOffline);
|
|
2947
|
+
globalThis.window.addEventListener("online", handleOnline);
|
|
2948
|
+
}
|
|
2949
|
+
}
|
|
2950
|
+
return pingableConnections.get(connection);
|
|
2951
|
+
};
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
// src/rpc-websocket-connection-sharding.ts
|
|
2955
|
+
init_env_shim();
|
|
2956
|
+
var NULL_SHARD_CACHE_KEY = Symbol(
|
|
2957
|
+
"Cache key to use when there is no connection sharding strategy"
|
|
2958
|
+
);
|
|
2959
|
+
function getWebSocketTransportWithConnectionSharding({ getShard, transport }) {
|
|
2960
|
+
return getCachedAbortableIterableFactory({
|
|
2961
|
+
getAbortSignalFromInputArgs: ({ signal }) => signal,
|
|
2962
|
+
getCacheEntryMissingError(shardKey) {
|
|
2963
|
+
return new Error(`Found no cache entry for connection with shard key \`${shardKey?.toString()}\``);
|
|
2964
|
+
},
|
|
2965
|
+
getCacheKeyFromInputArgs: ({ payload }) => getShard ? getShard(payload) : NULL_SHARD_CACHE_KEY,
|
|
2966
|
+
onCacheHit: (connection, { payload }) => connection.send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED(payload),
|
|
2967
|
+
onCreateIterable: (abortSignal, config) => transport({
|
|
2968
|
+
...config,
|
|
2969
|
+
signal: abortSignal
|
|
2970
|
+
})
|
|
2971
|
+
});
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
// src/rpc-websocket-transport.ts
|
|
2975
|
+
function createDefaultRpcSubscriptionsTransport(config) {
|
|
2976
|
+
const { getShard, intervalMs, ...rest } = config;
|
|
2977
|
+
return pipe(
|
|
2978
|
+
createWebSocketTransport({
|
|
2979
|
+
...rest,
|
|
2980
|
+
sendBufferHighWatermark: config.sendBufferHighWatermark ?? // Let 128KB of data into the WebSocket buffer before buffering it in the app.
|
|
2981
|
+
131072
|
|
2982
|
+
}),
|
|
2983
|
+
(transport) => getWebSocketTransportWithAutoping({
|
|
2984
|
+
intervalMs: intervalMs ?? 5e3,
|
|
2985
|
+
transport
|
|
2986
|
+
}),
|
|
2987
|
+
(transport) => getWebSocketTransportWithConnectionSharding({
|
|
2988
|
+
getShard,
|
|
2989
|
+
transport
|
|
2990
|
+
})
|
|
2261
2991
|
);
|
|
2262
2992
|
}
|
|
2263
2993
|
|
|
2264
2994
|
exports.AccountRole = AccountRole;
|
|
2995
|
+
exports.address = address;
|
|
2265
2996
|
exports.appendTransactionInstruction = appendTransactionInstruction;
|
|
2266
2997
|
exports.assertIsBase58EncodedAddress = assertIsBase58EncodedAddress;
|
|
2267
2998
|
exports.assertIsBlockhash = assertIsBlockhash;
|
|
2268
2999
|
exports.assertIsDurableNonceTransaction = assertIsDurableNonceTransaction;
|
|
2269
3000
|
exports.createAddressWithSeed = createAddressWithSeed;
|
|
3001
|
+
exports.createDefaultRpcSubscriptionsTransport = createDefaultRpcSubscriptionsTransport;
|
|
2270
3002
|
exports.createDefaultRpcTransport = createDefaultRpcTransport;
|
|
2271
3003
|
exports.createSolanaRpc = createSolanaRpc;
|
|
3004
|
+
exports.createSolanaRpcSubscriptions = createSolanaRpcSubscriptions;
|
|
2272
3005
|
exports.createTransaction = createTransaction;
|
|
2273
3006
|
exports.downgradeRoleToNonSigner = downgradeRoleToNonSigner;
|
|
2274
3007
|
exports.downgradeRoleToReadonly = downgradeRoleToReadonly;
|
|
@@ -2278,6 +3011,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
|
|
|
2278
3011
|
exports.getBase58EncodedAddressComparator = getBase58EncodedAddressComparator;
|
|
2279
3012
|
exports.getBase64EncodedWireTransaction = getBase64EncodedWireTransaction;
|
|
2280
3013
|
exports.getProgramDerivedAddress = getProgramDerivedAddress;
|
|
3014
|
+
exports.isBase58EncodedAddress = isBase58EncodedAddress;
|
|
2281
3015
|
exports.isSignerRole = isSignerRole;
|
|
2282
3016
|
exports.isWritableRole = isWritableRole;
|
|
2283
3017
|
exports.mergeRoles = mergeRoles;
|