@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.
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +31 -20
- package/package.json +1 -1
- package/src/tx/retryTxSender.ts +42 -26
|
@@ -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>(
|
|
19
|
+
promiseTimeout<T>(promises: Promise<T>[], timeoutMs: number): Promise<T | null>;
|
|
20
20
|
sendToAdditionalConnections(rawTx: Buffer, opts: ConfirmOptions): void;
|
|
21
21
|
}
|
|
22
22
|
export {};
|
package/lib/tx/retryTxSender.js
CHANGED
|
@@ -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
|
-
|
|
102
|
+
const subscriptionIds = new Array();
|
|
103
|
+
const connections = [
|
|
104
|
+
this.provider.connection,
|
|
105
|
+
...this.additionalConnections,
|
|
106
|
+
];
|
|
103
107
|
let response = null;
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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(
|
|
129
|
+
yield this.promiseTimeout(promises, this.timeout);
|
|
121
130
|
}
|
|
122
131
|
finally {
|
|
123
|
-
|
|
124
|
-
|
|
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(
|
|
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([
|
|
161
|
+
return Promise.race([...promises, timeoutPromise]).then((result) => {
|
|
151
162
|
clearTimeout(timeoutId);
|
|
152
163
|
return result;
|
|
153
164
|
});
|
package/package.json
CHANGED
package/src/tx/retryTxSender.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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(
|
|
170
|
+
await this.promiseTimeout(promises, this.timeout);
|
|
162
171
|
} finally {
|
|
163
|
-
|
|
164
|
-
|
|
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>(
|
|
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([
|
|
198
|
-
|
|
199
|
-
|
|
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 {
|