@solana/web3.js 1.66.2 → 1.66.4

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.
@@ -1827,7 +1827,7 @@ class Transaction {
1827
1827
  return false;
1828
1828
  }
1829
1829
  } else {
1830
- if (!verify(signature, signData, publicKey.toBuffer())) {
1830
+ if (!verify(signature, signData, publicKey.toBytes())) {
1831
1831
  return false;
1832
1832
  }
1833
1833
  }
@@ -3223,12 +3223,12 @@ class BpfLoader {
3223
3223
  return Loader.getMinNumSignatures(dataLength);
3224
3224
  }
3225
3225
  /**
3226
- * Load a BPF program
3226
+ * Load a SBF program
3227
3227
  *
3228
3228
  * @param connection The connection to use
3229
3229
  * @param payer Account that will pay program loading fees
3230
3230
  * @param program Account to load the program into
3231
- * @param elf The entire ELF containing the BPF program
3231
+ * @param elf The entire ELF containing the SBF program
3232
3232
  * @param loaderProgramId The program id of the BPF loader to use
3233
3233
  * @return true if program was loaded successfully, false if program was already loaded
3234
3234
  */
@@ -4605,6 +4605,10 @@ class Connection {
4605
4605
 
4606
4606
  /** @internal */
4607
4607
 
4608
+ /** @internal */
4609
+
4610
+ /** @internal */
4611
+
4608
4612
  /**
4609
4613
  * Special case.
4610
4614
  * After a signature is processed, RPCs automatically dispose of the
@@ -4650,6 +4654,8 @@ class Connection {
4650
4654
  };
4651
4655
  this._nextClientSubscriptionId = 0;
4652
4656
  this._subscriptionDisposeFunctionsByClientSubscriptionId = {};
4657
+ this._subscriptionHashByClientSubscriptionId = {};
4658
+ this._subscriptionStateChangeCallbacksByHash = {};
4653
4659
  this._subscriptionCallbacksByServerSubscriptionId = {};
4654
4660
  this._subscriptionsByHash = {};
4655
4661
  this._subscriptionsAutoDisposedByRpc = new Set();
@@ -5179,12 +5185,13 @@ class Connection {
5179
5185
  assert(decodedSignature.length === 64, 'signature has invalid length');
5180
5186
  const subscriptionCommitment = commitment || this.commitment;
5181
5187
  let timeoutId;
5182
- let subscriptionId;
5188
+ let signatureSubscriptionId;
5189
+ let disposeSignatureSubscriptionStateChangeObserver;
5183
5190
  let done = false;
5184
5191
  const confirmationPromise = new Promise((resolve, reject) => {
5185
5192
  try {
5186
- subscriptionId = this.onSignature(rawSignature, (result, context) => {
5187
- subscriptionId = undefined;
5193
+ signatureSubscriptionId = this.onSignature(rawSignature, (result, context) => {
5194
+ signatureSubscriptionId = undefined;
5188
5195
  const response = {
5189
5196
  context,
5190
5197
  value: result
@@ -5195,6 +5202,48 @@ class Connection {
5195
5202
  response
5196
5203
  });
5197
5204
  }, subscriptionCommitment);
5205
+ const subscriptionSetupPromise = new Promise(resolveSubscriptionSetup => {
5206
+ if (signatureSubscriptionId == null) {
5207
+ resolveSubscriptionSetup();
5208
+ } else {
5209
+ disposeSignatureSubscriptionStateChangeObserver = this._onSubscriptionStateChange(signatureSubscriptionId, nextState => {
5210
+ if (nextState === 'subscribed') {
5211
+ resolveSubscriptionSetup();
5212
+ }
5213
+ });
5214
+ }
5215
+ });
5216
+
5217
+ (async () => {
5218
+ await subscriptionSetupPromise;
5219
+ if (done) return;
5220
+ const response = await this.getSignatureStatus(rawSignature);
5221
+ if (done) return;
5222
+
5223
+ if (response == null) {
5224
+ return;
5225
+ }
5226
+
5227
+ const {
5228
+ context,
5229
+ value
5230
+ } = response;
5231
+
5232
+ if (value !== null && value !== void 0 && value.err) {
5233
+ reject(value.err);
5234
+ }
5235
+
5236
+ if (value) {
5237
+ done = true;
5238
+ resolve({
5239
+ __type: TransactionStatus.PROCESSED,
5240
+ response: {
5241
+ context,
5242
+ value
5243
+ }
5244
+ });
5245
+ }
5246
+ })();
5198
5247
  } catch (err) {
5199
5248
  reject(err);
5200
5249
  }
@@ -5267,8 +5316,12 @@ class Connection {
5267
5316
  } finally {
5268
5317
  clearTimeout(timeoutId);
5269
5318
 
5270
- if (subscriptionId) {
5271
- this.removeSignatureListener(subscriptionId);
5319
+ if (disposeSignatureSubscriptionStateChangeObserver) {
5320
+ disposeSignatureSubscriptionStateChangeObserver();
5321
+ }
5322
+
5323
+ if (signatureSubscriptionId) {
5324
+ this.removeSignatureListener(signatureSubscriptionId);
5272
5325
  }
5273
5326
  }
5274
5327
 
@@ -6770,9 +6823,9 @@ class Connection {
6770
6823
 
6771
6824
  this._subscriptionCallbacksByServerSubscriptionId = {};
6772
6825
  Object.entries(this._subscriptionsByHash).forEach(([hash, subscription]) => {
6773
- this._subscriptionsByHash[hash] = { ...subscription,
6826
+ this._setSubscription(hash, { ...subscription,
6774
6827
  state: 'pending'
6775
- };
6828
+ });
6776
6829
  });
6777
6830
  }
6778
6831
  /**
@@ -6780,6 +6833,53 @@ class Connection {
6780
6833
  */
6781
6834
 
6782
6835
 
6836
+ _setSubscription(hash, nextSubscription) {
6837
+ var _this$_subscriptionsB;
6838
+
6839
+ const prevState = (_this$_subscriptionsB = this._subscriptionsByHash[hash]) === null || _this$_subscriptionsB === void 0 ? void 0 : _this$_subscriptionsB.state;
6840
+ this._subscriptionsByHash[hash] = nextSubscription;
6841
+
6842
+ if (prevState !== nextSubscription.state) {
6843
+ const stateChangeCallbacks = this._subscriptionStateChangeCallbacksByHash[hash];
6844
+
6845
+ if (stateChangeCallbacks) {
6846
+ stateChangeCallbacks.forEach(cb => {
6847
+ try {
6848
+ cb(nextSubscription.state); // eslint-disable-next-line no-empty
6849
+ } catch {}
6850
+ });
6851
+ }
6852
+ }
6853
+ }
6854
+ /**
6855
+ * @internal
6856
+ */
6857
+
6858
+
6859
+ _onSubscriptionStateChange(clientSubscriptionId, callback) {
6860
+ var _this$_subscriptionSt;
6861
+
6862
+ const hash = this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
6863
+
6864
+ if (hash == null) {
6865
+ return () => {};
6866
+ }
6867
+
6868
+ const stateChangeCallbacks = (_this$_subscriptionSt = this._subscriptionStateChangeCallbacksByHash)[hash] || (_this$_subscriptionSt[hash] = new Set());
6869
+ stateChangeCallbacks.add(callback);
6870
+ return () => {
6871
+ stateChangeCallbacks.delete(callback);
6872
+
6873
+ if (stateChangeCallbacks.size === 0) {
6874
+ delete this._subscriptionStateChangeCallbacksByHash[hash];
6875
+ }
6876
+ };
6877
+ }
6878
+ /**
6879
+ * @internal
6880
+ */
6881
+
6882
+
6783
6883
  async _updateSubscriptions() {
6784
6884
  if (Object.keys(this._subscriptionsByHash).length === 0) {
6785
6885
  if (this._rpcWebSocketConnected) {
@@ -6865,14 +6965,17 @@ class Connection {
6865
6965
  } = subscription;
6866
6966
 
6867
6967
  try {
6868
- this._subscriptionsByHash[hash] = { ...subscription,
6968
+ this._setSubscription(hash, { ...subscription,
6869
6969
  state: 'subscribing'
6870
- };
6970
+ });
6971
+
6871
6972
  const serverSubscriptionId = await this._rpcWebSocket.call(method, args);
6872
- this._subscriptionsByHash[hash] = { ...subscription,
6973
+
6974
+ this._setSubscription(hash, { ...subscription,
6873
6975
  serverSubscriptionId,
6874
6976
  state: 'subscribed'
6875
- };
6977
+ });
6978
+
6876
6979
  this._subscriptionCallbacksByServerSubscriptionId[serverSubscriptionId] = subscription.callbacks;
6877
6980
  await this._updateSubscriptions();
6878
6981
  } catch (e) {
@@ -6885,9 +6988,10 @@ class Connection {
6885
6988
  } // TODO: Maybe add an 'errored' state or a retry limit?
6886
6989
 
6887
6990
 
6888
- this._subscriptionsByHash[hash] = { ...subscription,
6991
+ this._setSubscription(hash, { ...subscription,
6889
6992
  state: 'pending'
6890
- };
6993
+ });
6994
+
6891
6995
  await this._updateSubscriptions();
6892
6996
  }
6893
6997
  })();
@@ -6916,9 +7020,13 @@ class Connection {
6916
7020
  */
6917
7021
  this._subscriptionsAutoDisposedByRpc.delete(serverSubscriptionId);
6918
7022
  } else {
6919
- this._subscriptionsByHash[hash] = { ...subscription,
7023
+ this._setSubscription(hash, { ...subscription,
7024
+ state: 'unsubscribing'
7025
+ });
7026
+
7027
+ this._setSubscription(hash, { ...subscription,
6920
7028
  state: 'unsubscribing'
6921
- };
7029
+ });
6922
7030
 
6923
7031
  try {
6924
7032
  await this._rpcWebSocket.call(unsubscribeMethod, [serverSubscriptionId]);
@@ -6932,17 +7040,19 @@ class Connection {
6932
7040
  } // TODO: Maybe add an 'errored' state or a retry limit?
6933
7041
 
6934
7042
 
6935
- this._subscriptionsByHash[hash] = { ...subscription,
7043
+ this._setSubscription(hash, { ...subscription,
6936
7044
  state: 'subscribed'
6937
- };
7045
+ });
7046
+
6938
7047
  await this._updateSubscriptions();
6939
7048
  return;
6940
7049
  }
6941
7050
  }
6942
7051
 
6943
- this._subscriptionsByHash[hash] = { ...subscription,
7052
+ this._setSubscription(hash, { ...subscription,
6944
7053
  state: 'unsubscribed'
6945
- };
7054
+ });
7055
+
6946
7056
  await this._updateSubscriptions();
6947
7057
  })();
6948
7058
  }
@@ -7035,8 +7145,11 @@ class Connection {
7035
7145
  existingSubscription.callbacks.add(subscriptionConfig.callback);
7036
7146
  }
7037
7147
 
7148
+ this._subscriptionHashByClientSubscriptionId[clientSubscriptionId] = hash;
7149
+
7038
7150
  this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId] = async () => {
7039
7151
  delete this._subscriptionDisposeFunctionsByClientSubscriptionId[clientSubscriptionId];
7152
+ delete this._subscriptionHashByClientSubscriptionId[clientSubscriptionId];
7040
7153
  const subscription = this._subscriptionsByHash[hash];
7041
7154
  assert(subscription !== undefined, `Could not find a \`Subscription\` when tearing down client subscription #${clientSubscriptionId}`);
7042
7155
  subscription.callbacks.delete(subscriptionConfig.callback);