@shapeshiftoss/unchained-client 8.5.0 → 9.0.0-alpha.2

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.
@@ -109,7 +109,35 @@ const V1ApiAxiosParamCreator = function (configuration) {
109
109
  };
110
110
  },
111
111
  /**
112
- * Get transaction specific data directly from the node
112
+ * Get raw transaction details directly from the node
113
+ * @param {string} txid transaction hash
114
+ * @param {*} [options] Override http request option.
115
+ * @throws {RequiredError}
116
+ */
117
+ getRawTransaction: async (txid, options = {}) => {
118
+ // verify required parameter 'txid' is not null or undefined
119
+ (0, common_1.assertParamExists)('getRawTransaction', 'txid', txid);
120
+ const localVarPath = `/api/v1/tx/{txid}/raw`
121
+ .replace(`{${"txid"}}`, encodeURIComponent(String(txid)));
122
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
123
+ const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
124
+ let baseOptions;
125
+ if (configuration) {
126
+ baseOptions = configuration.baseOptions;
127
+ }
128
+ const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
129
+ const localVarHeaderParameter = {};
130
+ const localVarQueryParameter = {};
131
+ (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
132
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
133
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
134
+ return {
135
+ url: (0, common_1.toPathString)(localVarUrlObj),
136
+ options: localVarRequestOptions,
137
+ };
138
+ },
139
+ /**
140
+ * Get transaction details
113
141
  * @param {string} txid transaction hash
114
142
  * @param {*} [options] Override http request option.
115
143
  * @throws {RequiredError}
@@ -117,7 +145,7 @@ const V1ApiAxiosParamCreator = function (configuration) {
117
145
  getTransaction: async (txid, options = {}) => {
118
146
  // verify required parameter 'txid' is not null or undefined
119
147
  (0, common_1.assertParamExists)('getTransaction', 'txid', txid);
120
- const localVarPath = `/api/v1/transaction/{txid}`
148
+ const localVarPath = `/api/v1/tx/{txid}`
121
149
  .replace(`{${"txid"}}`, encodeURIComponent(String(txid)));
122
150
  // use dummy base URL string because the URL constructor only accepts absolute URLs.
123
151
  const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
@@ -268,7 +296,17 @@ const V1ApiFp = function (configuration) {
268
296
  return (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration);
269
297
  },
270
298
  /**
271
- * Get transaction specific data directly from the node
299
+ * Get raw transaction details directly from the node
300
+ * @param {string} txid transaction hash
301
+ * @param {*} [options] Override http request option.
302
+ * @throws {RequiredError}
303
+ */
304
+ async getRawTransaction(txid, options) {
305
+ const localVarAxiosArgs = await localVarAxiosParamCreator.getRawTransaction(txid, options);
306
+ return (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration);
307
+ },
308
+ /**
309
+ * Get transaction details
272
310
  * @param {string} txid transaction hash
273
311
  * @param {*} [options] Override http request option.
274
312
  * @throws {RequiredError}
@@ -345,7 +383,16 @@ const V1ApiFactory = function (configuration, basePath, axios) {
345
383
  return localVarFp.getNetworkFees(options).then((request) => request(axios, basePath));
346
384
  },
347
385
  /**
348
- * Get transaction specific data directly from the node
386
+ * Get raw transaction details directly from the node
387
+ * @param {string} txid transaction hash
388
+ * @param {*} [options] Override http request option.
389
+ * @throws {RequiredError}
390
+ */
391
+ getRawTransaction(txid, options) {
392
+ return localVarFp.getRawTransaction(txid, options).then((request) => request(axios, basePath));
393
+ },
394
+ /**
395
+ * Get transaction details
349
396
  * @param {string} txid transaction hash
350
397
  * @param {*} [options] Override http request option.
351
398
  * @throws {RequiredError}
@@ -421,7 +468,17 @@ class V1Api extends base_1.BaseAPI {
421
468
  return (0, exports.V1ApiFp)(this.configuration).getNetworkFees(options).then((request) => request(this.axios, this.basePath));
422
469
  }
423
470
  /**
424
- * Get transaction specific data directly from the node
471
+ * Get raw transaction details directly from the node
472
+ * @param {V1ApiGetRawTransactionRequest} requestParameters Request parameters.
473
+ * @param {*} [options] Override http request option.
474
+ * @throws {RequiredError}
475
+ * @memberof V1Api
476
+ */
477
+ getRawTransaction(requestParameters, options) {
478
+ return (0, exports.V1ApiFp)(this.configuration).getRawTransaction(requestParameters.txid, options).then((request) => request(this.axios, this.basePath));
479
+ }
480
+ /**
481
+ * Get transaction details
425
482
  * @param {V1ApiGetTransactionRequest} requestParameters Request parameters.
426
483
  * @param {*} [options] Override http request option.
427
484
  * @throws {RequiredError}
@@ -20,7 +20,7 @@ exports.RequiredError = exports.BaseAPI = exports.COLLECTION_FORMATS = exports.B
20
20
  // Some imports not used depending on template conditions
21
21
  // @ts-ignore
22
22
  const axios_1 = __importDefault(require("axios"));
23
- exports.BASE_PATH = "https://api.bitcoin.shapeshift.com".replace(/\/+$/, "");
23
+ exports.BASE_PATH = "https://dev-api.bitcoin.shapeshift.com".replace(/\/+$/, "");
24
24
  /**
25
25
  *
26
26
  * @export
@@ -85,13 +85,13 @@ export interface EthereumTx {
85
85
  * @type {number}
86
86
  * @memberof EthereumTx
87
87
  */
88
- 'blockHeight'?: number;
88
+ 'blockHeight': number;
89
89
  /**
90
90
  *
91
91
  * @type {number}
92
92
  * @memberof EthereumTx
93
93
  */
94
- 'timestamp'?: number;
94
+ 'timestamp': number;
95
95
  /**
96
96
  *
97
97
  * @type {string}
@@ -158,6 +158,12 @@ export interface EthereumTx {
158
158
  * @memberof EthereumTx
159
159
  */
160
160
  'tokenTransfers'?: Array<TokenTransfer>;
161
+ /**
162
+ *
163
+ * @type {Array<InternalTx>}
164
+ * @memberof EthereumTx
165
+ */
166
+ 'internalTxs'?: Array<InternalTx>;
161
167
  }
