@xchainjs/xchain-utxo-providers 0.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.
Files changed (35) hide show
  1. package/README.md +72 -0
  2. package/lib/index.d.ts +1 -0
  3. package/lib/index.js +14 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/providers/blockcypher/blockcypher-api-types.d.ts +96 -0
  6. package/lib/providers/blockcypher/blockcypher-api-types.js +11 -0
  7. package/lib/providers/blockcypher/blockcypher-api-types.js.map +1 -0
  8. package/lib/providers/blockcypher/blockcypher-api.d.ts +69 -0
  9. package/lib/providers/blockcypher/blockcypher-api.js +233 -0
  10. package/lib/providers/blockcypher/blockcypher-api.js.map +1 -0
  11. package/lib/providers/blockcypher/blockcypher-data-provider.d.ts +52 -0
  12. package/lib/providers/blockcypher/blockcypher-data-provider.js +366 -0
  13. package/lib/providers/blockcypher/blockcypher-data-provider.js.map +1 -0
  14. package/lib/providers/haskoin/haskoin-api-types.d.ts +113 -0
  15. package/lib/providers/haskoin/haskoin-api-types.js +14 -0
  16. package/lib/providers/haskoin/haskoin-api-types.js.map +1 -0
  17. package/lib/providers/haskoin/haskoin-api.d.ts +150 -0
  18. package/lib/providers/haskoin/haskoin-api.js +485 -0
  19. package/lib/providers/haskoin/haskoin-api.js.map +1 -0
  20. package/lib/providers/haskoin/haskoin-data-provider.d.ts +37 -0
  21. package/lib/providers/haskoin/haskoin-data-provider.js +269 -0
  22. package/lib/providers/haskoin/haskoin-data-provider.js.map +1 -0
  23. package/lib/providers/index.d.ts +8 -0
  24. package/lib/providers/index.js +34 -0
  25. package/lib/providers/index.js.map +1 -0
  26. package/lib/providers/sochainv3/sochain-api-types.d.ts +101 -0
  27. package/lib/providers/sochainv3/sochain-api-types.js +13 -0
  28. package/lib/providers/sochainv3/sochain-api-types.js.map +1 -0
  29. package/lib/providers/sochainv3/sochain-api.d.ts +113 -0
  30. package/lib/providers/sochainv3/sochain-api.js +354 -0
  31. package/lib/providers/sochainv3/sochain-api.js.map +1 -0
  32. package/lib/providers/sochainv3/sochain-data-provider.d.ts +42 -0
  33. package/lib/providers/sochainv3/sochain-data-provider.js +312 -0
  34. package/lib/providers/sochainv3/sochain-data-provider.js.map +1 -0
  35. package/package.json +45 -0
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # XChainJS API UTXO providers Interface
2
+
3
+ A specification for a generalised interface for api providers, to be used by XChainJS implementations. The providers should not have any functionality to generate a key, instead, the `asgardex-crypto` library should be used to ensure cross-chain compatible keystores are handled. The providers is only ever passed a master BIP39 phrase, from which a temporary key and address is decoded.
4
+
5
+ ## Documentation
6
+
7
+ ### [`xchain providers`](http://docs.xchainjs.org/xchain-xchain-utxo-providers/)
8
+
9
+ [`Overview of xchain-utxo-providers`](http://docs.xchainjs.org/xchain-utxo-providers/overview.html)\
10
+ [`Interface of xchain-utxo-providers`](http://docs.xchainjs.org/xchain-utxo-providers/interface.html)
11
+
12
+ ## Design
13
+
14
+ The UtxoOnlineDataProvider has the following signature:
15
+
16
+ ```typescript
17
+ import { Address, Asset } from '@xchainjs/xchain-util'
18
+
19
+ import { ExplorerProvider } from './explorer-provider'
20
+ import { Balance, Network, Tx, TxHash, TxHistoryParams, TxsPage } from './types'
21
+
22
+ export type Witness = {
23
+ value: number
24
+ script: Buffer
25
+ }
26
+ export type UTXO = {
27
+ hash: string
28
+ index: number
29
+ value: number
30
+ witnessUtxo: Witness
31
+ txHex?: string
32
+ }
33
+ export interface OnlineDataProvider {
34
+ getBalance(address: Address, assets?: Asset[]): Promise<Balance[]>
35
+ getTransactions(params: TxHistoryParams): Promise<TxsPage>
36
+ getTransactionData(txId: string, assetAddress?: Address): Promise<Tx>
37
+ }
38
+ export interface UtxoOnlineDataProvider extends OnlineDataProvider {
39
+ getConfirmedUnspentTxs(address: Address): Promise<UTXO[]>
40
+ getUnspentTxs(address: Address): Promise<UTXO[]>
41
+ broadcastTx(txHex: string): Promise<TxHash>
42
+ }
43
+ ```
44
+
45
+ ## Implementations
46
+
47
+ ### sochain v3
48
+
49
+ ```
50
+ Website: https://sochain.com/api/
51
+ Status: Complete
52
+ FreeTier: No
53
+ Chains supported: BTC,BTC-Testnet,LTC,LTC-Testnet,DOGE,DOGE-Testnet
54
+ ```
55
+
56
+ ### blockcypher
57
+
58
+ ```
59
+ Website: https://www.blockcypher.com/
60
+ Status: Complete
61
+ FreeTier: Yes, rate limited 3 reqs/sec
62
+ Chains supported: BTC,BTC-Testnet,LTC,DOGE
63
+ ```
64
+
65
+ ### haskoin
66
+
67
+ ```
68
+ Website: https://www.haskoin.com/
69
+ Status: Complete
70
+ FreeTier: Yes, rate limit unknown
71
+ Chains supported: BTC,BTC-Testnet,BCH,BCH-Testnet
72
+ ```
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './providers';
package/lib/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./providers"), exports);
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA2B"}
@@ -0,0 +1,96 @@
1
+ import { TxHash } from '@xchainjs/xchain-client';
2
+ export declare enum BlockcypherNetwork {
3
+ BTC = "btc/main",
4
+ BTCTEST = "btc/test3",
5
+ LTC = "ltc/main",
6
+ DOGE = "doge/main"
7
+ }
8
+ export declare type AddressParams = {
9
+ apiKey?: string;
10
+ baseUrl: string;
11
+ network: BlockcypherNetwork;
12
+ address: string;
13
+ page: number;
14
+ };
15
+ export declare type BalanceParams = {
16
+ apiKey?: string;
17
+ baseUrl: string;
18
+ network: BlockcypherNetwork;
19
+ address: string;
20
+ confirmedOnly: boolean;
21
+ assetDecimals: number;
22
+ };
23
+ export declare type TxHashParams = {
24
+ apiKey?: string;
25
+ baseUrl: string;
26
+ network: BlockcypherNetwork;
27
+ hash: TxHash;
28
+ };
29
+ export declare type TxBroadcastParams = {
30
+ apiKey?: string;
31
+ baseUrl: string;
32
+ network: BlockcypherNetwork;
33
+ txHex: string;
34
+ };
35
+ export interface TxInput {
36
+ output_value: string;
37
+ addresses: string[];
38
+ script_type?: string;
39
+ }
40
+ export interface TxOutput {
41
+ value: string;
42
+ addresses: string[];
43
+ script_type?: string;
44
+ script: string;
45
+ }
46
+ export interface Transaction {
47
+ hash: string;
48
+ block_hash: string;
49
+ confirmed: string;
50
+ hex: string;
51
+ inputs: TxInput[];
52
+ outputs: TxOutput[];
53
+ }
54
+ export declare type AddressUTXO = {
55
+ hash: string;
56
+ index: number;
57
+ script: string;
58
+ address: string;
59
+ tx_hex: string;
60
+ value: string;
61
+ block: number;
62
+ };
63
+ export declare type AddressTxDTO = {
64
+ tx_hash: string;
65
+ block_height: number;
66
+ confirmed: string;
67
+ };
68
+ export declare type GetBalanceDTO = {
69
+ balance: string;
70
+ unconfirmed_balance: string;
71
+ final_balance: string;
72
+ n_tx: number;
73
+ unconfirmed_n_tx: number;
74
+ final_n_tx: number;
75
+ };
76
+ export declare type GetTxsDTO = {
77
+ txrefs: AddressTxDTO[];
78
+ };
79
+ export declare type BroadcastDTO = {
80
+ tx: {
81
+ hash: string;
82
+ };
83
+ };
84
+ export declare type UnspentTxsDTO = {
85
+ outputs: AddressUTXO[];
86
+ };
87
+ export declare type BroadcastTransfer = {
88
+ network: string;
89
+ txid: string;
90
+ };
91
+ export declare type TxConfirmedStatus = {
92
+ network: string;
93
+ txid: string;
94
+ confirmations: number;
95
+ is_confirmed: boolean;
96
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BlockcypherNetwork = void 0;
4
+ var BlockcypherNetwork;
5
+ (function (BlockcypherNetwork) {
6
+ BlockcypherNetwork["BTC"] = "btc/main";
7
+ BlockcypherNetwork["BTCTEST"] = "btc/test3";
8
+ BlockcypherNetwork["LTC"] = "ltc/main";
9
+ BlockcypherNetwork["DOGE"] = "doge/main";
10
+ })(BlockcypherNetwork = exports.BlockcypherNetwork || (exports.BlockcypherNetwork = {}));
11
+ //# sourceMappingURL=blockcypher-api-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blockcypher-api-types.js","sourceRoot":"","sources":["../../../src/providers/blockcypher/blockcypher-api-types.ts"],"names":[],"mappings":";;;AAEA,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,sCAAgB,CAAA;IAChB,2CAAqB,CAAA;IACrB,sCAAgB,CAAA;IAChB,wCAAkB,CAAA;AACpB,CAAC,EALW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAK7B"}
@@ -0,0 +1,69 @@
1
+ import { TxHash } from '@xchainjs/xchain-client';
2
+ import { BaseAmount } from '@xchainjs/xchain-util';
3
+ import { BalanceParams, BlockcypherNetwork, GetTxsDTO, Transaction, TxConfirmedStatus, TxHashParams } from './blockcypher-api-types';
4
+ /**
5
+ * Get transaction by hash.
6
+ *
7
+ *
8
+ * @param {string} baseUrl The sochain node url.
9
+ * @param {string} network network id
10
+ * @param {string} hash The transaction hash.
11
+ * @returns {Transactions}
12
+ */
13
+ export declare const getTx: ({ apiKey, baseUrl, network, hash }: TxHashParams) => Promise<Transaction>;
14
+ /**
15
+ * Get transactions
16
+ *
17
+ *
18
+ * @param {string} baseUrl The sochain node url.
19
+ * @param {string} network network id
20
+ * @param {string} hash The transaction hash.
21
+ * @returns {Transactions}
22
+ */
23
+ export declare const getTxs: ({ apiKey, address, baseUrl, network, beforeBlock, limit, unspentOnly, }: {
24
+ apiKey?: string;
25
+ address: string;
26
+ baseUrl: string;
27
+ network: BlockcypherNetwork;
28
+ limit: number;
29
+ beforeBlock?: number;
30
+ unspentOnly: boolean;
31
+ }) => Promise<GetTxsDTO>;
32
+ /**
33
+ * Get address balance.
34
+ *
35
+ *
36
+ * @param {string} baseUrl The sochain node url.
37
+ * @param {string} network Network
38
+ * @param {string} address Address
39
+ * @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
40
+ * @returns {number}
41
+ */
42
+ export declare const getBalance: ({ apiKey, baseUrl, network, address, confirmedOnly, assetDecimals, }: BalanceParams) => Promise<BaseAmount>;
43
+ /**
44
+ * Get Tx Confirmation status
45
+ *
46
+ *
47
+ * @param {string} baseUrl The sochain node url.
48
+ * @param {Network} network
49
+ * @param {string} hash tx id
50
+ * @returns {TxConfirmedStatus}
51
+ */
52
+ export declare const getIsTxConfirmed: ({ apiKey, baseUrl, network, hash, }: TxHashParams) => Promise<TxConfirmedStatus>;
53
+ /**
54
+ * Helper to get `confirmed` status of a tx.
55
+ *
56
+ * It will get it from cache or try to get it from Sochain (if not cached before)
57
+ */
58
+ export declare const getConfirmedTxStatus: ({ apiKey, txHash, baseUrl, network, }: {
59
+ apiKey?: string;
60
+ baseUrl: string;
61
+ txHash: TxHash;
62
+ network: BlockcypherNetwork;
63
+ }) => Promise<boolean>;
64
+ export declare const broadcastTx: ({ apiKey, baseUrl, network, txHex, }: {
65
+ apiKey?: string;
66
+ baseUrl: string;
67
+ txHex: string;
68
+ network: BlockcypherNetwork;
69
+ }) => Promise<TxHash>;
@@ -0,0 +1,233 @@
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 __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.broadcastTx = exports.getConfirmedTxStatus = exports.getIsTxConfirmed = exports.getBalance = exports.getTxs = exports.getTx = void 0;
43
+ var xchain_util_1 = require("@xchainjs/xchain-util");
44
+ var axios_1 = __importDefault(require("axios"));
45
+ /**
46
+ * Get transaction by hash.
47
+ *
48
+ *
49
+ * @param {string} baseUrl The sochain node url.
50
+ * @param {string} network network id
51
+ * @param {string} hash The transaction hash.
52
+ * @returns {Transactions}
53
+ */
54
+ var getTx = function (_a) {
55
+ var apiKey = _a.apiKey, baseUrl = _a.baseUrl, network = _a.network, hash = _a.hash;
56
+ return __awaiter(void 0, void 0, void 0, function () {
57
+ var params, url, response, tx;
58
+ return __generator(this, function (_b) {
59
+ switch (_b.label) {
60
+ case 0:
61
+ params = { includeHex: 'true' };
62
+ if (apiKey)
63
+ params['token'] = apiKey;
64
+ url = baseUrl + "/" + network + "/txs/" + hash;
65
+ return [4 /*yield*/, axios_1.default.get(url, { params: params })];
66
+ case 1:
67
+ response = _b.sent();
68
+ tx = response.data;
69
+ return [2 /*return*/, tx];
70
+ }
71
+ });
72
+ });
73
+ };
74
+ exports.getTx = getTx;
75
+ /**
76
+ * Get transactions
77
+ *
78
+ *
79
+ * @param {string} baseUrl The sochain node url.
80
+ * @param {string} network network id
81
+ * @param {string} hash The transaction hash.
82
+ * @returns {Transactions}
83
+ */
84
+ var getTxs = function (_a) {
85
+ var apiKey = _a.apiKey, address = _a.address, baseUrl = _a.baseUrl, network = _a.network, beforeBlock = _a.beforeBlock, limit = _a.limit, unspentOnly = _a.unspentOnly;
86
+ return __awaiter(void 0, void 0, void 0, function () {
87
+ var params, url, response, txs;
88
+ return __generator(this, function (_b) {
89
+ switch (_b.label) {
90
+ case 0:
91
+ params = { limit: "" + limit, unspentOnly: "" + unspentOnly };
92
+ url = baseUrl + "/" + network + "/addrs/" + address;
93
+ if (apiKey)
94
+ params['token'] = apiKey;
95
+ if (beforeBlock)
96
+ params['before'] = "" + beforeBlock;
97
+ return [4 /*yield*/, axios_1.default.get(url, { params: params })];
98
+ case 1:
99
+ response = _b.sent();
100
+ txs = response.data;
101
+ return [2 /*return*/, txs];
102
+ }
103
+ });
104
+ });
105
+ };
106
+ exports.getTxs = getTxs;
107
+ /**
108
+ * Get address balance.
109
+ *
110
+ *
111
+ * @param {string} baseUrl The sochain node url.
112
+ * @param {string} network Network
113
+ * @param {string} address Address
114
+ * @param {boolean} confirmedOnly Flag whether to get balances of confirmed txs only or for all
115
+ * @returns {number}
116
+ */
117
+ var getBalance = function (_a) {
118
+ var apiKey = _a.apiKey, baseUrl = _a.baseUrl, network = _a.network, address = _a.address, confirmedOnly = _a.confirmedOnly, assetDecimals = _a.assetDecimals;
119
+ return __awaiter(void 0, void 0, void 0, function () {
120
+ var params, url, response, balanceResponse, total, unconfirmed, netAmt, result;
121
+ return __generator(this, function (_b) {
122
+ switch (_b.label) {
123
+ case 0:
124
+ params = {};
125
+ url = baseUrl + "/" + network + "/addrs/" + address + "/balance";
126
+ if (apiKey)
127
+ params['token'] = apiKey;
128
+ return [4 /*yield*/, axios_1.default.get(url, { params: params })];
129
+ case 1:
130
+ response = _b.sent();
131
+ balanceResponse = response.data;
132
+ total = xchain_util_1.assetAmount(balanceResponse.final_balance, assetDecimals);
133
+ unconfirmed = xchain_util_1.assetAmount(balanceResponse.unconfirmed_balance, assetDecimals);
134
+ netAmt = !confirmedOnly ? unconfirmed : total;
135
+ result = xchain_util_1.assetToBase(netAmt);
136
+ return [2 /*return*/, result];
137
+ }
138
+ });
139
+ });
140
+ };
141
+ exports.getBalance = getBalance;
142
+ /**
143
+ * Get Tx Confirmation status
144
+ *
145
+ *
146
+ * @param {string} baseUrl The sochain node url.
147
+ * @param {Network} network
148
+ * @param {string} hash tx id
149
+ * @returns {TxConfirmedStatus}
150
+ */
151
+ var getIsTxConfirmed = function (_a) {
152
+ var apiKey = _a.apiKey, baseUrl = _a.baseUrl, network = _a.network, hash = _a.hash;
153
+ return __awaiter(void 0, void 0, void 0, function () {
154
+ var tx;
155
+ return __generator(this, function (_b) {
156
+ switch (_b.label) {
157
+ case 0: return [4 /*yield*/, exports.getTx({ apiKey: apiKey, baseUrl: baseUrl, network: network, hash: hash })];
158
+ case 1:
159
+ tx = _b.sent();
160
+ return [2 /*return*/, {
161
+ network: network,
162
+ txid: hash,
163
+ confirmations: !!tx.confirmed ? 1 : 0,
164
+ is_confirmed: !!tx.confirmed,
165
+ }];
166
+ }
167
+ });
168
+ });
169
+ };
170
+ exports.getIsTxConfirmed = getIsTxConfirmed;
171
+ /**
172
+ * List of confirmed txs
173
+ *
174
+ * Stores a list of confirmed txs (hashes) in memory to avoid requesting same data
175
+ */
176
+ var confirmedTxs = [];
177
+ /**
178
+ * Helper to get `confirmed` status of a tx.
179
+ *
180
+ * It will get it from cache or try to get it from Sochain (if not cached before)
181
+ */
182
+ var getConfirmedTxStatus = function (_a) {
183
+ var apiKey = _a.apiKey, txHash = _a.txHash, baseUrl = _a.baseUrl, network = _a.network;
184
+ return __awaiter(void 0, void 0, void 0, function () {
185
+ var is_confirmed;
186
+ return __generator(this, function (_b) {
187
+ switch (_b.label) {
188
+ case 0:
189
+ // try to get it from cache
190
+ if (confirmedTxs.includes(txHash))
191
+ return [2 /*return*/, true
192
+ // or get status from Sochain
193
+ ];
194
+ return [4 /*yield*/, exports.getIsTxConfirmed({
195
+ apiKey: apiKey,
196
+ baseUrl: baseUrl,
197
+ network: network,
198
+ hash: txHash,
199
+ })
200
+ // cache status
201
+ ];
202
+ case 1:
203
+ is_confirmed = (_b.sent()).is_confirmed;
204
+ // cache status
205
+ confirmedTxs.push(txHash);
206
+ return [2 /*return*/, is_confirmed];
207
+ }
208
+ });
209
+ });
210
+ };
211
+ exports.getConfirmedTxStatus = getConfirmedTxStatus;
212
+ var broadcastTx = function (_a) {
213
+ var apiKey = _a.apiKey, baseUrl = _a.baseUrl, network = _a.network, txHex = _a.txHex;
214
+ return __awaiter(void 0, void 0, void 0, function () {
215
+ var params, url, response, broadcastResponse;
216
+ return __generator(this, function (_b) {
217
+ switch (_b.label) {
218
+ case 0:
219
+ params = {};
220
+ url = baseUrl + "/" + network + "/txs/push";
221
+ if (apiKey)
222
+ params['token'] = apiKey;
223
+ return [4 /*yield*/, axios_1.default.post(url, { tx: txHex }, { params: params })];
224
+ case 1:
225
+ response = _b.sent();
226
+ broadcastResponse = response.data;
227
+ return [2 /*return*/, broadcastResponse.tx.hash];
228
+ }
229
+ });
230
+ });
231
+ };
232
+ exports.broadcastTx = broadcastTx;
233
+ //# sourceMappingURL=blockcypher-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blockcypher-api.js","sourceRoot":"","sources":["../../../src/providers/blockcypher/blockcypher-api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAA4E;AAC5E,gDAAyB;AAazB;;;;;;;;GAQG;AACI,IAAM,KAAK,GAAG,UAAO,EAAgD;QAA9C,MAAM,YAAA,EAAE,OAAO,aAAA,EAAE,OAAO,aAAA,EAAE,IAAI,UAAA;;;;;;oBACpD,MAAM,GAA2B,EAAE,UAAU,EAAE,MAAM,EAAE,CAAA;oBAC7D,IAAI,MAAM;wBAAE,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAA;oBAC9B,GAAG,GAAM,OAAO,SAAI,OAAO,aAAQ,IAAM,CAAA;oBAC9B,qBAAM,eAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,EAAA;;oBAA3C,QAAQ,GAAG,SAAgC;oBAC3C,EAAE,GAAgB,QAAQ,CAAC,IAAI,CAAA;oBACrC,sBAAO,EAAE,EAAA;;;;CACV,CAAA;AAPY,QAAA,KAAK,SAOjB;AAED;;;;;;;;GAQG;AACI,IAAM,MAAM,GAAG,UAAO,EAgB5B;QAfC,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;sBADb;;oBALM,YAAY,GAAK,CAAA,SAKvB,CAAA,aALkB;oBAMpB,eAAe;oBACf,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;oBACzB,sBAAO,YAAY,EAAA;;;;CACpB,CAAA;AAvBY,QAAA,oBAAoB,wBAuBhC;AAEM,IAAM,WAAW,GAAG,UAAO,EAUjC;QATC,MAAM,YAAA,EACN,OAAO,aAAA,EACP,OAAO,aAAA,EACP,KAAK,WAAA;;;;;;oBAOC,MAAM,GAA2B,EAAE,CAAA;oBACnC,GAAG,GAAM,OAAO,SAAI,OAAO,cAAW,CAAA;oBAC5C,IAAI,MAAM;wBAAE,MAAM,CAAC,OAAO,CAAC,GAAG,MAAM,CAAA;oBACnB,qBAAM,eAAK,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,QAAA,EAAE,CAAC,EAAA;;oBAA3D,QAAQ,GAAG,SAAgD;oBAC3D,iBAAiB,GAAiB,QAAQ,CAAC,IAAI,CAAA;oBACrD,sBAAO,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAA;;;;CACjC,CAAA;AAjBY,QAAA,WAAW,eAiBvB"}
@@ -0,0 +1,52 @@
1
+ import { Balance, Tx, TxHash, TxHistoryParams, TxsPage, UTXO, UtxoOnlineDataProvider } from '@xchainjs/xchain-client';
2
+ import { Address, Asset, Chain } from '@xchainjs/xchain-util';
3
+ import { BlockcypherNetwork } from './blockcypher-api-types';
4
+ export declare class BlockcypherProvider implements UtxoOnlineDataProvider {
5
+ private baseUrl;
6
+ private _apiKey?;
7
+ private chain;
8
+ private asset;
9
+ private assetDecimals;
10
+ private blockcypherNetwork;
11
+ constructor(baseUrl: string, chain: Chain, asset: Asset, assetDecimals: number, blockcypherNetwork: BlockcypherNetwork, apiKey?: string);
12
+ get apiKey(): string | undefined;
13
+ set apiKey(value: string | undefined);
14
+ broadcastTx(txHex: string): Promise<TxHash>;
15
+ getConfirmedUnspentTxs(address: string): Promise<UTXO[]>;
16
+ getUnspentTxs(address: string): Promise<UTXO[]>;
17
+ getBalance(address: Address, assets?: Asset[], confirmedOnly?: boolean): Promise<Balance[]>;
18
+ /**
19
+ * Get transaction history of a given address with pagination options.
20
+ * By default it will return the transaction history of the current wallet.
21
+ *
22
+ * @param {TxHistoryParams} params The options to get transaction history. (optional)
23
+ * @returns {TxsPage} The transaction history.
24
+ */
25
+ getTransactions(params?: TxHistoryParams, unspentOnly?: boolean): Promise<TxsPage>;
26
+ /**
27
+ * Get the transaction details of a given transaction id.
28
+ *
29
+ * @param {string} txId The transaction id.
30
+ * @returns {Tx} The transaction details of the given transaction id.
31
+ */
32
+ getTransactionData(txId: string): Promise<Tx>;
33
+ private mapTransactionToTx;
34
+ private mapUTXOs;
35
+ /**
36
+ * helper function tto limit adding to an array
37
+ *
38
+ * @param arr array to be added to
39
+ * @param toAdd elements to add
40
+ * @param limit do not add more than this limit
41
+ */
42
+ private addArrayUpToLimit;
43
+ private delay;
44
+ /**
45
+ * Get transaction history of a given address with pagination options.
46
+ * By default it will return the transaction history of the current wallet.
47
+ *
48
+ * @param {TxHistoryParams} params The options to get transaction history. (optional)
49
+ * @returns {TxsPage} The transaction history.
50
+ */
51
+ private getRawTransactions;
52
+ }