@drift-labs/sdk 0.1.30-master.3 → 0.1.30-master.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.
@@ -16,7 +16,7 @@ export declare class RetryTxSender implements TxSender {
16
16
  confirmTransaction(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
17
17
  getTimestamp(): number;
18
18
  sleep(reference: ResolveReference): Promise<void>;
19
- promiseTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T | null>;
19
+ promiseTimeout<T>(promises: Promise<T>[], timeoutMs: number): Promise<T | null>;
20
20
  sendToAdditionalConnections(rawTx: Buffer, opts: ConfirmOptions): void;
21
21
  }
22
22
  export {};
@@ -99,29 +99,40 @@ class RetryTxSender {
99
99
  (0, assert_1.default)(decodedSignature.length === 64, 'signature has invalid length');
100
100
  const start = Date.now();
101
101
  const subscriptionCommitment = commitment || this.provider.opts.commitment;
102
- let subscriptionId;
102
+ const subscriptionIds = new Array();
103
+ const connections = [
104
+ this.provider.connection,
105
+ ...this.additionalConnections,
106
+ ];
103
107
  let response = null;
104
- const confirmPromise = new Promise((resolve, reject) => {
105
- try {
106
- subscriptionId = this.provider.connection.onSignature(signature, (result, context) => {
107
- subscriptionId = undefined;
108
- response = {
109
- context,
110
- value: result,
111
- };
112
- resolve(null);
113
- }, subscriptionCommitment);
114
- }
115
- catch (err) {
116
- reject(err);
117
- }
108
+ const promises = connections.map((connection, i) => {
109
+ let subscriptionId;
110
+ const confirmPromise = new Promise((resolve, reject) => {
111
+ try {
112
+ subscriptionId = connection.onSignature(signature, (result, context) => {
113
+ subscriptionIds[i] = undefined;
114
+ response = {
115
+ context,
116
+ value: result,
117
+ };
118
+ resolve(null);
119
+ }, subscriptionCommitment);
120
+ }
121
+ catch (err) {
122
+ reject(err);
123
+ }
124
+ });
125
+ subscriptionIds.push(subscriptionId);
126
+ return confirmPromise;
118
127
  });
119
128
  try {
120
- yield this.promiseTimeout(confirmPromise, this.timeout);
129
+ yield this.promiseTimeout(promises, this.timeout);
121
130
  }
122
131
  finally {
123
- if (subscriptionId) {
124
- this.provider.connection.removeSignatureListener(subscriptionId);
132
+ for (const [i, subscriptionId] of subscriptionIds.entries()) {
133
+ if (subscriptionId) {
134
+ connections[i].removeSignatureListener(subscriptionId);
135
+ }
125
136
  }
126
137
  }
127
138
  if (response === null) {
@@ -142,12 +153,12 @@ class RetryTxSender {
142
153
  });
143
154
  });
144
155
  }
145
- promiseTimeout(promise, timeoutMs) {
156
+ promiseTimeout(promises, timeoutMs) {
146
157
  let timeoutId;
147
158
  const timeoutPromise = new Promise((resolve) => {
148
159
  timeoutId = setTimeout(() => resolve(null), timeoutMs);
149
160
  });
150
- return Promise.race([promise, timeoutPromise]).then((result) => {
161
+ return Promise.race([...promises, timeoutPromise]).then((result) => {
151
162
  clearTimeout(timeoutId);
152
163
  return result;
153
164
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "0.1.30-master.3",
3
+ "version": "0.1.30-master.4",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -136,32 +136,43 @@ export class RetryTxSender implements TxSender {
136
136
  const start = Date.now();
137
137
  const subscriptionCommitment = commitment || this.provider.opts.commitment;
138
138
 
139
- let subscriptionId;
139
+ const subscriptionIds = new Array<number>();
140
+ const connections = [
141
+ this.provider.connection,
142
+ ...this.additionalConnections,
143
+ ];
140
144
  let response: RpcResponseAndContext<SignatureResult> | null = null;
141
- const confirmPromise = new Promise((resolve, reject) => {
142
- try {
143
- subscriptionId = this.provider.connection.onSignature(
144
- signature,
145
- (result: SignatureResult, context: Context) => {
146
- subscriptionId = undefined;
147
- response = {
148
- context,
149
- value: result,
150
- };
151
- resolve(null);
152
- },
153
- subscriptionCommitment
154
- );
155
- } catch (err) {
156
- reject(err);
157
- }
145
+ const promises = connections.map((connection, i) => {
146
+ let subscriptionId;
147
+ const confirmPromise = new Promise((resolve, reject) => {
148
+ try {
149
+ subscriptionId = connection.onSignature(
150
+ signature,
151
+ (result: SignatureResult, context: Context) => {
152
+ subscriptionIds[i] = undefined;
153
+ response = {
154
+ context,
155
+ value: result,
156
+ };
157
+ resolve(null);
158
+ },
159
+ subscriptionCommitment
160
+ );
161
+ } catch (err) {
162
+ reject(err);
163
+ }
164
+ });
165
+ subscriptionIds.push(subscriptionId);
166
+ return confirmPromise;
158
167
  });
159
168
 
160
169
  try {
161
- await this.promiseTimeout(confirmPromise, this.timeout);
170
+ await this.promiseTimeout(promises, this.timeout);
162
171
  } finally {
163
- if (subscriptionId) {
164
- this.provider.connection.removeSignatureListener(subscriptionId);
172
+ for (const [i, subscriptionId] of subscriptionIds.entries()) {
173
+ if (subscriptionId) {
174
+ connections[i].removeSignatureListener(subscriptionId);
175
+ }
165
176
  }
166
177
  }
167
178
 
@@ -188,16 +199,21 @@ export class RetryTxSender implements TxSender {
188
199
  });
189
200
  }
190
201
 
191
- promiseTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T | null> {
202
+ promiseTimeout<T>(
203
+ promises: Promise<T>[],
204
+ timeoutMs: number
205
+ ): Promise<T | null> {
192
206
  let timeoutId: ReturnType<typeof setTimeout>;
193
207
  const timeoutPromise: Promise<null> = new Promise((resolve) => {
194
208
  timeoutId = setTimeout(() => resolve(null), timeoutMs);
195
209
  });
196
210
 
197
- return Promise.race([promise, timeoutPromise]).then((result: T | null) => {
198
- clearTimeout(timeoutId);
199
- return result;
200
- });
211
+ return Promise.race([...promises, timeoutPromise]).then(
212
+ (result: T | null) => {
213
+ clearTimeout(timeoutId);
214
+ return result;
215
+ }
216
+ );
201
217
  }
202
218
 
203
219
  sendToAdditionalConnections(rawTx: Buffer, opts: ConfirmOptions): void {