162
168
  /**
163
169
  * Contains info about Ethereum transaction history
@@ -235,6 +241,31 @@ export interface InternalServerError {
235
241
  */
236
242
  'message': string;
237
243
  }
244
+ /**
245
+ * Contains info about an Ethereum internal transaction
246
+ * @export
247
+ * @interface InternalTx
248
+ */
249
+ export interface InternalTx {
250
+ /**
251
+ *
252
+ * @type {string}
253
+ * @memberof InternalTx
254
+ */
255
+ 'from': string;
256
+ /**
257
+ *
258
+ * @type {string}
259
+ * @memberof InternalTx
260
+ */
261
+ 'to': string;
262
+ /**
263
+ *
264
+ * @type {string}
265
+ * @memberof InternalTx
266
+ */
267
+ 'value': string;
268
+ }
238
269
  /**
239
270
  * Contains the serialized raw transaction hex
240
271
  * @export
@@ -369,13 +400,13 @@ export interface Tx {
369
400
  * @type {number}
370
401
  * @memberof Tx
371
402
  */
372
- 'blockHeight'?: number;
403
+ 'blockHeight': number;
373
404
  /**
374
405
  *
375
406
  * @type {number}
376
407
  * @memberof Tx
377
408
  */
378
- 'timestamp'?: number;
409
+ 'timestamp': number;
379
410
  }
