@solana/web3.js 1.41.0 → 1.41.3
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 +516 -387
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +516 -388
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +516 -387
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +47 -30
- package/lib/index.esm.js +516 -388
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +548 -628
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -24
- package/lib/index.iife.min.js.map +1 -1
- package/package.json +11 -8
- package/src/connection.ts +657 -486
- package/src/index.ts +1 -0
- package/src/loader.ts +2 -1
- package/src/message.ts +1 -1
- package/src/transaction-constants.ts +10 -0
- package/src/transaction.ts +7 -16
package/lib/index.browser.esm.js
CHANGED
|
@@ -2076,6 +2076,16 @@ class Account {
|
|
|
2076
2076
|
|
|
2077
2077
|
const BPF_LOADER_DEPRECATED_PROGRAM_ID = new PublicKey('BPFLoader1111111111111111111111111111111111');
|
|
2078
2078
|
|
|
2079
|
+
/**
|
|
2080
|
+
* Maximum over-the-wire size of a Transaction
|
|
2081
|
+
*
|
|
2082
|
+
* 1280 is IPv6 minimum MTU
|
|
2083
|
+
* 40 bytes is the size of the IPv6 header
|
|
2084
|
+
* 8 bytes is the size of the fragment header
|
|
2085
|
+
*/
|
|
2086
|
+
const PACKET_DATA_SIZE = 1280 - 40 - 8;
|
|
2087
|
+
const SIGNATURE_LENGTH_IN_BYTES = 64;
|
|
2088
|
+
|
|
2079
2089
|
/**
|
|
2080
2090
|
* Layout for a public key
|
|
2081
2091
|
*/
|
|
@@ -2335,20 +2345,8 @@ function assert (condition, message) {
|
|
|
2335
2345
|
|
|
2336
2346
|
/**
|
|
2337
2347
|
* Default (empty) signature
|
|
2338
|
-
*
|
|
2339
|
-
* Signatures are 64 bytes in length
|
|
2340
2348
|
*/
|
|
2341
|
-
const DEFAULT_SIGNATURE = Buffer.alloc(
|
|
2342
|
-
/**
|
|
2343
|
-
* Maximum over-the-wire size of a Transaction
|
|
2344
|
-
*
|
|
2345
|
-
* 1280 is IPv6 minimum MTU
|
|
2346
|
-
* 40 bytes is the size of the IPv6 header
|
|
2347
|
-
* 8 bytes is the size of the fragment header
|
|
2348
|
-
*/
|
|
2349
|
-
|
|
2350
|
-
const PACKET_DATA_SIZE = 1280 - 40 - 8;
|
|
2351
|
-
const SIGNATURE_LENGTH = 64;
|
|
2349
|
+
const DEFAULT_SIGNATURE = Buffer.alloc(SIGNATURE_LENGTH_IN_BYTES).fill(0);
|
|
2352
2350
|
/**
|
|
2353
2351
|
* Account metadata used to define instructions
|
|
2354
2352
|
*/
|
|
@@ -2978,8 +2976,8 @@ class Transaction {
|
|
|
2978
2976
|
let signatures = [];
|
|
2979
2977
|
|
|
2980
2978
|
for (let i = 0; i < signatureCount; i++) {
|
|
2981
|
-
const signature = byteArray.slice(0,
|
|
2982
|
-
byteArray = byteArray.slice(
|
|
2979
|
+
const signature = byteArray.slice(0, SIGNATURE_LENGTH_IN_BYTES);
|
|
2980
|
+
byteArray = byteArray.slice(SIGNATURE_LENGTH_IN_BYTES);
|
|
2983
2981
|
signatures.push(bs58.encode(Buffer.from(signature)));
|
|
2984
2982
|
}
|
|
2985
2983
|
|
|
@@ -3868,11 +3866,11 @@ class SystemProgram {
|
|
|
3868
3866
|
}
|
|
3869
3867
|
SystemProgram.programId = new PublicKey('11111111111111111111111111111111');
|
|
3870
3868
|
|
|
3871
|
-
// Keep program chunks under PACKET_DATA_SIZE, leaving enough room for the
|
|
3872
3869
|
// rest of the Transaction fields
|
|
3873
3870
|
//
|
|
3874
3871
|
// TODO: replace 300 with a proper constant for the size of the other
|
|
3875
3872
|
// Transaction fields
|
|
3873
|
+
|
|
3876
3874
|
const CHUNK_SIZE = PACKET_DATA_SIZE - 300;
|
|
3877
3875
|
/**
|
|
3878
3876
|
* Program loader interface
|
|
@@ -4763,6 +4761,82 @@ module.exports = exports;
|
|
|
4763
4761
|
|
|
4764
4762
|
var crossFetch = /*@__PURE__*/getDefaultExportFromCjs(browserPonyfill.exports);
|
|
4765
4763
|
|
|
4764
|
+
var objToString = Object.prototype.toString;
|
|
4765
|
+
var objKeys = Object.keys || function(obj) {
|
|
4766
|
+
var keys = [];
|
|
4767
|
+
for (var name in obj) {
|
|
4768
|
+
keys.push(name);
|
|
4769
|
+
}
|
|
4770
|
+
return keys;
|
|
4771
|
+
};
|
|
4772
|
+
|
|
4773
|
+
function stringify(val, isArrayProp) {
|
|
4774
|
+
var i, max, str, keys, key, propVal, toStr;
|
|
4775
|
+
if (val === true) {
|
|
4776
|
+
return "true";
|
|
4777
|
+
}
|
|
4778
|
+
if (val === false) {
|
|
4779
|
+
return "false";
|
|
4780
|
+
}
|
|
4781
|
+
switch (typeof val) {
|
|
4782
|
+
case "object":
|
|
4783
|
+
if (val === null) {
|
|
4784
|
+
return null;
|
|
4785
|
+
} else if (val.toJSON && typeof val.toJSON === "function") {
|
|
4786
|
+
return stringify(val.toJSON(), isArrayProp);
|
|
4787
|
+
} else {
|
|
4788
|
+
toStr = objToString.call(val);
|
|
4789
|
+
if (toStr === "[object Array]") {
|
|
4790
|
+
str = '[';
|
|
4791
|
+
max = val.length - 1;
|
|
4792
|
+
for(i = 0; i < max; i++) {
|
|
4793
|
+
str += stringify(val[i], true) + ',';
|
|
4794
|
+
}
|
|
4795
|
+
if (max > -1) {
|
|
4796
|
+
str += stringify(val[i], true);
|
|
4797
|
+
}
|
|
4798
|
+
return str + ']';
|
|
4799
|
+
} else if (toStr === "[object Object]") {
|
|
4800
|
+
// only object is left
|
|
4801
|
+
keys = objKeys(val).sort();
|
|
4802
|
+
max = keys.length;
|
|
4803
|
+
str = "";
|
|
4804
|
+
i = 0;
|
|
4805
|
+
while (i < max) {
|
|
4806
|
+
key = keys[i];
|
|
4807
|
+
propVal = stringify(val[key], false);
|
|
4808
|
+
if (propVal !== undefined) {
|
|
4809
|
+
if (str) {
|
|
4810
|
+
str += ',';
|
|
4811
|
+
}
|
|
4812
|
+
str += JSON.stringify(key) + ':' + propVal;
|
|
4813
|
+
}
|
|
4814
|
+
i++;
|
|
4815
|
+
}
|
|
4816
|
+
return '{' + str + '}';
|
|
4817
|
+
} else {
|
|
4818
|
+
return JSON.stringify(val);
|
|
4819
|
+
}
|
|
4820
|
+
}
|
|
4821
|
+
case "function":
|
|
4822
|
+
case "undefined":
|
|
4823
|
+
return isArrayProp ? null : undefined;
|
|
4824
|
+
case "string":
|
|
4825
|
+
return JSON.stringify(val);
|
|
4826
|
+
default:
|
|
4827
|
+
return isFinite(val) ? val : null;
|
|
4828
|
+
}
|
|
4829
|
+
}
|
|
4830
|
+
|
|
4831
|
+
var fastStableStringify = function(val) {
|
|
4832
|
+
var returnVal = stringify(val, false);
|
|
4833
|
+
if (returnVal !== undefined) {
|
|
4834
|
+
return ''+ returnVal;
|
|
4835
|
+
}
|
|
4836
|
+
};
|
|
4837
|
+
|
|
4838
|
+
var fastStableStringify$1 = fastStableStringify;
|
|
4839
|
+
|
|
4766
4840
|
const MINIMUM_SLOT_PER_EPOCH = 32; // Returns the number of trailing zeros in the binary representation of self.
|
|
4767
4841
|
|
|
4768
4842
|
function trailingZeros(n) {
|
|
@@ -4929,6 +5003,12 @@ const BufferFromRawAccountData = coerce(instance(Buffer), RawAccountDataResult,
|
|
|
4929
5003
|
*/
|
|
4930
5004
|
|
|
4931
5005
|
const BLOCKHASH_CACHE_TIMEOUT_MS = 30 * 1000;
|
|
5006
|
+
/**
|
|
5007
|
+
* HACK.
|
|
5008
|
+
* Copied from rpc-websockets/dist/lib/client.
|
|
5009
|
+
* Otherwise, `yarn build` fails with:
|
|
5010
|
+
* https://gist.github.com/steveluscher/c057eca81d479ef705cdb53162f9971d
|
|
5011
|
+
*/
|
|
4932
5012
|
|
|
4933
5013
|
/**
|
|
4934
5014
|
* @internal
|
|
@@ -5797,14 +5877,9 @@ const LogsNotificationResult = type({
|
|
|
5797
5877
|
* Filter for log subscriptions.
|
|
5798
5878
|
*/
|
|
5799
5879
|
|
|
5800
|
-
function createSubscriptionWarningMessage(id, label) {
|
|
5801
|
-
return 'Ignored unsubscribe request because an active subscription ' + `with id \`${id}\` for '${label}' events could not be found.`;
|
|
5802
|
-
}
|
|
5803
5880
|
/**
|
|
5804
5881
|
* A connection to a fullnode JSON RPC endpoint
|
|
5805
5882
|
*/
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
5883
|
class Connection {
|
|
5809
5884
|
/** @internal */
|
|
5810
5885
|
|
|
@@ -5828,21 +5903,13 @@ class Connection {
|
|
|
5828
5903
|
|
|
5829
5904
|
/** @internal */
|
|
5830
5905
|
|
|
5831
|
-
/** @internal
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
|
|
5837
|
-
|
|
5838
|
-
|
|
5839
|
-
/** @internal */
|
|
5840
|
-
|
|
5841
|
-
/** @internal */
|
|
5842
|
-
|
|
5843
|
-
/** @internal */
|
|
5844
|
-
|
|
5845
|
-
/** @internal */
|
|
5906
|
+
/** @internal
|
|
5907
|
+
* A number that we increment every time an active connection closes.
|
|
5908
|
+
* Used to determine whether the same socket connection that was open
|
|
5909
|
+
* when an async operation started is the same one that's active when
|
|
5910
|
+
* its continuation fires.
|
|
5911
|
+
*
|
|
5912
|
+
*/
|
|
5846
5913
|
|
|
5847
5914
|
/** @internal */
|
|
5848
5915
|
|
|
@@ -5858,7 +5925,19 @@ class Connection {
|
|
|
5858
5925
|
|
|
5859
5926
|
/** @internal */
|
|
5860
5927
|
|
|
5861
|
-
/**
|
|
5928
|
+
/**
|
|
5929
|
+
* Special case.
|
|
5930
|
+
* After a signature is processed, RPCs automatically dispose of the
|
|
5931
|
+
* subscription on the server side. We need to track which of these
|
|
5932
|
+
* subscriptions have been disposed in such a way, so that we know
|
|
5933
|
+
* whether the client is dealing with a not-yet-processed signature
|
|
5934
|
+
* (in which case we must tear down the server subscription) or an
|
|
5935
|
+
* already-processed signature (in which case the client can simply
|
|
5936
|
+
* clear out the subscription locally without telling the server).
|
|
5937
|
+
*
|
|
5938
|
+
* NOTE: There is a proposal to eliminate this special case, here:
|
|
5939
|
+
* https://github.com/solana-labs/solana/issues/18892
|
|
5940
|
+
*/
|
|
5862
5941
|
|
|
5863
5942
|
/** @internal */
|
|
5864
5943
|
|
|
@@ -5880,6 +5959,7 @@ class Connection {
|
|
|
5880
5959
|
this._rpcWebSocketConnected = false;
|
|
5881
5960
|
this._rpcWebSocketHeartbeat = null;
|
|
5882
5961
|
this._rpcWebSocketIdleTimeout = null;
|
|
5962
|
+
this._rpcWebSocketGeneration = 0;
|
|
5883
5963
|
this._disableBlockhashCaching = false;
|
|
5884
5964
|
this._pollingBlockhash = false;
|
|
5885
5965
|
this._blockhashInfo = {
|
|
@@ -5888,20 +5968,11 @@ class Connection {
|
|
|
5888
5968
|
transactionSignatures: [],
|
|
5889
5969
|
simulatedSignatures: []
|
|
5890
5970
|
};
|
|
5891
|
-
this.
|
|
5892
|
-
this.
|
|
5893
|
-
this.
|
|
5894
|
-
this.
|
|
5895
|
-
this.
|
|
5896
|
-
this._rootSubscriptions = {};
|
|
5897
|
-
this._signatureSubscriptionCounter = 0;
|
|
5898
|
-
this._signatureSubscriptions = {};
|
|
5899
|
-
this._slotSubscriptionCounter = 0;
|
|
5900
|
-
this._slotSubscriptions = {};
|
|
5901
|
-
this._logsSubscriptionCounter = 0;
|
|
5902
|
-
this._logsSubscriptions = {};
|
|
5903
|
-
this._slotUpdateSubscriptionCounter = 0;
|
|
5904
|
-
this._slotUpdateSubscriptions = {};
|
|
5971
|
+
this._nextClientSubscriptionId = 0;
|
|
5972
|
+
this._subscriptionDisposeFunctionsByClientSubscriptionId = {};
|
|
5973
|
+
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
5974
|
+
this._subscriptionsByHash = {};
|
|
5975
|
+
this._subscriptionsAutoDisposedByRpc = new Set();
|
|
5905
5976
|
let url = new URL(endpoint);
|
|
5906
5977
|
const useHttps = url.protocol === 'https:';
|
|
5907
5978
|
let wsEndpoint;
|
|
@@ -7669,6 +7740,8 @@ class Connection {
|
|
|
7669
7740
|
|
|
7670
7741
|
|
|
7671
7742
|
_wsOnClose(code) {
|
|
7743
|
+
this._rpcWebSocketGeneration++;
|
|
7744
|
+
|
|
7672
7745
|
if (this._rpcWebSocketHeartbeat) {
|
|
7673
7746
|
clearInterval(this._rpcWebSocketHeartbeat);
|
|
7674
7747
|
this._rpcWebSocketHeartbeat = null;
|
|
@@ -7682,85 +7755,20 @@ class Connection {
|
|
|
7682
7755
|
} // implicit close, prepare subscriptions for auto-reconnect
|
|
7683
7756
|
|
|
7684
7757
|
|
|
7685
|
-
this.
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
7690
|
-
|
|
7691
|
-
|
|
7692
|
-
async _subscribe(sub, rpcMethod, rpcArgs) {
|
|
7693
|
-
if (sub.subscriptionId == null) {
|
|
7694
|
-
sub.subscriptionId = 'subscribing';
|
|
7695
|
-
|
|
7696
|
-
try {
|
|
7697
|
-
const id = await this._rpcWebSocket.call(rpcMethod, rpcArgs);
|
|
7698
|
-
|
|
7699
|
-
if (typeof id === 'number' && sub.subscriptionId === 'subscribing') {
|
|
7700
|
-
// eslint-disable-next-line require-atomic-updates
|
|
7701
|
-
sub.subscriptionId = id;
|
|
7702
|
-
}
|
|
7703
|
-
} catch (err) {
|
|
7704
|
-
if (sub.subscriptionId === 'subscribing') {
|
|
7705
|
-
// eslint-disable-next-line require-atomic-updates
|
|
7706
|
-
sub.subscriptionId = null;
|
|
7707
|
-
}
|
|
7708
|
-
|
|
7709
|
-
if (err instanceof Error) {
|
|
7710
|
-
console.error(`${rpcMethod} error for argument`, rpcArgs, err.message);
|
|
7711
|
-
}
|
|
7712
|
-
}
|
|
7713
|
-
}
|
|
7714
|
-
}
|
|
7715
|
-
/**
|
|
7716
|
-
* @internal
|
|
7717
|
-
*/
|
|
7718
|
-
|
|
7719
|
-
|
|
7720
|
-
async _unsubscribe(sub, rpcMethod) {
|
|
7721
|
-
const subscriptionId = sub.subscriptionId;
|
|
7722
|
-
|
|
7723
|
-
if (subscriptionId != null && typeof subscriptionId != 'string') {
|
|
7724
|
-
const unsubscribeId = subscriptionId;
|
|
7725
|
-
|
|
7726
|
-
try {
|
|
7727
|
-
await this._rpcWebSocket.call(rpcMethod, [unsubscribeId]);
|
|
7728
|
-
} catch (err) {
|
|
7729
|
-
if (err instanceof Error) {
|
|
7730
|
-
console.error(`${rpcMethod} error:`, err.message);
|
|
7731
|
-
}
|
|
7732
|
-
}
|
|
7733
|
-
}
|
|
7734
|
-
}
|
|
7735
|
-
/**
|
|
7736
|
-
* @internal
|
|
7737
|
-
*/
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
_resetSubscriptions() {
|
|
7741
|
-
Object.values(this._accountChangeSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7742
|
-
Object.values(this._logsSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7743
|
-
Object.values(this._programAccountChangeSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7744
|
-
Object.values(this._rootSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7745
|
-
Object.values(this._signatureSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7746
|
-
Object.values(this._slotSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7747
|
-
Object.values(this._slotUpdateSubscriptions).forEach(s => s.subscriptionId = null);
|
|
7758
|
+
this._subscriptionCallbacksByServerSubscriptionId = {};
|
|
7759
|
+
Object.entries(this._subscriptionsByHash).forEach(([hash, subscription]) => {
|
|
7760
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7761
|
+
state: 'pending'
|
|
7762
|
+
};
|
|
7763
|
+
});
|
|
7748
7764
|
}
|
|
7749
7765
|
/**
|
|
7750
7766
|
* @internal
|
|
7751
7767
|
*/
|
|
7752
7768
|
|
|
7753
7769
|
|
|
7754
|
-
_updateSubscriptions() {
|
|
7755
|
-
|
|
7756
|
-
const programKeys = Object.keys(this._programAccountChangeSubscriptions).map(Number);
|
|
7757
|
-
const slotKeys = Object.keys(this._slotSubscriptions).map(Number);
|
|
7758
|
-
const slotUpdateKeys = Object.keys(this._slotUpdateSubscriptions).map(Number);
|
|
7759
|
-
const signatureKeys = Object.keys(this._signatureSubscriptions).map(Number);
|
|
7760
|
-
const rootKeys = Object.keys(this._rootSubscriptions).map(Number);
|
|
7761
|
-
const logsKeys = Object.keys(this._logsSubscriptions).map(Number);
|
|
7762
|
-
|
|
7763
|
-
if (accountKeys.length === 0 && programKeys.length === 0 && slotKeys.length === 0 && slotUpdateKeys.length === 0 && signatureKeys.length === 0 && rootKeys.length === 0 && logsKeys.length === 0) {
|
|
7770
|
+
async _updateSubscriptions() {
|
|
7771
|
+
if (Object.keys(this._subscriptionsByHash).length === 0) {
|
|
7764
7772
|
if (this._rpcWebSocketConnected) {
|
|
7765
7773
|
this._rpcWebSocketConnected = false;
|
|
7766
7774
|
this._rpcWebSocketIdleTimeout = setTimeout(() => {
|
|
@@ -7792,60 +7800,167 @@ class Connection {
|
|
|
7792
7800
|
return;
|
|
7793
7801
|
}
|
|
7794
7802
|
|
|
7795
|
-
|
|
7796
|
-
const sub = this._accountChangeSubscriptions[id];
|
|
7803
|
+
const activeWebSocketGeneration = this._rpcWebSocketGeneration;
|
|
7797
7804
|
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
for (let id of programKeys) {
|
|
7802
|
-
const sub = this._programAccountChangeSubscriptions[id];
|
|
7805
|
+
const isCurrentConnectionStillActive = () => {
|
|
7806
|
+
return activeWebSocketGeneration === this._rpcWebSocketGeneration;
|
|
7807
|
+
};
|
|
7803
7808
|
|
|
7804
|
-
|
|
7805
|
-
|
|
7806
|
-
|
|
7807
|
-
|
|
7809
|
+
await Promise.all( // Don't be tempted to change this to `Object.entries`. We call
|
|
7810
|
+
// `_updateSubscriptions` recursively when processing the state,
|
|
7811
|
+
// so it's important that we look up the *current* version of
|
|
7812
|
+
// each subscription, every time we process a hash.
|
|
7813
|
+
Object.keys(this._subscriptionsByHash).map(async hash => {
|
|
7814
|
+
const subscription = this._subscriptionsByHash[hash];
|
|
7808
7815
|
|
|
7809
|
-
|
|
7810
|
-
|
|
7816
|
+
if (subscription === undefined) {
|
|
7817
|
+
// This entry has since been deleted. Skip.
|
|
7818
|
+
return;
|
|
7819
|
+
}
|
|
7811
7820
|
|
|
7812
|
-
|
|
7813
|
-
|
|
7821
|
+
switch (subscription.state) {
|
|
7822
|
+
case 'pending':
|
|
7823
|
+
case 'unsubscribed':
|
|
7824
|
+
if (subscription.callbacks.size === 0) {
|
|
7825
|
+
/**
|
|
7826
|
+
* You can end up here when:
|
|
7827
|
+
*
|
|
7828
|
+
* - a subscription has recently unsubscribed
|
|
7829
|
+
* without having new callbacks added to it
|
|
7830
|
+
* while the unsubscribe was in flight, or
|
|
7831
|
+
* - when a pending subscription has its
|
|
7832
|
+
* listeners removed before a request was
|
|
7833
|
+
* sent to the server.
|
|
7834
|
+
*
|
|
7835
|
+
* Being that nobody is interested in this
|
|
7836
|
+
* subscription any longer, delete it.
|
|
7837
|
+
*/
|
|
7838
|
+
delete this._subscriptionsByHash[hash];
|
|
7839
|
+
|
|
7840
|
+
if (subscription.state === 'unsubscribed') {
|
|
7841
|
+
delete this._subscriptionCallbacksByServerSubscriptionId[subscription.serverSubscriptionId];
|
|
7842
|
+
}
|
|
7814
7843
|
|
|
7815
|
-
|
|
7816
|
-
|
|
7844
|
+
await this._updateSubscriptions();
|
|
7845
|
+
return;
|
|
7846
|
+
}
|
|
7817
7847
|
|
|
7818
|
-
|
|
7819
|
-
|
|
7848
|
+
await (async () => {
|
|
7849
|
+
const {
|
|
7850
|
+
args,
|
|
7851
|
+
method
|
|
7852
|
+
} = subscription;
|
|
7820
7853
|
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
|
|
7854
|
+
try {
|
|
7855
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7856
|
+
state: 'subscribing'
|
|
7857
|
+
};
|
|
7858
|
+
const serverSubscriptionId = await this._rpcWebSocket.call(method, args);
|
|
7859
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7860
|
+
serverSubscriptionId,
|
|
7861
|
+
state: 'subscribed'
|
|
7862
|
+
};
|
|
7863
|
+
this._subscriptionCallbacksByServerSubscriptionId[serverSubscriptionId] = subscription.callbacks;
|
|
7864
|
+
await this._updateSubscriptions();
|
|
7865
|
+
} catch (e) {
|
|
7866
|
+
if (e instanceof Error) {
|
|
7867
|
+
console.error(`${method} error for argument`, args, e.message);
|
|
7868
|
+
}
|
|
7869
|
+
|
|
7870
|
+
if (!isCurrentConnectionStillActive()) {
|
|
7871
|
+
return;
|
|
7872
|
+
} // TODO: Maybe add an 'errored' state or a retry limit?
|
|
7825
7873
|
|
|
7826
|
-
this._subscribe(sub, 'signatureSubscribe', args);
|
|
7827
|
-
}
|
|
7828
7874
|
|
|
7829
|
-
|
|
7830
|
-
|
|
7875
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7876
|
+
state: 'pending'
|
|
7877
|
+
};
|
|
7878
|
+
await this._updateSubscriptions();
|
|
7879
|
+
}
|
|
7880
|
+
})();
|
|
7881
|
+
break;
|
|
7831
7882
|
|
|
7832
|
-
|
|
7833
|
-
|
|
7883
|
+
case 'subscribed':
|
|
7884
|
+
if (subscription.callbacks.size === 0) {
|
|
7885
|
+
// By the time we successfully set up a subscription
|
|
7886
|
+
// with the server, the client stopped caring about it.
|
|
7887
|
+
// Tear it down now.
|
|
7888
|
+
await (async () => {
|
|
7889
|
+
const {
|
|
7890
|
+
serverSubscriptionId,
|
|
7891
|
+
unsubscribeMethod
|
|
7892
|
+
} = subscription;
|
|
7893
|
+
|
|
7894
|
+
if (this._subscriptionsAutoDisposedByRpc.has(serverSubscriptionId)) {
|
|
7895
|
+
/**
|
|
7896
|
+
* Special case.
|
|
7897
|
+
* If we're dealing with a subscription that has been auto-
|
|
7898
|
+
* disposed by the RPC, then we can skip the RPC call to
|
|
7899
|
+
* tear down the subscription here.
|
|
7900
|
+
*
|
|
7901
|
+
* NOTE: There is a proposal to eliminate this special case, here:
|
|
7902
|
+
* https://github.com/solana-labs/solana/issues/18892
|
|
7903
|
+
*/
|
|
7904
|
+
this._subscriptionsAutoDisposedByRpc.delete(serverSubscriptionId);
|
|
7905
|
+
} else {
|
|
7906
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7907
|
+
state: 'unsubscribing'
|
|
7908
|
+
};
|
|
7909
|
+
|
|
7910
|
+
try {
|
|
7911
|
+
await this._rpcWebSocket.call(unsubscribeMethod, [serverSubscriptionId]);
|
|
7912
|
+
} catch (e) {
|
|
7913
|
+
if (e instanceof Error) {
|
|
7914
|
+
console.error(`${unsubscribeMethod} error:`, e.message);
|
|
7915
|
+
}
|
|
7916
|
+
|
|
7917
|
+
if (!isCurrentConnectionStillActive()) {
|
|
7918
|
+
return;
|
|
7919
|
+
} // TODO: Maybe add an 'errored' state or a retry limit?
|
|
7920
|
+
|
|
7921
|
+
|
|
7922
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7923
|
+
state: 'subscribed'
|
|
7924
|
+
};
|
|
7925
|
+
await this._updateSubscriptions();
|
|
7926
|
+
return;
|
|
7927
|
+
}
|
|
7928
|
+
}
|
|
7834
7929
|
|
|
7835
|
-
|
|
7836
|
-
|
|
7837
|
-
|
|
7930
|
+
this._subscriptionsByHash[hash] = { ...subscription,
|
|
7931
|
+
state: 'unsubscribed'
|
|
7932
|
+
};
|
|
7933
|
+
await this._updateSubscriptions();
|
|
7934
|
+
})();
|
|
7935
|
+
}
|
|
7838
7936
|
|
|
7839
|
-
|
|
7840
|
-
filter = {
|
|
7841
|
-
mentions: [sub.filter.toString()]
|
|
7842
|
-
};
|
|
7843
|
-
} else {
|
|
7844
|
-
filter = sub.filter;
|
|
7937
|
+
break;
|
|
7845
7938
|
}
|
|
7939
|
+
}));
|
|
7940
|
+
}
|
|
7941
|
+
/**
|
|
7942
|
+
* @internal
|
|
7943
|
+
*/
|
|
7846
7944
|
|
|
7847
|
-
|
|
7945
|
+
|
|
7946
|
+
_handleServerNotification(serverSubscriptionId, callbackArgs) {
|
|
7947
|
+
const callbacks = this._subscriptionCallbacksByServerSubscriptionId[serverSubscriptionId];
|
|
7948
|
+
|
|
7949
|
+
if (callbacks === undefined) {
|
|
7950
|
+
return;
|
|
7848
7951
|
}
|
|
7952
|
+
|
|
7953
|
+
callbacks.forEach(cb => {
|
|
7954
|
+
try {
|
|
7955
|
+
cb( // I failed to find a way to convince TypeScript that `cb` is of type
|
|
7956
|
+
// `TCallback` which is certainly compatible with `Parameters<TCallback>`.
|
|
7957
|
+
// See https://github.com/microsoft/TypeScript/issues/47615
|
|
7958
|
+
// @ts-ignore
|
|
7959
|
+
...callbackArgs);
|
|
7960
|
+
} catch (e) {
|
|
7961
|
+
console.error(e);
|
|
7962
|
+
}
|
|
7963
|
+
});
|
|
7849
7964
|
}
|
|
7850
7965
|
/**
|
|
7851
7966
|
* @internal
|
|
@@ -7853,14 +7968,71 @@ class Connection {
|
|
|
7853
7968
|
|
|
7854
7969
|
|
|
7855
7970
|
_wsOnAccountNotification(notification) {
|
|
7856
|
-
const
|
|
7971
|
+
const {
|
|
7972
|
+
result,
|
|
7973
|
+
subscription
|
|
7974
|
+
} = create(notification, AccountNotificationResult);
|
|
7857
7975
|
|
|
7858
|
-
|
|
7859
|
-
|
|
7860
|
-
|
|
7861
|
-
|
|
7862
|
-
|
|
7976
|
+
this._handleServerNotification(subscription, [result.value, result.context]);
|
|
7977
|
+
}
|
|
7978
|
+
/**
|
|
7979
|
+
* @internal
|
|
7980
|
+
*/
|
|
7981
|
+
|
|
7982
|
+
|
|
7983
|
+
_makeSubscription(subscriptionConfig,
|
|
7984
|
+
/**
|
|
7985
|
+
* When preparing `args` for a call to `_makeSubscription`, be sure
|
|
7986
|
+
* to carefully apply a default `commitment` property, if necessary.
|
|
7987
|
+
*
|
|
7988
|
+
* - If the user supplied a `commitment` use that.
|
|
7989
|
+
* - Otherwise, if the `Connection::commitment` is set, use that.
|
|
7990
|
+
* - Otherwise, set it to the RPC server default: `finalized`.
|
|
7991
|
+
*
|
|
7992
|
+
* This is extremely important to ensure that these two fundamentally
|
|
7993
|
+
* identical subscriptions produce the same identifying hash:
|
|
7994
|
+
*
|
|
7995
|
+
* - A subscription made without specifying a commitment.
|
|
7996
|
+
* - A subscription made where the commitment specified is the same
|
|
7997
|
+
* as the default applied to the subscription above.
|
|
7998
|
+
*
|
|
7999
|
+
* Example; these two subscriptions must produce the same hash:
|
|
8000
|
+
*
|
|
8001
|
+
* - An `accountSubscribe` subscription for `'PUBKEY'`
|
|
8002
|
+
* - An `accountSubscribe` subscription for `'PUBKEY'` with commitment
|
|
8003
|
+
* `'finalized'`.
|
|
8004
|
+
*
|
|
8005
|
+
* See the 'making a subscription with defaulted params omitted' test
|
|
8006
|
+
* in `connection-subscriptions.ts` for more.
|
|
8007
|
+
*/
|
|
8008
|
+
args) {
|
|
8009
|
+
const clientSubscriptionId = this._nextClientSubscriptionId++;
|
|
8010
|
+
const hash = fastStableStringify$1([subscriptionConfig.method, args], true
|
|
8011
|
+
/* isArrayProp */
|
|
8012
|
+
);
|
|
8013
|
+
const existingSubscription = this._subscriptionsByHash[hash];
|
|
8014
|
+
|
|
8015
|
+
if (existingSubscription === undefined) {
|
|
8016
|
+
this._subscriptionsByHash[hash] = { ...subscriptionConfig,
|
|
8017
|
+
args,
|
|
8018
|
+
callbacks: new Set([subscriptionConfig.callback]),
|
|
8019
|
+
state: 'pending'
|
|
8020
|
+
};
|
|
8021
|
+
} else {
|
|
8022
|
+
existingSubscription.callbacks.add(subscriptionConfig.callback);
|
|
7863
8023
|
}
|
|
8024
|
+
|
|
8025
|
+
this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId] = async () => {
|
|
8026
|
+
delete this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId];
|
|
8027
|
+
const subscription = this._subscriptionsByHash[hash];
|
|
8028
|
+
assert(subscription !== undefined, `Could not find a \`Subscription\` when tearing down client subscription #${clientSubscriptionId}`);
|
|
8029
|
+
subscription.callbacks.delete(subscriptionConfig.callback);
|
|
8030
|
+
await this._updateSubscriptions();
|
|
8031
|
+
};
|
|
8032
|
+
|
|
8033
|
+
this._updateSubscriptions();
|
|
8034
|
+
|
|
8035
|
+
return clientSubscriptionId;
|
|
7864
8036
|
}
|
|
7865
8037
|
/**
|
|
7866
8038
|
* Register a callback to be invoked whenever the specified account changes
|
|
@@ -7873,35 +8045,24 @@ class Connection {
|
|
|
7873
8045
|
|
|
7874
8046
|
|
|
7875
8047
|
onAccountChange(publicKey, callback, commitment) {
|
|
7876
|
-
const
|
|
7877
|
-
|
|
7878
|
-
publicKey: publicKey.toBase58(),
|
|
7879
|
-
callback,
|
|
7880
|
-
commitment,
|
|
7881
|
-
subscriptionId: null
|
|
7882
|
-
};
|
|
8048
|
+
const args = this._buildArgs([publicKey.toBase58()], commitment || this._commitment || 'finalized', // Apply connection/server default.
|
|
8049
|
+
'base64');
|
|
7883
8050
|
|
|
7884
|
-
this.
|
|
7885
|
-
|
|
7886
|
-
|
|
8051
|
+
return this._makeSubscription({
|
|
8052
|
+
callback,
|
|
8053
|
+
method: 'accountSubscribe',
|
|
8054
|
+
unsubscribeMethod: 'accountUnsubscribe'
|
|
8055
|
+
}, args);
|
|
7887
8056
|
}
|
|
7888
8057
|
/**
|
|
7889
8058
|
* Deregister an account notification callback
|
|
7890
8059
|
*
|
|
7891
|
-
* @param id subscription id to deregister
|
|
8060
|
+
* @param id client subscription id to deregister
|
|
7892
8061
|
*/
|
|
7893
8062
|
|
|
7894
8063
|
|
|
7895
|
-
async removeAccountChangeListener(
|
|
7896
|
-
|
|
7897
|
-
const subInfo = this._accountChangeSubscriptions[id];
|
|
7898
|
-
delete this._accountChangeSubscriptions[id];
|
|
7899
|
-
await this._unsubscribe(subInfo, 'accountUnsubscribe');
|
|
7900
|
-
|
|
7901
|
-
this._updateSubscriptions();
|
|
7902
|
-
} else {
|
|
7903
|
-
console.warn(createSubscriptionWarningMessage(id, 'account change'));
|
|
7904
|
-
}
|
|
8064
|
+
async removeAccountChangeListener(clientSubscriptionId) {
|
|
8065
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'account change');
|
|
7905
8066
|
}
|
|
7906
8067
|
/**
|
|
7907
8068
|
* @internal
|
|
@@ -7909,21 +8070,15 @@ class Connection {
|
|
|
7909
8070
|
|
|
7910
8071
|
|
|
7911
8072
|
_wsOnProgramAccountNotification(notification) {
|
|
7912
|
-
const
|
|
8073
|
+
const {
|
|
8074
|
+
result,
|
|
8075
|
+
subscription
|
|
8076
|
+
} = create(notification, ProgramAccountNotificationResult);
|
|
7913
8077
|
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
context
|
|
7919
|
-
} = res.result;
|
|
7920
|
-
sub.callback({
|
|
7921
|
-
accountId: value.pubkey,
|
|
7922
|
-
accountInfo: value.account
|
|
7923
|
-
}, context);
|
|
7924
|
-
return;
|
|
7925
|
-
}
|
|
7926
|
-
}
|
|
8078
|
+
this._handleServerNotification(subscription, [{
|
|
8079
|
+
accountId: result.value.pubkey,
|
|
8080
|
+
accountInfo: result.value.account
|
|
8081
|
+
}, result.context]);
|
|
7927
8082
|
}
|
|
7928
8083
|
/**
|
|
7929
8084
|
* Register a callback to be invoked whenever accounts owned by the
|
|
@@ -7938,36 +8093,30 @@ class Connection {
|
|
|
7938
8093
|
|
|
7939
8094
|
|
|
7940
8095
|
onProgramAccountChange(programId, callback, commitment, filters) {
|
|
7941
|
-
const
|
|
7942
|
-
|
|
7943
|
-
|
|
8096
|
+
const args = this._buildArgs([programId.toBase58()], commitment || this._commitment || 'finalized', // Apply connection/server default.
|
|
8097
|
+
'base64'
|
|
8098
|
+
/* encoding */
|
|
8099
|
+
, filters ? {
|
|
8100
|
+
filters: filters
|
|
8101
|
+
} : undefined
|
|
8102
|
+
/* extra */
|
|
8103
|
+
);
|
|
8104
|
+
|
|
8105
|
+
return this._makeSubscription({
|
|
7944
8106
|
callback,
|
|
7945
|
-
|
|
7946
|
-
|
|
7947
|
-
|
|
7948
|
-
};
|
|
7949
|
-
|
|
7950
|
-
this._updateSubscriptions();
|
|
7951
|
-
|
|
7952
|
-
return id;
|
|
8107
|
+
method: 'programSubscribe',
|
|
8108
|
+
unsubscribeMethod: 'programUnsubscribe'
|
|
8109
|
+
}, args);
|
|
7953
8110
|
}
|
|
7954
8111
|
/**
|
|
7955
8112
|
* Deregister an account notification callback
|
|
7956
8113
|
*
|
|
7957
|
-
* @param id subscription id to deregister
|
|
8114
|
+
* @param id client subscription id to deregister
|
|
7958
8115
|
*/
|
|
7959
8116
|
|
|
7960
8117
|
|
|
7961
|
-
async removeProgramAccountChangeListener(
|
|
7962
|
-
|
|
7963
|
-
const subInfo = this._programAccountChangeSubscriptions[id];
|
|
7964
|
-
delete this._programAccountChangeSubscriptions[id];
|
|
7965
|
-
await this._unsubscribe(subInfo, 'programUnsubscribe');
|
|
7966
|
-
|
|
7967
|
-
this._updateSubscriptions();
|
|
7968
|
-
} else {
|
|
7969
|
-
console.warn(createSubscriptionWarningMessage(id, 'program account change'));
|
|
7970
|
-
}
|
|
8118
|
+
async removeProgramAccountChangeListener(clientSubscriptionId) {
|
|
8119
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'program account change');
|
|
7971
8120
|
}
|
|
7972
8121
|
/**
|
|
7973
8122
|
* Registers a callback to be invoked whenever logs are emitted.
|
|
@@ -7975,35 +8124,26 @@ class Connection {
|
|
|
7975
8124
|
|
|
7976
8125
|
|
|
7977
8126
|
onLogs(filter, callback, commitment) {
|
|
7978
|
-
const
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
commitment,
|
|
7983
|
-
subscriptionId: null
|
|
7984
|
-
};
|
|
8127
|
+
const args = this._buildArgs([typeof filter === 'object' ? {
|
|
8128
|
+
mentions: [filter.toString()]
|
|
8129
|
+
} : filter], commitment || this._commitment || 'finalized' // Apply connection/server default.
|
|
8130
|
+
);
|
|
7985
8131
|
|
|
7986
|
-
this.
|
|
7987
|
-
|
|
7988
|
-
|
|
8132
|
+
return this._makeSubscription({
|
|
8133
|
+
callback,
|
|
8134
|
+
method: 'logsSubscribe',
|
|
8135
|
+
unsubscribeMethod: 'logsUnsubscribe'
|
|
8136
|
+
}, args);
|
|
7989
8137
|
}
|
|
7990
8138
|
/**
|
|
7991
8139
|
* Deregister a logs callback.
|
|
7992
8140
|
*
|
|
7993
|
-
* @param id subscription id to deregister.
|
|
8141
|
+
* @param id client subscription id to deregister.
|
|
7994
8142
|
*/
|
|
7995
8143
|
|
|
7996
8144
|
|
|
7997
|
-
async removeOnLogsListener(
|
|
7998
|
-
|
|
7999
|
-
const subInfo = this._logsSubscriptions[id];
|
|
8000
|
-
delete this._logsSubscriptions[id];
|
|
8001
|
-
await this._unsubscribe(subInfo, 'logsUnsubscribe');
|
|
8002
|
-
|
|
8003
|
-
this._updateSubscriptions();
|
|
8004
|
-
} else {
|
|
8005
|
-
console.warn(createSubscriptionWarningMessage(id, 'logs'));
|
|
8006
|
-
}
|
|
8145
|
+
async removeOnLogsListener(clientSubscriptionId) {
|
|
8146
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'logs');
|
|
8007
8147
|
}
|
|
8008
8148
|
/**
|
|
8009
8149
|
* @internal
|
|
@@ -8011,17 +8151,12 @@ class Connection {
|
|
|
8011
8151
|
|
|
8012
8152
|
|
|
8013
8153
|
_wsOnLogsNotification(notification) {
|
|
8014
|
-
const
|
|
8015
|
-
|
|
8016
|
-
|
|
8017
|
-
|
|
8018
|
-
const sub = this._logsSubscriptions[id];
|
|
8154
|
+
const {
|
|
8155
|
+
result,
|
|
8156
|
+
subscription
|
|
8157
|
+
} = create(notification, LogsNotificationResult);
|
|
8019
8158
|
|
|
8020
|
-
|
|
8021
|
-
sub.callback(res.result.value, res.result.context);
|
|
8022
|
-
return;
|
|
8023
|
-
}
|
|
8024
|
-
}
|
|
8159
|
+
this._handleServerNotification(subscription, [result.value, result.context]);
|
|
8025
8160
|
}
|
|
8026
8161
|
/**
|
|
8027
8162
|
* @internal
|
|
@@ -8029,14 +8164,12 @@ class Connection {
|
|
|
8029
8164
|
|
|
8030
8165
|
|
|
8031
8166
|
_wsOnSlotNotification(notification) {
|
|
8032
|
-
const
|
|
8167
|
+
const {
|
|
8168
|
+
result,
|
|
8169
|
+
subscription
|
|
8170
|
+
} = create(notification, SlotNotificationResult);
|
|
8033
8171
|
|
|
8034
|
-
|
|
8035
|
-
if (sub.subscriptionId === res.subscription) {
|
|
8036
|
-
sub.callback(res.result);
|
|
8037
|
-
return;
|
|
8038
|
-
}
|
|
8039
|
-
}
|
|
8172
|
+
this._handleServerNotification(subscription, [result]);
|
|
8040
8173
|
}
|
|
8041
8174
|
/**
|
|
8042
8175
|
* Register a callback to be invoked upon slot changes
|
|
@@ -8047,33 +8180,23 @@ class Connection {
|
|
|
8047
8180
|
|
|
8048
8181
|
|
|
8049
8182
|
onSlotChange(callback) {
|
|
8050
|
-
|
|
8051
|
-
this._slotSubscriptions[id] = {
|
|
8183
|
+
return this._makeSubscription({
|
|
8052
8184
|
callback,
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
return id;
|
|
8185
|
+
method: 'slotSubscribe',
|
|
8186
|
+
unsubscribeMethod: 'slotUnsubscribe'
|
|
8187
|
+
}, []
|
|
8188
|
+
/* args */
|
|
8189
|
+
);
|
|
8059
8190
|
}
|
|
8060
8191
|
/**
|
|
8061
8192
|
* Deregister a slot notification callback
|
|
8062
8193
|
*
|
|
8063
|
-
* @param id subscription id to deregister
|
|
8194
|
+
* @param id client subscription id to deregister
|
|
8064
8195
|
*/
|
|
8065
8196
|
|
|
8066
8197
|
|
|
8067
|
-
async removeSlotChangeListener(
|
|
8068
|
-
|
|
8069
|
-
const subInfo = this._slotSubscriptions[id];
|
|
8070
|
-
delete this._slotSubscriptions[id];
|
|
8071
|
-
await this._unsubscribe(subInfo, 'slotUnsubscribe');
|
|
8072
|
-
|
|
8073
|
-
this._updateSubscriptions();
|
|
8074
|
-
} else {
|
|
8075
|
-
console.warn(createSubscriptionWarningMessage(id, 'slot change'));
|
|
8076
|
-
}
|
|
8198
|
+
async removeSlotChangeListener(clientSubscriptionId) {
|
|
8199
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'slot change');
|
|
8077
8200
|
}
|
|
8078
8201
|
/**
|
|
8079
8202
|
* @internal
|
|
@@ -8081,14 +8204,12 @@ class Connection {
|
|
|
8081
8204
|
|
|
8082
8205
|
|
|
8083
8206
|
_wsOnSlotUpdatesNotification(notification) {
|
|
8084
|
-
const
|
|
8207
|
+
const {
|
|
8208
|
+
result,
|
|
8209
|
+
subscription
|
|
8210
|
+
} = create(notification, SlotUpdateNotificationResult);
|
|
8085
8211
|
|
|
8086
|
-
|
|
8087
|
-
if (sub.subscriptionId === res.subscription) {
|
|
8088
|
-
sub.callback(res.result);
|
|
8089
|
-
return;
|
|
8090
|
-
}
|
|
8091
|
-
}
|
|
8212
|
+
this._handleServerNotification(subscription, [result]);
|
|
8092
8213
|
}
|
|
8093
8214
|
/**
|
|
8094
8215
|
* Register a callback to be invoked upon slot updates. {@link SlotUpdate}'s
|
|
@@ -8100,32 +8221,36 @@ class Connection {
|
|
|
8100
8221
|
|
|
8101
8222
|
|
|
8102
8223
|
onSlotUpdate(callback) {
|
|
8103
|
-
|
|
8104
|
-
this._slotUpdateSubscriptions[id] = {
|
|
8224
|
+
return this._makeSubscription({
|
|
8105
8225
|
callback,
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
return id;
|
|
8226
|
+
method: 'slotsUpdatesSubscribe',
|
|
8227
|
+
unsubscribeMethod: 'slotsUpdatesUnsubscribe'
|
|
8228
|
+
}, []
|
|
8229
|
+
/* args */
|
|
8230
|
+
);
|
|
8112
8231
|
}
|
|
8113
8232
|
/**
|
|
8114
8233
|
* Deregister a slot update notification callback
|
|
8115
8234
|
*
|
|
8116
|
-
* @param id subscription id to deregister
|
|
8235
|
+
* @param id client subscription id to deregister
|
|
8117
8236
|
*/
|
|
8118
8237
|
|
|
8119
8238
|
|
|
8120
|
-
async removeSlotUpdateListener(
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
8239
|
+
async removeSlotUpdateListener(clientSubscriptionId) {
|
|
8240
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'slot update');
|
|
8241
|
+
}
|
|
8242
|
+
/**
|
|
8243
|
+
* @internal
|
|
8244
|
+
*/
|
|
8125
8245
|
|
|
8126
|
-
|
|
8246
|
+
|
|
8247
|
+
async _unsubscribeClientSubscription(clientSubscriptionId, subscriptionName) {
|
|
8248
|
+
const dispose = this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId];
|
|
8249
|
+
|
|
8250
|
+
if (dispose) {
|
|
8251
|
+
await dispose();
|
|
8127
8252
|
} else {
|
|
8128
|
-
console.warn(
|
|
8253
|
+
console.warn('Ignored unsubscribe request because an active subscription with id ' + `\`${clientSubscriptionId}\` for '${subscriptionName}' events ` + 'could not be found.');
|
|
8129
8254
|
}
|
|
8130
8255
|
}
|
|
8131
8256
|
|
|
@@ -8172,30 +8297,34 @@ class Connection {
|
|
|
8172
8297
|
|
|
8173
8298
|
|
|
8174
8299
|
_wsOnSignatureNotification(notification) {
|
|
8175
|
-
const
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
|
|
8194
|
-
|
|
8195
|
-
|
|
8196
|
-
|
|
8197
|
-
|
|
8198
|
-
|
|
8300
|
+
const {
|
|
8301
|
+
result,
|
|
8302
|
+
subscription
|
|
8303
|
+
} = create(notification, SignatureNotificationResult);
|
|
8304
|
+
|
|
8305
|
+
if (result.value !== 'receivedSignature') {
|
|
8306
|
+
/**
|
|
8307
|
+
* Special case.
|
|
8308
|
+
* After a signature is processed, RPCs automatically dispose of the
|
|
8309
|
+
* subscription on the server side. We need to track which of these
|
|
8310
|
+
* subscriptions have been disposed in such a way, so that we know
|
|
8311
|
+
* whether the client is dealing with a not-yet-processed signature
|
|
8312
|
+
* (in which case we must tear down the server subscription) or an
|
|
8313
|
+
* already-processed signature (in which case the client can simply
|
|
8314
|
+
* clear out the subscription locally without telling the server).
|
|
8315
|
+
*
|
|
8316
|
+
* NOTE: There is a proposal to eliminate this special case, here:
|
|
8317
|
+
* https://github.com/solana-labs/solana/issues/18892
|
|
8318
|
+
*/
|
|
8319
|
+
this._subscriptionsAutoDisposedByRpc.add(subscription);
|
|
8320
|
+
}
|
|
8321
|
+
|
|
8322
|
+
this._handleServerNotification(subscription, result.value === 'receivedSignature' ? [{
|
|
8323
|
+
type: 'received'
|
|
8324
|
+
}, result.context] : [{
|
|
8325
|
+
type: 'status',
|
|
8326
|
+
result: result.value
|
|
8327
|
+
}, result.context]);
|
|
8199
8328
|
}
|
|
8200
8329
|
/**
|
|
8201
8330
|
* Register a callback to be invoked upon signature updates
|
|
@@ -8208,23 +8337,26 @@ class Connection {
|
|
|
8208
8337
|
|
|
8209
8338
|
|
|
8210
8339
|
onSignature(signature, callback, commitment) {
|
|
8211
|
-
const
|
|
8212
|
-
|
|
8213
|
-
|
|
8340
|
+
const args = this._buildArgs([signature], commitment || this._commitment || 'finalized' // Apply connection/server default.
|
|
8341
|
+
);
|
|
8342
|
+
|
|
8343
|
+
const clientSubscriptionId = this._makeSubscription({
|
|
8214
8344
|
callback: (notification, context) => {
|
|
8215
8345
|
if (notification.type === 'status') {
|
|
8216
|
-
callback(notification.result, context);
|
|
8346
|
+
callback(notification.result, context); // Signatures subscriptions are auto-removed by the RPC service
|
|
8347
|
+
// so no need to explicitly send an unsubscribe message.
|
|
8348
|
+
|
|
8349
|
+
try {
|
|
8350
|
+
this.removeSignatureListener(clientSubscriptionId); // eslint-disable-next-line no-empty
|
|
8351
|
+
} catch {// Already removed.
|
|
8352
|
+
}
|
|
8217
8353
|
}
|
|
8218
8354
|
},
|
|
8219
|
-
|
|
8220
|
-
|
|
8221
|
-
|
|
8222
|
-
subscriptionId: null
|
|
8223
|
-
};
|
|
8224
|
-
|
|
8225
|
-
this._updateSubscriptions();
|
|
8355
|
+
method: 'signatureSubscribe',
|
|
8356
|
+
unsubscribeMethod: 'signatureUnsubscribe'
|
|
8357
|
+
}, args);
|
|
8226
8358
|
|
|
8227
|
-
return
|
|
8359
|
+
return clientSubscriptionId;
|
|
8228
8360
|
}
|
|
8229
8361
|
/**
|
|
8230
8362
|
* Register a callback to be invoked when a transaction is
|
|
@@ -8239,35 +8371,43 @@ class Connection {
|
|
|
8239
8371
|
|
|
8240
8372
|
|
|
8241
8373
|
onSignatureWithOptions(signature, callback, options) {
|
|
8242
|
-
const
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
options
|
|
8247
|
-
|
|
8374
|
+
const {
|
|
8375
|
+
commitment,
|
|
8376
|
+
...extra
|
|
8377
|
+
} = { ...options,
|
|
8378
|
+
commitment: options && options.commitment || this._commitment || 'finalized' // Apply connection/server default.
|
|
8379
|
+
|
|
8248
8380
|
};
|
|
8249
8381
|
|
|
8250
|
-
this.
|
|
8382
|
+
const args = this._buildArgs([signature], commitment, undefined
|
|
8383
|
+
/* encoding */
|
|
8384
|
+
, extra);
|
|
8385
|
+
|
|
8386
|
+
const clientSubscriptionId = this._makeSubscription({
|
|
8387
|
+
callback: (notification, context) => {
|
|
8388
|
+
callback(notification, context); // Signatures subscriptions are auto-removed by the RPC service
|
|
8389
|
+
// so no need to explicitly send an unsubscribe message.
|
|
8390
|
+
|
|
8391
|
+
try {
|
|
8392
|
+
this.removeSignatureListener(clientSubscriptionId); // eslint-disable-next-line no-empty
|
|
8393
|
+
} catch {// Already removed.
|
|
8394
|
+
}
|
|
8395
|
+
},
|
|
8396
|
+
method: 'signatureSubscribe',
|
|
8397
|
+
unsubscribeMethod: 'signatureUnsubscribe'
|
|
8398
|
+
}, args);
|
|
8251
8399
|
|
|
8252
|
-
return
|
|
8400
|
+
return clientSubscriptionId;
|
|
8253
8401
|
}
|
|
8254
8402
|
/**
|
|
8255
8403
|
* Deregister a signature notification callback
|
|
8256
8404
|
*
|
|
8257
|
-
* @param id subscription id to deregister
|
|
8405
|
+
* @param id client subscription id to deregister
|
|
8258
8406
|
*/
|
|
8259
8407
|
|
|
8260
8408
|
|
|
8261
|
-
async removeSignatureListener(
|
|
8262
|
-
|
|
8263
|
-
const subInfo = this._signatureSubscriptions[id];
|
|
8264
|
-
delete this._signatureSubscriptions[id];
|
|
8265
|
-
await this._unsubscribe(subInfo, 'signatureUnsubscribe');
|
|
8266
|
-
|
|
8267
|
-
this._updateSubscriptions();
|
|
8268
|
-
} else {
|
|
8269
|
-
console.warn(createSubscriptionWarningMessage(id, 'signature result'));
|
|
8270
|
-
}
|
|
8409
|
+
async removeSignatureListener(clientSubscriptionId) {
|
|
8410
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'signature result');
|
|
8271
8411
|
}
|
|
8272
8412
|
/**
|
|
8273
8413
|
* @internal
|
|
@@ -8275,14 +8415,12 @@ class Connection {
|
|
|
8275
8415
|
|
|
8276
8416
|
|
|
8277
8417
|
_wsOnRootNotification(notification) {
|
|
8278
|
-
const
|
|
8418
|
+
const {
|
|
8419
|
+
result,
|
|
8420
|
+
subscription
|
|
8421
|
+
} = create(notification, RootNotificationResult);
|
|
8279
8422
|
|
|
8280
|
-
|
|
8281
|
-
if (sub.subscriptionId === res.subscription) {
|
|
8282
|
-
sub.callback(res.result);
|
|
8283
|
-
return;
|
|
8284
|
-
}
|
|
8285
|
-
}
|
|
8423
|
+
this._handleServerNotification(subscription, [result]);
|
|
8286
8424
|
}
|
|
8287
8425
|
/**
|
|
8288
8426
|
* Register a callback to be invoked upon root changes
|
|
@@ -8293,33 +8431,23 @@ class Connection {
|
|
|
8293
8431
|
|
|
8294
8432
|
|
|
8295
8433
|
onRootChange(callback) {
|
|
8296
|
-
|
|
8297
|
-
this._rootSubscriptions[id] = {
|
|
8434
|
+
return this._makeSubscription({
|
|
8298
8435
|
callback,
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
return id;
|
|
8436
|
+
method: 'rootSubscribe',
|
|
8437
|
+
unsubscribeMethod: 'rootUnsubscribe'
|
|
8438
|
+
}, []
|
|
8439
|
+
/* args */
|
|
8440
|
+
);
|
|
8305
8441
|
}
|
|
8306
8442
|
/**
|
|
8307
8443
|
* Deregister a root notification callback
|
|
8308
8444
|
*
|
|
8309
|
-
* @param id subscription id to deregister
|
|
8445
|
+
* @param id client subscription id to deregister
|
|
8310
8446
|
*/
|
|
8311
8447
|
|
|
8312
8448
|
|
|
8313
|
-
async removeRootChangeListener(
|
|
8314
|
-
|
|
8315
|
-
const subInfo = this._rootSubscriptions[id];
|
|
8316
|
-
delete this._rootSubscriptions[id];
|
|
8317
|
-
await this._unsubscribe(subInfo, 'rootUnsubscribe');
|
|
8318
|
-
|
|
8319
|
-
this._updateSubscriptions();
|
|
8320
|
-
} else {
|
|
8321
|
-
console.warn(createSubscriptionWarningMessage(id, 'root change'));
|
|
8322
|
-
}
|
|
8449
|
+
async removeRootChangeListener(clientSubscriptionId) {
|
|
8450
|
+
await this._unsubscribeClientSubscription(clientSubscriptionId, 'root change');
|
|
8323
8451
|
}
|
|
8324
8452
|
|
|
8325
8453
|
}
|
|
@@ -9999,5 +10127,5 @@ function clusterApiUrl(cluster, tls) {
|
|
|
9999
10127
|
|
|
10000
10128
|
const LAMPORTS_PER_SOL = 1000000000;
|
|
10001
10129
|
|
|
10002
|
-
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
10130
|
+
export { Account, Authorized, BLOCKHASH_CACHE_TIMEOUT_MS, BPF_LOADER_DEPRECATED_PROGRAM_ID, BPF_LOADER_PROGRAM_ID, BpfLoader, COMPUTE_BUDGET_INSTRUCTION_LAYOUTS, ComputeBudgetInstruction, ComputeBudgetProgram, Connection, Ed25519Program, Enum, EpochSchedule, FeeCalculatorLayout, Keypair, LAMPORTS_PER_SOL, Loader, Lockup, MAX_SEED_LENGTH, Message, NONCE_ACCOUNT_LENGTH, NonceAccount, PACKET_DATA_SIZE, PublicKey, SIGNATURE_LENGTH_IN_BYTES, SOLANA_SCHEMA, STAKE_CONFIG_ID, STAKE_INSTRUCTION_LAYOUTS, SYSTEM_INSTRUCTION_LAYOUTS, SYSVAR_CLOCK_PUBKEY, SYSVAR_EPOCH_SCHEDULE_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, SYSVAR_RECENT_BLOCKHASHES_PUBKEY, SYSVAR_RENT_PUBKEY, SYSVAR_REWARDS_PUBKEY, SYSVAR_SLOT_HASHES_PUBKEY, SYSVAR_SLOT_HISTORY_PUBKEY, SYSVAR_STAKE_HISTORY_PUBKEY, Secp256k1Program, SendTransactionError, StakeAuthorizationLayout, StakeInstruction, StakeProgram, Struct, SystemInstruction, SystemProgram, Transaction, TransactionInstruction, VALIDATOR_INFO_KEY, VOTE_PROGRAM_ID, ValidatorInfo, VoteAccount, VoteAuthorizationLayout, VoteInit, VoteInstruction, VoteProgram, clusterApiUrl, sendAndConfirmRawTransaction, sendAndConfirmTransaction };
|
|
10003
10131
|
//# sourceMappingURL=index.browser.esm.js.map
|