@shapeshiftoss/unchained-client 3.5.0 → 4.1.0
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/dist/bitcoin/index.d.ts +3 -0
- package/dist/bitcoin/index.d.ts.map +1 -0
- package/dist/{bitcoin.js → bitcoin/index.js} +3 -4
- package/dist/bitcoin/index.js.map +1 -0
- package/dist/bitcoin/websocket.d.ts +61 -0
- package/dist/bitcoin/websocket.d.ts.map +1 -0
- package/dist/bitcoin/websocket.js +175 -0
- package/dist/bitcoin/websocket.js.map +1 -0
- package/dist/ethereum/index.d.ts +3 -0
- package/dist/ethereum/index.d.ts.map +1 -0
- package/dist/{ethereum.js → ethereum/index.js} +3 -4
- package/dist/ethereum/index.js.map +1 -0
- package/dist/ethereum/websocket.d.ts +61 -0
- package/dist/ethereum/websocket.d.ts.map +1 -0
- package/dist/ethereum/websocket.js +175 -0
- package/dist/ethereum/websocket.js.map +1 -0
- package/dist/generated/bitcoin/api.d.ts +39 -1
- package/dist/generated/bitcoin/api.d.ts.map +1 -1
- package/dist/generated/bitcoin/api.js +53 -1
- package/dist/generated/bitcoin/api.js.map +1 -1
- package/dist/generated/bitcoin/base.d.ts +1 -1
- package/dist/generated/bitcoin/base.js +1 -1
- package/dist/generated/bitcoin/common.d.ts +1 -1
- package/dist/generated/bitcoin/common.js +1 -1
- package/dist/generated/bitcoin/configuration.d.ts +1 -1
- package/dist/generated/bitcoin/configuration.js +1 -1
- package/dist/generated/bitcoin/index.d.ts +1 -1
- package/dist/generated/bitcoin/index.js +1 -1
- package/dist/generated/ethereum/api.d.ts +39 -1
- package/dist/generated/ethereum/api.d.ts.map +1 -1
- package/dist/generated/ethereum/api.js +53 -1
- package/dist/generated/ethereum/api.js.map +1 -1
- package/dist/generated/ethereum/base.d.ts +1 -1
- package/dist/generated/ethereum/base.js +1 -1
- package/dist/generated/ethereum/common.d.ts +1 -1
- package/dist/generated/ethereum/common.js +1 -1
- package/dist/generated/ethereum/configuration.d.ts +1 -1
- package/dist/generated/ethereum/configuration.js +1 -1
- package/dist/generated/ethereum/index.d.ts +1 -1
- package/dist/generated/ethereum/index.js +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +131 -317
- package/package.json +9 -6
- package/dist/bitcoin.d.ts +0 -3
- package/dist/bitcoin.d.ts.map +0 -1
- package/dist/bitcoin.js.map +0 -1
- package/dist/ethereum.d.ts +0 -3
- package/dist/ethereum.d.ts.map +0 -1
- package/dist/ethereum.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bitcoin/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,sBAAsB,CAAA;AAC3C,OAAO,KAAK,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -20,7 +20,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.ws = exports.api = void 0;
|
|
23
|
-
exports.api = __importStar(require("
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=bitcoin.js.map
|
|
23
|
+
exports.api = __importStar(require("../generated/bitcoin"));
|
|
24
|
+
exports.ws = __importStar(require("./websocket"));
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bitcoin/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,4DAA2C;AAC3C,kDAAiC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import WebSocket from 'isomorphic-ws';
|
|
3
|
+
import type { ErrorResponse, Topics, TxsTopicData } from '@shapeshiftoss/common-api';
|
|
4
|
+
import type { SequencedTx } from '@shapeshiftoss/unchained-tx-parser';
|
|
5
|
+
export interface Connection {
|
|
6
|
+
ws: WebSocket;
|
|
7
|
+
pingTimeout?: NodeJS.Timeout;
|
|
8
|
+
}
|
|
9
|
+
export interface TransactionMessage {
|
|
10
|
+
subscriptionId: string;
|
|
11
|
+
data: SequencedTx;
|
|
12
|
+
}
|
|
13
|
+
export interface TxsParams {
|
|
14
|
+
data: TxsTopicData | undefined;
|
|
15
|
+
onMessage: (message: SequencedTx) => void;
|
|
16
|
+
onError?: (err: ErrorResponse) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class Client {
|
|
19
|
+
private readonly url;
|
|
20
|
+
private readonly connections;
|
|
21
|
+
private txs;
|
|
22
|
+
constructor(url: string);
|
|
23
|
+
private heartbeat;
|
|
24
|
+
private onOpen;
|
|
25
|
+
/**
|
|
26
|
+
* Subscribe to transaction history and updates for newly confirmed and pending transactions.
|
|
27
|
+
*
|
|
28
|
+
* - Subsequent calls to `subscribeTxs` for the same `subscriptionId` will add additional addresses to be watched.
|
|
29
|
+
*
|
|
30
|
+
* @param subscriptionId unique id for grouping of addresses
|
|
31
|
+
* @param data details for subscribe
|
|
32
|
+
* @param data.topic specifies which topic to subscribe to
|
|
33
|
+
* @param data.addresses list of addresses to subscribe to
|
|
34
|
+
* @param onMessage handler for all transaction messages associated with `subscriptionId`
|
|
35
|
+
* @param [onError] optional handler for any error messages associated with `subscriptionId`
|
|
36
|
+
*/
|
|
37
|
+
subscribeTxs(subscriptionId: string, data: TxsTopicData, onMessage: (message: SequencedTx) => void, onError?: (err: ErrorResponse) => void): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Unsubscribe from transaction history and updates for newly confirmed and pending transactions.
|
|
40
|
+
*
|
|
41
|
+
* - If `subscriptionId` is provided, any provided addresses will be unsubscribed from.
|
|
42
|
+
* If no addresses are provided, the subscription will be unsubscribed from.
|
|
43
|
+
*
|
|
44
|
+
* - If `subscriptionId` is not provided, all subscriptions will be unsubscribed from.
|
|
45
|
+
*
|
|
46
|
+
* @param [subscriptionId] unique identifier to unsubscribe from
|
|
47
|
+
* @param [data] details for unsubscribe
|
|
48
|
+
* @param data.topic specifies which topic to unsubscribe from
|
|
49
|
+
* @param data.addresses list of addresses to unsubscribe from
|
|
50
|
+
*/
|
|
51
|
+
unsubscribeTxs(subscriptionId?: string, data?: TxsTopicData): void;
|
|
52
|
+
/**
|
|
53
|
+
* Close and unsubscribe from any subscriptions
|
|
54
|
+
*
|
|
55
|
+
* - If no topic is provided, all supported topics will be closed and unsubscribed from
|
|
56
|
+
*
|
|
57
|
+
* @param [topic] specifies which topic to close and unsubscribe from
|
|
58
|
+
*/
|
|
59
|
+
close(topic?: Topics): void;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/bitcoin/websocket.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,eAAe,CAAA;AACrC,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACpG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AAErE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,SAAS,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAC,OAAO,CAAA;CAC7B;AAED,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,YAAY,GAAG,SAAS,CAAA;IAC9B,SAAS,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAA;IACzC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI,CAAA;CACvC;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwC;IAEpE,OAAO,CAAC,GAAG,CAAgC;gBAE/B,GAAG,EAAE,MAAM;IAQvB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,MAAM;IAKd;;;;;;;;;;;OAWG;IACG,YAAY,CAChB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,EACzC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI,GACrC,OAAO,CAAC,IAAI,CAAC;IAgFhB;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI;IAalE;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;CAoB5B"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Client = void 0;
|
|
16
|
+
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
17
|
+
class Client {
|
|
18
|
+
constructor(url) {
|
|
19
|
+
this.txs = {};
|
|
20
|
+
this.url = url;
|
|
21
|
+
this.connections = {
|
|
22
|
+
txs: undefined,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
heartbeat(topic) {
|
|
26
|
+
const connection = this.connections[topic];
|
|
27
|
+
if (!connection)
|
|
28
|
+
return;
|
|
29
|
+
connection.pingTimeout && clearTimeout(connection.pingTimeout);
|
|
30
|
+
connection.pingTimeout = setTimeout(() => connection === null || connection === void 0 ? void 0 : connection.ws.close(), 10000 + 5000);
|
|
31
|
+
}
|
|
32
|
+
onOpen(topic, resolve) {
|
|
33
|
+
this.heartbeat(topic);
|
|
34
|
+
resolve(true);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to transaction history and updates for newly confirmed and pending transactions.
|
|
38
|
+
*
|
|
39
|
+
* - Subsequent calls to `subscribeTxs` for the same `subscriptionId` will add additional addresses to be watched.
|
|
40
|
+
*
|
|
41
|
+
* @param subscriptionId unique id for grouping of addresses
|
|
42
|
+
* @param data details for subscribe
|
|
43
|
+
* @param data.topic specifies which topic to subscribe to
|
|
44
|
+
* @param data.addresses list of addresses to subscribe to
|
|
45
|
+
* @param onMessage handler for all transaction messages associated with `subscriptionId`
|
|
46
|
+
* @param [onError] optional handler for any error messages associated with `subscriptionId`
|
|
47
|
+
*/
|
|
48
|
+
subscribeTxs(subscriptionId, data, onMessage, onError) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
// keep track of the onMessage and onError handlers associated with each subscriptionId
|
|
51
|
+
this.txs[subscriptionId] = { onMessage, onError, data: undefined };
|
|
52
|
+
if (this.connections.txs) {
|
|
53
|
+
if (this.connections.txs.ws.readyState === 1) {
|
|
54
|
+
// subscribe if connection exists and is ready
|
|
55
|
+
this.connections.txs.ws.send(JSON.stringify({ subscriptionId, method: 'subscribe', data }));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// queue up unique addresses for subscriptions if connection exists, but is not ready yet
|
|
59
|
+
const txsData = this.txs[subscriptionId].data;
|
|
60
|
+
this.txs[subscriptionId].data = txsData
|
|
61
|
+
? Object.assign(Object.assign({}, txsData), { addresses: [...new Set(...txsData.addresses, ...data.addresses)] }) : data;
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const ws = new isomorphic_ws_1.default(this.url);
|
|
66
|
+
this.connections.txs = { ws };
|
|
67
|
+
// send connection errors to all subscription onError handlers
|
|
68
|
+
ws.onerror = (event) => {
|
|
69
|
+
Object.entries(this.txs).forEach(([subscriptionId, { onError }]) => {
|
|
70
|
+
onError && onError({ subscriptionId, type: 'error', message: event.message });
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
// clear heartbeat timeout on close
|
|
74
|
+
ws.onclose = () => { var _a; return ((_a = this.connections.txs) === null || _a === void 0 ? void 0 : _a.pingTimeout) && clearTimeout(this.connections.txs.pingTimeout); };
|
|
75
|
+
ws.onmessage = (event) => {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
if (!event)
|
|
78
|
+
return;
|
|
79
|
+
// TODO: check event.type and handle non desired messages separately (noop)
|
|
80
|
+
// trigger heartbeat keep alive on ping event
|
|
81
|
+
if (event.data === 'ping') {
|
|
82
|
+
this.heartbeat('txs');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const message = JSON.parse(event.data.toString());
|
|
87
|
+
// narrow type to ErrorResponse if key `type` exists and forward to correct onError handler
|
|
88
|
+
if ('type' in message) {
|
|
89
|
+
const onErrorHandler = (_a = this.txs[message.subscriptionId]) === null || _a === void 0 ? void 0 : _a.onError;
|
|
90
|
+
onErrorHandler && onErrorHandler(message);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// forward the transaction message to the correct onMessage handler
|
|
94
|
+
const onMessageHandler = (_b = this.txs[message.subscriptionId]) === null || _b === void 0 ? void 0 : _b.onMessage;
|
|
95
|
+
onMessageHandler && onMessageHandler(message.data);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
console.log(`failed to handle onmessage event: ${JSON.stringify(event)}: ${err}`);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// wait for the connection to open
|
|
102
|
+
yield new Promise((resolve) => {
|
|
103
|
+
ws.onopen = () => {
|
|
104
|
+
// start heartbeat
|
|
105
|
+
this.onOpen('txs', resolve);
|
|
106
|
+
// subscribe to all queued subscriptions
|
|
107
|
+
Object.values(this.txs).forEach(({ data }) => {
|
|
108
|
+
if (!data)
|
|
109
|
+
return;
|
|
110
|
+
const payload = { subscriptionId, method: 'subscribe', data };
|
|
111
|
+
ws.send(JSON.stringify(payload));
|
|
112
|
+
delete this.txs[subscriptionId].data;
|
|
113
|
+
});
|
|
114
|
+
// subscribe to initial subscription
|
|
115
|
+
const payload = { subscriptionId, method: 'subscribe', data };
|
|
116
|
+
ws.send(JSON.stringify(payload));
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Unsubscribe from transaction history and updates for newly confirmed and pending transactions.
|
|
123
|
+
*
|
|
124
|
+
* - If `subscriptionId` is provided, any provided addresses will be unsubscribed from.
|
|
125
|
+
* If no addresses are provided, the subscription will be unsubscribed from.
|
|
126
|
+
*
|
|
127
|
+
* - If `subscriptionId` is not provided, all subscriptions will be unsubscribed from.
|
|
128
|
+
*
|
|
129
|
+
* @param [subscriptionId] unique identifier to unsubscribe from
|
|
130
|
+
* @param [data] details for unsubscribe
|
|
131
|
+
* @param data.topic specifies which topic to unsubscribe from
|
|
132
|
+
* @param data.addresses list of addresses to unsubscribe from
|
|
133
|
+
*/
|
|
134
|
+
unsubscribeTxs(subscriptionId, data) {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
if (!subscriptionId)
|
|
137
|
+
this.txs = {};
|
|
138
|
+
if (subscriptionId && !(data === null || data === void 0 ? void 0 : data.addresses.length))
|
|
139
|
+
delete this.txs[subscriptionId];
|
|
140
|
+
const payload = {
|
|
141
|
+
subscriptionId: subscriptionId !== null && subscriptionId !== void 0 ? subscriptionId : '',
|
|
142
|
+
method: 'unsubscribe',
|
|
143
|
+
data: { topic: 'txs', addresses: (_a = data === null || data === void 0 ? void 0 : data.addresses) !== null && _a !== void 0 ? _a : [] },
|
|
144
|
+
};
|
|
145
|
+
(_b = this.connections.txs) === null || _b === void 0 ? void 0 : _b.ws.send(JSON.stringify(payload));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Close and unsubscribe from any subscriptions
|
|
149
|
+
*
|
|
150
|
+
* - If no topic is provided, all supported topics will be closed and unsubscribed from
|
|
151
|
+
*
|
|
152
|
+
* @param [topic] specifies which topic to close and unsubscribe from
|
|
153
|
+
*/
|
|
154
|
+
close(topic) {
|
|
155
|
+
const closeTxs = () => {
|
|
156
|
+
var _a;
|
|
157
|
+
this.unsubscribeTxs();
|
|
158
|
+
(_a = this.connections.txs) === null || _a === void 0 ? void 0 : _a.ws.close();
|
|
159
|
+
};
|
|
160
|
+
// close all connections if no topic is provided
|
|
161
|
+
if (!topic) {
|
|
162
|
+
closeTxs();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
switch (topic) {
|
|
166
|
+
case 'txs':
|
|
167
|
+
closeTxs();
|
|
168
|
+
break;
|
|
169
|
+
default:
|
|
170
|
+
console.log(`topic: ${topic} not supported`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.Client = Client;
|
|
175
|
+
//# sourceMappingURL=websocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../src/bitcoin/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kEAAqC;AAoBrC,MAAa,MA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EAAE,CAAA;QAClC,CAAC,CAAA;QAED,gDAAgD;QAChD,IAAI,CAAC,KAAK,EAAE;YACV,QAAQ,EAAE,CAAA;YACV,OAAM;SACP;QAED,QAAQ,KAAK,EAAE;YACb,KAAK,KAAK;gBACR,QAAQ,EAAE,CAAA;gBACV,MAAK;YACP;gBACE,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,gBAAgB,CAAC,CAAA;SAC/C;IACH,CAAC;CACF;AAjLD,wBAiLC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ethereum/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,uBAAuB,CAAA;AAC5C,OAAO,KAAK,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -20,7 +20,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.ws = exports.api = void 0;
|
|
23
|
-
exports.api = __importStar(require("
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//# sourceMappingURL=ethereum.js.map
|
|
23
|
+
exports.api = __importStar(require("../generated/ethereum"));
|
|
24
|
+
exports.ws = __importStar(require("./websocket"));
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ethereum/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6DAA4C;AAC5C,kDAAiC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import WebSocket from 'isomorphic-ws';
|
|
3
|
+
import type { ErrorResponse, Topics, TxsTopicData } from '@shapeshiftoss/common-api';
|
|
4
|
+
import type { SequencedTx } from '@shapeshiftoss/unchained-tx-parser';
|
|
5
|
+
export interface Connection {
|
|
6
|
+
ws: WebSocket;
|
|
7
|
+
pingTimeout?: NodeJS.Timeout;
|
|
8
|
+
}
|
|
9
|
+
export interface TransactionMessage {
|
|
10
|
+
subscriptionId: string;
|
|
11
|
+
data: SequencedTx;
|
|
12
|
+
}
|
|
13
|
+
export interface TxsParams {
|
|
14
|
+
data: TxsTopicData | undefined;
|
|
15
|
+
onMessage: (message: SequencedTx) => void;
|
|
16
|
+
onError?: (err: ErrorResponse) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class Client {
|
|
19
|
+
private readonly url;
|
|
20
|
+
private readonly connections;
|
|
21
|
+
private txs;
|
|
22
|
+
constructor(url: string);
|
|
23
|
+
private heartbeat;
|
|
24
|
+
private onOpen;
|
|
25
|
+
/**
|
|
26
|
+
* Subscribe to transaction history and updates for newly confirmed and pending transactions.
|
|
27
|
+
*
|
|
28
|
+
* - Subsequent calls to `subscribeTxs` for the same `subscriptionId` will add additional addresses to be watched.
|
|
29
|
+
*
|
|
30
|
+
* @param subscriptionId unique id for grouping of addresses
|
|
31
|
+
* @param data details for subscribe
|
|
32
|
+
* @param data.topic specifies which topic to subscribe to
|
|
33
|
+
* @param data.addresses list of addresses to subscribe to
|
|
34
|
+
* @param onMessage handler for all transaction messages associated with `subscriptionId`
|
|
35
|
+
* @param [onError] optional handler for any error messages associated with `subscriptionId`
|
|
36
|
+
*/
|
|
37
|
+
subscribeTxs(subscriptionId: string, data: TxsTopicData, onMessage: (message: SequencedTx) => void, onError?: (err: ErrorResponse) => void): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Unsubscribe from transaction history and updates for newly confirmed and pending transactions.
|
|
40
|
+
*
|
|
41
|
+
* - If `subscriptionId` is provided, any provided addresses will be unsubscribed from.
|
|
42
|
+
* If no addresses are provided, the subscription will be unsubscribed from.
|
|
43
|
+
*
|
|
44
|
+
* - If `subscriptionId` is not provided, all subscriptions will be unsubscribed from.
|
|
45
|
+
*
|
|
46
|
+
* @param [subscriptionId] unique identifier to unsubscribe from
|
|
47
|
+
* @param [data] details for unsubscribe
|
|
48
|
+
* @param data.topic specifies which topic to unsubscribe from
|
|
49
|
+
* @param data.addresses list of addresses to unsubscribe from
|
|
50
|
+
*/
|
|
51
|
+
unsubscribeTxs(subscriptionId?: string, data?: TxsTopicData): void;
|
|
52
|
+
/**
|
|
53
|
+
* Close and unsubscribe from any subscriptions
|
|
54
|
+
*
|
|
55
|
+
* - If no topic is provided, all supported topics will be closed and unsubscribed from
|
|
56
|
+
*
|
|
57
|
+
* @param [topic] specifies which topic to close and unsubscribe from
|
|
58
|
+
*/
|
|
59
|
+
close(topic?: Topics): void;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/ethereum/websocket.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,eAAe,CAAA;AACrC,OAAO,KAAK,EAAE,aAAa,EAAkB,MAAM,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACpG,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AAErE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,SAAS,CAAA;IACb,WAAW,CAAC,EAAE,MAAM,CAAC,OAAO,CAAA;CAC7B;AAED,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,YAAY,GAAG,SAAS,CAAA;IAC9B,SAAS,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAA;IACzC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI,CAAA;CACvC;AAED,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAwC;IAEpE,OAAO,CAAC,GAAG,CAAgC;gBAE/B,GAAG,EAAE,MAAM;IAQvB,OAAO,CAAC,SAAS;IAQjB,OAAO,CAAC,MAAM;IAKd;;;;;;;;;;;OAWG;IACG,YAAY,CAChB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,YAAY,EAClB,SAAS,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,EACzC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,IAAI,GACrC,OAAO,CAAC,IAAI,CAAC;IAiFhB;;;;;;;;;;;;OAYG;IACH,cAAc,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,IAAI;IAalE;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;CAoB5B"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Client = void 0;
|
|
16
|
+
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
17
|
+
class Client {
|
|
18
|
+
constructor(url) {
|
|
19
|
+
this.txs = {};
|
|
20
|
+
this.url = url;
|
|
21
|
+
this.connections = {
|
|
22
|
+
txs: undefined,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
heartbeat(topic) {
|
|
26
|
+
const connection = this.connections[topic];
|
|
27
|
+
if (!connection)
|
|
28
|
+
return;
|
|
29
|
+
connection.pingTimeout && clearTimeout(connection.pingTimeout);
|
|
30
|
+
connection.pingTimeout = setTimeout(() => connection === null || connection === void 0 ? void 0 : connection.ws.close(), 10000 + 5000);
|
|
31
|
+
}
|
|
32
|
+
onOpen(topic, resolve) {
|
|
33
|
+
this.heartbeat(topic);
|
|
34
|
+
resolve(true);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Subscribe to transaction history and updates for newly confirmed and pending transactions.
|
|
38
|
+
*
|
|
39
|
+
* - Subsequent calls to `subscribeTxs` for the same `subscriptionId` will add additional addresses to be watched.
|
|
40
|
+
*
|
|
41
|
+
* @param subscriptionId unique id for grouping of addresses
|
|
42
|
+
* @param data details for subscribe
|
|
43
|
+
* @param data.topic specifies which topic to subscribe to
|
|
44
|
+
* @param data.addresses list of addresses to subscribe to
|
|
45
|
+
* @param onMessage handler for all transaction messages associated with `subscriptionId`
|
|
46
|
+
* @param [onError] optional handler for any error messages associated with `subscriptionId`
|
|
47
|
+
*/
|
|
48
|
+
subscribeTxs(subscriptionId, data, onMessage, onError) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
// keep track of the onMessage and onError handlers associated with each subscriptionId
|
|
51
|
+
this.txs[subscriptionId] = { onMessage, onError, data: undefined };
|
|
52
|
+
if (this.connections.txs) {
|
|
53
|
+
if (this.connections.txs.ws.readyState === 1) {
|
|
54
|
+
// subscribe if connection exists and is ready
|
|
55
|
+
this.connections.txs.ws.send(JSON.stringify({ subscriptionId, method: 'subscribe', data }));
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// queue up unique addresses for subscriptions if connection exists, but is not ready yet
|
|
59
|
+
const txsData = this.txs[subscriptionId].data;
|
|
60
|
+
this.txs[subscriptionId].data = txsData
|
|
61
|
+
? Object.assign(Object.assign({}, txsData), { addresses: [...new Set(...txsData.addresses, ...data.addresses)] }) : data;
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const ws = new isomorphic_ws_1.default(this.url);
|
|
66
|
+
this.connections.txs = { ws };
|
|
67
|
+
// send connection errors to all subscription onError handlers
|
|
68
|
+
ws.onerror = (event) => {
|
|
69
|
+
Object.entries(this.txs).forEach(([subscriptionId, { onError }]) => {
|
|
70
|
+
onError && onError({ subscriptionId, type: 'error', message: event.message });
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
// clear heartbeat timeout on close
|
|
74
|
+
ws.onclose = () => { var _a; return ((_a = this.connections.txs) === null || _a === void 0 ? void 0 : _a.pingTimeout) && clearTimeout(this.connections.txs.pingTimeout); };
|
|
75
|
+
ws.onmessage = (event) => {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
if (!event)
|
|
78
|
+
return;
|
|
79
|
+
// TODO: check event.type and handle non desired messages separately (noop)
|
|
80
|
+
// trigger heartbeat keep alive on ping event
|
|
81
|
+
if (event.data === 'ping') {
|
|
82
|
+
this.heartbeat('txs');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const message = JSON.parse(event.data.toString());
|
|
87
|
+
// narrow type to ErrorResponse if key `type` exists and forward to correct onError handler
|
|
88
|
+
if ('type' in message) {
|
|
89
|
+
const onErrorHandler = (_a = this.txs[message.subscriptionId]) === null || _a === void 0 ? void 0 : _a.onError;
|
|
90
|
+
onErrorHandler && onErrorHandler(message);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
// forward the transaction message to the correct onMessage handler
|
|
94
|
+
const onMessageHandler = (_b = this.txs[message.subscriptionId]) === null || _b === void 0 ? void 0 : _b.onMessage;
|
|
95
|
+
onMessageHandler && onMessageHandler(message.data);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
console.log(`failed to handle onmessage event: ${JSON.stringify(event)}: ${err}`);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
// wait for the connection to open
|
|
102
|
+
yield new Promise((resolve) => {
|
|
103
|
+
ws.onopen = () => {
|
|
104
|
+
// start heartbeat
|
|
105
|
+
this.onOpen('txs', resolve);
|
|
106
|
+
// subscribe to all queued subscriptions
|
|
107
|
+
Object.values(this.txs).forEach(({ data }) => {
|
|
108
|
+
if (!data)
|
|
109
|
+
return;
|
|
110
|
+
const payload = { subscriptionId, method: 'subscribe', data };
|
|
111
|
+
ws.send(JSON.stringify(payload));
|
|
112
|
+
delete this.txs[subscriptionId].data;
|
|
113
|
+
});
|
|
114
|
+
// subscribe to initial subscription
|
|
115
|
+
const payload = { subscriptionId, method: 'subscribe', data };
|
|
116
|
+
ws.send(JSON.stringify(payload));
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Unsubscribe from transaction history and updates for newly confirmed and pending transactions.
|
|
123
|
+
*
|
|
124
|
+
* - If `subscriptionId` is provided, any provided addresses will be unsubscribed from.
|
|
125
|
+
* If no addresses are provided, the subscription will be unsubscribed from.
|
|
126
|
+
*
|
|
127
|
+
* - If `subscriptionId` is not provided, all subscriptions will be unsubscribed from.
|
|
128
|
+
*
|
|
129
|
+
* @param [subscriptionId] unique identifier to unsubscribe from
|
|
130
|
+
* @param [data] details for unsubscribe
|
|
131
|
+
* @param data.topic specifies which topic to unsubscribe from
|
|
132
|
+
* @param data.addresses list of addresses to unsubscribe from
|
|
133
|
+
*/
|
|
134
|
+
unsubscribeTxs(subscriptionId, data) {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
if (!subscriptionId)
|
|
137
|
+
this.txs = {};
|
|
138
|
+
if (subscriptionId && !(data === null || data === void 0 ? void 0 : data.addresses.length))
|
|
139
|
+
delete this.txs[subscriptionId];
|
|
140
|
+
const payload = {
|
|
141
|
+
subscriptionId: subscriptionId !== null && subscriptionId !== void 0 ? subscriptionId : '',
|
|
142
|
+
method: 'unsubscribe',
|
|
143
|
+
data: { topic: 'txs', addresses: (_a = data === null || data === void 0 ? void 0 : data.addresses) !== null && _a !== void 0 ? _a : [] },
|
|
144
|
+
};
|
|
145
|
+
(_b = this.connections.txs) === null || _b === void 0 ? void 0 : _b.ws.send(JSON.stringify(payload));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Close and unsubscribe from any subscriptions
|
|
149
|
+
*
|
|
150
|
+
* - If no topic is provided, all supported topics will be closed and unsubscribed from
|
|
151
|
+
*
|
|
152
|
+
* @param [topic] specifies which topic to close and unsubscribe from
|
|
153
|
+
*/
|
|
154
|
+
close(topic) {
|
|
155
|
+
const closeTxs = () => {
|
|
156
|
+
var _a;
|
|
157
|
+
this.unsubscribeTxs();
|
|
158
|
+
(_a = this.connections.txs) === null || _a === void 0 ? void 0 : _a.ws.close();
|
|
159
|
+
};
|
|
160
|
+
// close all connections if no topic is provided
|
|
161
|
+
if (!topic) {
|
|
162
|
+
closeTxs();
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
switch (topic) {
|
|
166
|
+
case 'txs':
|
|
167
|
+
closeTxs();
|
|
168
|
+
break;
|
|
169
|
+
default:
|
|
170
|
+
console.log(`topic: ${topic} not supported`);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.Client = Client;
|
|
175
|
+
//# sourceMappingURL=websocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../src/ethereum/websocket.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kEAAqC;AAoBrC,MAAa,MAAM;IAMjB,YAAY,GAAW;QAFf,QAAG,GAA8B,EAAE,CAAA;QAGzC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QAEd,IA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M;SACP;QAED,QAAQ,KAAK,EAAE;YACb,KAAK,KAAK;gBACR,QAAQ,EAAE,CAAA;gBACV,MAAK;YACP;gBACE,OAAO,CAAC,GAAG,CAAC,UAAU,KAAK,gBAAgB,CAAC,CAAA;SAC/C;IACH,CAAC;CACF;AAlLD,wBAkLC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @shapeshiftoss/bitcoin-api
|
|
3
3
|
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
|
4
4
|
*
|
|
5
|
-
* The version of the OpenAPI document:
|
|
5
|
+
* The version of the OpenAPI document: 4.0.0
|
|
6
6
|
*
|
|
7
7
|
*
|
|
8
8
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
@@ -340,6 +340,19 @@ export interface BitcoinTxSpecificVout {
|
|
|
340
340
|
*/
|
|
341
341
|
value?: string | number;
|
|
342
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Contains info about the running coinstack
|
|
345
|
+
* @export
|
|
346
|
+
* @interface Info
|
|
347
|
+
*/
|
|
348
|
+
export interface Info {
|
|
349
|
+
/**
|
|
350
|
+
*
|
|
351
|
+
* @type {string}
|
|
352
|
+
* @memberof Info
|
|
353
|
+
*/
|
|
354
|
+
network: string;
|
|
355
|
+
}
|
|
343
356
|
/**
|
|
344
357
|
* Contains info about a 500 Internal Server Error response
|
|
345
358
|
* @export
|
|
@@ -565,6 +578,12 @@ export declare const V1ApiAxiosParamCreator: (configuration?: Configuration | un
|
|
|
565
578
|
* @throws {RequiredError}
|
|
566
579
|
*/
|
|
567
580
|
getAccount: (pubkey: string, options?: any) => Promise<RequestArgs>;
|
|
581
|
+
/**
|
|
582
|
+
* Get information about the running coinstack
|
|
583
|
+
* @param {*} [options] Override http request option.
|
|
584
|
+
* @throws {RequiredError}
|
|
585
|
+
*/
|
|
586
|
+
getInfo: (options?: any) => Promise<RequestArgs>;
|
|
568
587
|
/**
|
|
569
588
|
* Gets current network fee estimates for \'fast\', \'average\', and \'slow\' tx confirmation times
|
|
570
589
|
* @param {*} [options] Override http request option.
|
|
@@ -615,6 +634,12 @@ export declare const V1ApiFp: (configuration?: Configuration | undefined) => {
|
|
|
615
634
|
* @throws {RequiredError}
|
|
616
635
|
*/
|
|
617
636
|
getAccount(pubkey: string, options?: any): Promise<(axios?: AxiosInstance | undefined, basePath?: string | undefined) => AxiosPromise<BitcoinAccount>>;
|
|
637
|
+
/**
|
|
638
|
+
* Get information about the running coinstack
|
|
639
|
+
* @param {*} [options] Override http request option.
|
|
640
|
+
* @throws {RequiredError}
|
|
641
|
+
*/
|
|
642
|
+
getInfo(options?: any): Promise<(axios?: AxiosInstance | undefined, basePath?: string | undefined) => AxiosPromise<Info>>;
|
|
618
643
|
/**
|
|
619
644
|
* Gets current network fee estimates for \'fast\', \'average\', and \'slow\' tx confirmation times
|
|
620
645
|
* @param {*} [options] Override http request option.
|
|
@@ -665,6 +690,12 @@ export declare const V1ApiFactory: (configuration?: Configuration | undefined, b
|
|
|
665
690
|
* @throws {RequiredError}
|
|
666
691
|
*/
|
|
667
692
|
getAccount(pubkey: string, options?: any): AxiosPromise<BitcoinAccount>;
|
|
693
|
+
/**
|
|
694
|
+
* Get information about the running coinstack
|
|
695
|
+
* @param {*} [options] Override http request option.
|
|
696
|
+
* @throws {RequiredError}
|
|
697
|
+
*/
|
|
698
|
+
getInfo(options?: any): AxiosPromise<Info>;
|
|
668
699
|
/**
|
|
669
700
|
* Gets current network fee estimates for \'fast\', \'average\', and \'slow\' tx confirmation times
|
|
670
701
|
* @param {*} [options] Override http request option.
|
|
@@ -801,6 +832,13 @@ export declare class V1Api extends BaseAPI {
|
|
|
801
832
|
* @memberof V1Api
|
|
802
833
|
*/
|
|
803
834
|
getAccount(requestParameters: V1ApiGetAccountRequest, options?: any): Promise<import("axios").AxiosResponse<BitcoinAccount>>;
|
|
835
|
+
/**
|
|
836
|
+
* Get information about the running coinstack
|
|
837
|
+
* @param {*} [options] Override http request option.
|
|
838
|
+
* @throws {RequiredError}
|
|
839
|
+
* @memberof V1Api
|
|
840
|
+
*/
|
|
841
|
+
getInfo(options?: any): Promise<import("axios").AxiosResponse<Info>>;
|
|
804
842
|
/**
|
|
805
843
|
* Gets current network fee estimates for \'fast\', \'average\', and \'slow\' tx confirmation times
|
|
806
844
|
* @param {*} [options] Override http request option.
|