380
411
  /**
381
412
  * Contains info about a 422 Validation Error response
@@ -436,6 +467,13 @@ export declare const V1ApiAxiosParamCreator: (configuration?: Configuration | un
436
467
  * @throws {RequiredError}
437
468
  */
438
469
  getInfo: (options?: AxiosRequestConfig) => Promise<RequestArgs>;
470
+ /**
471
+ * Get transaction details
472
+ * @param {string} txid transaction hash
473
+ * @param {*} [options] Override http request option.
474
+ * @throws {RequiredError}
475
+ */
476
+ getTransaction: (txid: string, options?: AxiosRequestConfig) => Promise<RequestArgs>;
439
477
  /**
440
478
  * Get transaction history by address
441
479
  * @param {string} pubkey account address
@@ -487,6 +525,13 @@ export declare const V1ApiFp: (configuration?: Configuration | undefined) => {
487
525
  * @throws {RequiredError}
488
526
  */
489
527
  getInfo(options?: AxiosRequestConfig<any> | undefined): Promise<(axios?: AxiosInstance | undefined, basePath?: string | undefined) => AxiosPromise<Info>>;
528
+ /**
529
+ * Get transaction details
530
+ * @param {string} txid transaction hash
531
+ * @param {*} [options] Override http request option.
532
+ * @throws {RequiredError}
533
+ */
534
+ getTransaction(txid: string, options?: AxiosRequestConfig<any> | undefined): Promise<(axios?: AxiosInstance | undefined, basePath?: string | undefined) => AxiosPromise<EthereumTx>>;
490
535
  /**
491
536
  * Get transaction history by address
492
537
  * @param {string} pubkey account address
@@ -538,6 +583,13 @@ export declare const V1ApiFactory: (configuration?: Configuration | undefined, b
538
583
  * @throws {RequiredError}
539
584
  */
540
585
  getInfo(options?: any): AxiosPromise<Info>;
586
+ /**
587
+ * Get transaction details
588
+ * @param {string} txid transaction hash
589
+ * @param {*} [options] Override http request option.
590
+ * @throws {RequiredError}
591
+ */
592
+ getTransaction(txid: string, options?: any): AxiosPromise<EthereumTx>;
541
593
  /**
542
594
  * Get transaction history by address
543
595
  * @param {string} pubkey account address
@@ -599,6 +651,19 @@ export interface V1ApiGetAccountRequest {
599
651
  */
600
652
  readonly pubkey: string;
601
653
  }
654
+ /**
655
+ * Request parameters for getTransaction operation in V1Api.
656
+ * @export
657
+ * @interface V1ApiGetTransactionRequest
658
+ */
659
+ export interface V1ApiGetTransactionRequest {
660
+ /**
661
+ * transaction hash
662
+ * @type {string}
663
+ * @memberof V1ApiGetTransaction
664
+ */
665
+ readonly txid: string;
666
+ }
602
667
  /**
603
668
  * Request parameters for getTxHistory operation in V1Api.
604
669
  * @export
@@ -674,6 +739,14 @@ export declare class V1Api extends BaseAPI {
674
739
  * @memberof V1Api
675
740
  */
676
741
  getInfo(options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<Info, any>>;
742
+ /**
743
+ * Get transaction details
744
+ * @param {V1ApiGetTransactionRequest} requestParameters Request parameters.
745
+ * @param {*} [options] Override http request option.
746
+ * @throws {RequiredError}
747
+ * @memberof V1Api
748
+ */
749
+ getTransaction(requestParameters: V1ApiGetTransactionRequest, options?: AxiosRequestConfig): Promise<import("axios").AxiosResponse<EthereumTx, any>>;
677
750
  /**
678
751
  * Get transaction history by address
679
752
  * @param {V1ApiGetTxHistoryRequest} requestParameters Request parameters.
@@ -156,6 +156,34 @@ const V1ApiAxiosParamCreator = function (configuration) {
156
156
  options: localVarRequestOptions,
157
157
  };
158
158
  },
159
+ /**
160
+ * Get transaction details
161
+ * @param {string} txid transaction hash
162
+ * @param {*} [options] Override http request option.
163
+ * @throws {RequiredError}
164
+ */
165
+ getTransaction: async (txid, options = {}) => {
166
+ // verify required parameter 'txid' is not null or undefined
167
+ (0, common_1.assertParamExists)('getTransaction', 'txid', txid);
168
+ const localVarPath = `/api/v1/tx/{txid}`
169
+ .replace(`{${"txid"}}`, encodeURIComponent(String(txid)));
170
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
171
+ const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
172
+ let baseOptions;
173
+ if (configuration) {
174
+ baseOptions = configuration.baseOptions;
175
+ }
176
+ const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
177
+ const localVarHeaderParameter = {};
178
+ const localVarQueryParameter = {};
179
+ (0, common_1.setSearchParams)(localVarUrlObj, localVarQueryParameter);
180
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
181
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
182
+ return {
183
+ url: (0, common_1.toPathString)(localVarUrlObj),
184
+ options: localVarRequestOptions,
185
+ };
186
+ },
159
187
  /**
160
188
  * Get transaction history by address
161
189
  * @param {string} pubkey account address
@@ -272,6 +300,16 @@ const V1ApiFp = function (configuration) {
272
300
  const localVarAxiosArgs = await localVarAxiosParamCreator.getInfo(options);
273
301
  return (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration);
274
302
  },
303
+ /**
304
+ * Get transaction details
305
+ * @param {string} txid transaction hash
306
+ * @param {*} [options] Override http request option.
307
+ * @throws {RequiredError}
308
+ */
309
+ async getTransaction(txid, options) {
310
+ const localVarAxiosArgs = await localVarAxiosParamCreator.getTransaction(txid, options);
311
+ return (0, common_1.createRequestFunction)(localVarAxiosArgs, axios_1.default, base_1.BASE_PATH, configuration);
312
+ },
275
313
  /**
276
314
  * Get transaction history by address
277
315
  * @param {string} pubkey account address
@@ -341,6 +379,15 @@ const V1ApiFactory = function (configuration, basePath, axios) {
341
379
  getInfo(options) {
342
380
  return localVarFp.getInfo(options).then((request) => request(axios, basePath));
343
381
  },
382
+ /**
383
+ * Get transaction details
384
+ * @param {string} txid transaction hash
385
+ * @param {*} [options] Override http request option.
386
+ * @throws {RequiredError}
387
+ */
388
+ getTransaction(txid, options) {
389
+ return localVarFp.getTransaction(txid, options).then((request) => request(axios, basePath));
390
+ },
344
391
  /**
345
392
  * Get transaction history by address
346
393
  * @param {string} pubkey account address
@@ -409,6 +456,16 @@ class V1Api extends base_1.BaseAPI {
409
456
  getInfo(options) {
410
457
  return (0, exports.V1ApiFp)(this.configuration).getInfo(options).then((request) => request(this.axios, this.basePath));
411
458
  }
459
+ /**
460
+ * Get transaction details
461
+ * @param {V1ApiGetTransactionRequest} requestParameters Request parameters.
462
+ * @param {*} [options] Override http request option.
463
+ * @throws {RequiredError}
464
+ * @memberof V1Api
465
+ */
466
+ getTransaction(requestParameters, options) {
467
+ return (0, exports.V1ApiFp)(this.configuration).getTransaction(requestParameters.txid, options).then((request) => request(this.axios, this.basePath));
468
+ }
412
469
  /**
413
470
  * Get transaction history by address
414
471
  * @param {V1ApiGetTxHistoryRequest} requestParameters Request parameters.
@@ -20,7 +20,7 @@ exports.RequiredError = exports.BaseAPI = exports.COLLECTION_FORMATS = exports.B
20
20
  // Some imports not used depending on template conditions
21
21
  // @ts-ignore
22
22
  const axios_1 = __importDefault(require("axios"));
23
- exports.BASE_PATH = "https://api.ethereum.shapeshift.com".replace(/\/+$/, "");
23
+ exports.BASE_PATH = "https://dev-api.ethereum.shapeshift.com".replace(/\/+$/, "");
24
24
  /**
25
25
  *
26
26
  * @export
@@ -4,6 +4,7 @@ import WebSocket from 'isomorphic-ws';
4
4
  export interface Connection {
5
5
  ws: WebSocket;
6
6
  pingTimeout?: NodeJS.Timeout;
7
+ interval: NodeJS.Timeout;
7
8
  }
8
9
  export interface TransactionMessage<T> {
9
10
  address: string;
@@ -19,10 +20,10 @@ export declare type SubscriptionId = string;
19
20
  export declare class Client<T> {
20
21
  private readonly url;
21
22
  private readonly connections;
23
+ private readonly pingInterval;
22
24
  private txs;
23
25
  constructor(url: string);
24
26
  private heartbeat;
25
- private onOpen;
26
27
  /**
27
28
  * Subscribe to transaction history and updates for newly confirmed and pending transactions.
28
29
  *
package/dist/websocket.js CHANGED
@@ -12,6 +12,7 @@ const logger = new logger_1.Logger({
12
12
  });
13
13
  class Client {
14
14
  constructor(url) {
15
+ this.pingInterval = 10000;
15
16
  this.txs = {};
16
17
  this.url = url;
17
18
  this.connections = {
@@ -23,11 +24,10 @@ class Client {
23
24
  if (!connection)
24
25
  return;
25
26
  connection.pingTimeout && clearTimeout(connection.pingTimeout);
26
- connection.pingTimeout = setTimeout(() => connection === null || connection === void 0 ? void 0 : connection.ws.close(), 10000 + 5000);
27
- }
28
- onOpen(topic, resolve) {
29
- this.heartbeat(topic);
30
- resolve(true);
27
+ connection.pingTimeout = setTimeout(() => {
28
+ logger.warn({ fn: 'pingTimeout' }, `${topic} heartbeat failed`);
29
+ connection === null || connection === void 0 ? void 0 : connection.ws.close();
30
+ }, this.pingInterval + 5000);
31
31
  }
32
32
  /**
33
33
  * Subscribe to transaction history and updates for newly confirmed and pending transactions.
@@ -59,7 +59,12 @@ class Client {
59
59
  return;
60
60
  }
61
61
  const ws = new isomorphic_ws_1.default(this.url);
62
- this.connections.txs = { ws };
62
+ const interval = setInterval(() => {
63
+ // browsers do not support ping/pong frame, send ping payload instead
64
+ const payload = { subscriptionId: '', method: 'ping' };
65
+ ws.send(JSON.stringify(payload));
66
+ }, this.pingInterval);
67
+ this.connections.txs = { ws, interval };
63
68
  // send connection errors to all subscription onError handlers
64
69
  ws.onerror = (event) => {
65
70
  Object.entries(this.txs).forEach(([id, sub]) => {
@@ -67,16 +72,19 @@ class Client {
67
72
  });
68
73
  };
69
74
  // clear heartbeat timeout on close
70
- ws.onclose = () => { var _a; return ((_a = this.connections.txs) === null || _a === void 0 ? void 0 : _a.pingTimeout) && clearTimeout(this.connections.txs.pingTimeout); };
75
+ ws.onclose = () => {
76
+ var _a, _b;
77
+ ((_a = this.connections.txs) === null || _a === void 0 ? void 0 : _a.pingTimeout) && clearTimeout(this.connections.txs.pingTimeout);
78
+ ((_b = this.connections.txs) === null || _b === void 0 ? void 0 : _b.interval) && clearInterval(this.connections.txs.interval);
79
+ };
71
80
  ws.onmessage = (event) => {
72
81
  var _a, _b;
73
82
  if (!event)
74
83
  return;
75
84
  if (event.type !== 'message')
76
85
  return;
77
- // browsers do not support ping/pong frame, handle message instead
78
- // trigger heartbeat keep alive on ping message and respond with pong
79
- if (event.data === 'ping') {
86
+ if (event.data === 'pong') {
87
+ // trigger heartbeat keep alive on pong response
80
88
  this.heartbeat('txs');
81
89
  return;
82
90
  }
@@ -97,21 +105,26 @@ class Client {
97
105
  }
98
106
  };
99
107
  // wait for the connection to open
100
- const openConnection = new Promise((resolve) => {
108
+ const openConnection = new Promise((resolve, reject) => {
101
109
  ws.onopen = () => {
102
- // start heartbeat
103
- this.onOpen('txs', resolve);
104
- // subscribe to all queued subscriptions
105
- Object.values(this.txs).forEach((tx) => {
106
- if (!tx.data)
107
- return;
108
- const payload = { subscriptionId, method: 'subscribe', data: tx.data };
110
+ this.heartbeat('txs');
111
+ try {
112
+ // subscribe to all queued subscriptions
113
+ Object.values(this.txs).forEach((tx) => {
114
+ if (!tx.data)
115
+ return;
116
+ const payload = { subscriptionId, method: 'subscribe', data: tx.data };
117
+ ws.send(JSON.stringify(payload));
118
+ delete this.txs[subscriptionId].data;
119
+ });
120
+ // subscribe to initial subscription
121
+ const payload = { subscriptionId, method: 'subscribe', data };
109
122
  ws.send(JSON.stringify(payload));
110
- delete this.txs[subscriptionId].data;
111
- });
112
- // subscribe to initial subscription
113
- const payload = { subscriptionId, method: 'subscribe', data };
114
- ws.send(JSON.stringify(payload));
123
+ resolve(true);
124
+ }
125
+ catch (err) {
126
+ reject(err);
127
+ }
115
128
  };
116
129
  });
117
130
  const connectionTimeout = new Promise((_, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/unchained-client",
3
- "version": "8.5.0",
3
+ "version": "9.0.0-alpha.2",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "source": "src/index.ts",
@@ -9,7 +9,7 @@
9
9
  "dist"
10
10
  ],
11
11
  "scripts": {
12
- "build": "yarn build:prod",
12
+ "build": "yarn build:dev",
13
13
  "build:dev": "yarn clean && yarn generate:dev && tsc -p tsconfig.build.json",
14
14
  "build:prod": "yarn clean && yarn generate:prod && tsc -p tsconfig.build.json",
15
15
  "build:local": "yarn clean && yarn generate:local && tsc -p tsconfig.build.json",
@@ -32,14 +32,14 @@
32
32
  "peerDependencies": {
33
33
  "@shapeshiftoss/caip": "^5.2.1",
34
34
  "@shapeshiftoss/logger": "^1.1.2",
35
- "@shapeshiftoss/types": "^4.3.1"
35
+ "@shapeshiftoss/types": "4.3.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@openapitools/openapi-generator-cli": "^2.5.1",
39
39
  "@shapeshiftoss/caip": "^5.2.1",
40
40
  "@shapeshiftoss/common-api": "^6.11.0",
41
41
  "@shapeshiftoss/logger": "^1.1.2",
42
- "@shapeshiftoss/types": "^4.3.1",
42
+ "@shapeshiftoss/types": "4.3.1",
43
43
  "@types/ws": "^8.2.1"
44
44
  }
45
45
  }
@@ -1,3 +0,0 @@
1
- import { JsonFragment } from '@ethersproject/abi/lib/fragments';
2
- declare const multiSig: Array<JsonFragment>;
3
- export default multiSig;