@xchainjs/xchain-utxo 0.1.1
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/client.d.ts +81 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +275 -0
- package/lib/index.esm.js.map +1 -0
- package/lib/index.js +279 -0
- package/lib/index.js.map +1 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/types.d.ts +10 -0
- package/package.json +49 -0
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Balance, BaseXChainClient, ExplorerProviders, FeeEstimateOptions, FeeRate, FeeRates, Fees, FeesWithRates, Protocol, Tx, TxHash, TxHistoryParams, TxsPage } from '@xchainjs/xchain-client';
|
|
3
|
+
import { Address, Asset, Chain } from '@xchainjs/xchain-util';
|
|
4
|
+
import { UTXO, UtxoOnlineDataProviders } from '@xchainjs/xchain-utxo-providers';
|
|
5
|
+
import { UtxoClientParams } from './types';
|
|
6
|
+
export declare abstract class Client extends BaseXChainClient {
|
|
7
|
+
protected explorerProviders: ExplorerProviders;
|
|
8
|
+
protected dataProviders: UtxoOnlineDataProviders[];
|
|
9
|
+
/**
|
|
10
|
+
* Constructor
|
|
11
|
+
* Client is initialized with network type
|
|
12
|
+
*
|
|
13
|
+
* @param {Chain} chain Chain to instantiate the client with
|
|
14
|
+
* @param {UtxoClientParams} params
|
|
15
|
+
*/
|
|
16
|
+
constructor(chain: Chain, params: UtxoClientParams);
|
|
17
|
+
/**
|
|
18
|
+
* Get the explorer url.
|
|
19
|
+
*
|
|
20
|
+
* @returns {string} The explorer url based on the network.
|
|
21
|
+
*/
|
|
22
|
+
getExplorerUrl(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Get the explorer url for the given address.
|
|
25
|
+
*
|
|
26
|
+
* @param {Address} address
|
|
27
|
+
* @returns {string} The explorer url for the given address based on the network.
|
|
28
|
+
*/
|
|
29
|
+
getExplorerAddressUrl(address: string): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get the explorer url for the given transaction id.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} txID The transaction id
|
|
34
|
+
* @returns {string} The explorer url for the given transaction id based on the network.
|
|
35
|
+
*/
|
|
36
|
+
getExplorerTxUrl(txID: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Get transaction history of a given address with pagination options.
|
|
39
|
+
* By default it will return the transaction history of the current wallet.
|
|
40
|
+
*
|
|
41
|
+
* @param {TxHistoryParams} params The options to get transaction history. (optional)
|
|
42
|
+
* @returns {TxsPage} The transaction history.
|
|
43
|
+
*/
|
|
44
|
+
getTransactions(params?: TxHistoryParams): Promise<TxsPage>;
|
|
45
|
+
/**
|
|
46
|
+
* Get the transaction details of a given transaction id.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} txId The transaction id.
|
|
49
|
+
* @returns {Tx} The transaction details of the given transaction id.
|
|
50
|
+
*/
|
|
51
|
+
getTransactionData(txId: string): Promise<Tx>;
|
|
52
|
+
/**
|
|
53
|
+
* Gets balance of a given address.
|
|
54
|
+
*
|
|
55
|
+
* @param {Address} address to get balances from
|
|
56
|
+
* @param {undefined} Needed for legacy only to be in common with `XChainClient` interface - will be removed by a next version
|
|
57
|
+
* @param {confirmedOnly} Flag to get balances of confirmed txs only
|
|
58
|
+
*
|
|
59
|
+
* @returns {Balance[]} BTC balances
|
|
60
|
+
*/
|
|
61
|
+
getBalance(address: Address, _assets?: Asset[], confirmedOnly?: boolean): Promise<Balance[]>;
|
|
62
|
+
protected scanUTXOs(address: string, confirmedOnly?: boolean): Promise<UTXO[]>;
|
|
63
|
+
getFeesWithRates(options?: FeeEstimateOptions): Promise<FeesWithRates>;
|
|
64
|
+
getFees(options?: FeeEstimateOptions): Promise<Fees>;
|
|
65
|
+
/**
|
|
66
|
+
* Get fee rates
|
|
67
|
+
* @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers
|
|
68
|
+
*
|
|
69
|
+
* @returns {FeeRates} The fee rates (average, fast, fastest) in `Satoshis/byte`
|
|
70
|
+
*/
|
|
71
|
+
getFeeRates(protocol?: Protocol): Promise<FeeRates>;
|
|
72
|
+
broadcastTx(txHex: string): Promise<TxHash>;
|
|
73
|
+
protected roundRobinGetBalance(address: Address): Promise<Balance[]>;
|
|
74
|
+
protected roundRobinGetUnspentTxs(address: Address, confirmed: boolean): Promise<UTXO[]>;
|
|
75
|
+
protected roundRobinGetTransactionData(txid: string): Promise<Tx>;
|
|
76
|
+
protected roundRobinGetTransactions(params: TxHistoryParams): Promise<TxsPage>;
|
|
77
|
+
protected roundRobinBroadcastTx(txHex: string): Promise<string>;
|
|
78
|
+
protected abstract compileMemo(memo: string): Buffer;
|
|
79
|
+
protected abstract getFeeFromUtxos(inputs: UTXO[], feeRate: FeeRate, data: Buffer | null): number;
|
|
80
|
+
protected roundRobinGetFeeRates(): Promise<FeeRates>;
|
|
81
|
+
}
|
package/lib/index.d.ts
ADDED
package/lib/index.esm.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { BaseXChainClient, FeeType, Protocol, standardFeeRates } from '@xchainjs/xchain-client';
|
|
2
|
+
import { baseAmount } from '@xchainjs/xchain-util';
|
|
3
|
+
|
|
4
|
+
/******************************************************************************
|
|
5
|
+
Copyright (c) Microsoft Corporation.
|
|
6
|
+
|
|
7
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
8
|
+
purpose with or without fee is hereby granted.
|
|
9
|
+
|
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
11
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
12
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
13
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
14
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
17
|
+
***************************************************************************** */
|
|
18
|
+
|
|
19
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
20
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class Client extends BaseXChainClient {
|
|
30
|
+
/**
|
|
31
|
+
* Constructor
|
|
32
|
+
* Client is initialized with network type
|
|
33
|
+
*
|
|
34
|
+
* @param {Chain} chain Chain to instantiate the client with
|
|
35
|
+
* @param {UtxoClientParams} params
|
|
36
|
+
*/
|
|
37
|
+
constructor(chain, params) {
|
|
38
|
+
super(chain, {
|
|
39
|
+
network: params.network,
|
|
40
|
+
rootDerivationPaths: params.rootDerivationPaths,
|
|
41
|
+
phrase: params.phrase,
|
|
42
|
+
feeBounds: params.feeBounds,
|
|
43
|
+
});
|
|
44
|
+
this.explorerProviders = params.explorerProviders;
|
|
45
|
+
this.dataProviders = params.dataProviders;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the explorer url.
|
|
49
|
+
*
|
|
50
|
+
* @returns {string} The explorer url based on the network.
|
|
51
|
+
*/
|
|
52
|
+
getExplorerUrl() {
|
|
53
|
+
return this.explorerProviders[this.network].getExplorerUrl();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get the explorer url for the given address.
|
|
57
|
+
*
|
|
58
|
+
* @param {Address} address
|
|
59
|
+
* @returns {string} The explorer url for the given address based on the network.
|
|
60
|
+
*/
|
|
61
|
+
getExplorerAddressUrl(address) {
|
|
62
|
+
return this.explorerProviders[this.network].getExplorerAddressUrl(address);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the explorer url for the given transaction id.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} txID The transaction id
|
|
68
|
+
* @returns {string} The explorer url for the given transaction id based on the network.
|
|
69
|
+
*/
|
|
70
|
+
getExplorerTxUrl(txID) {
|
|
71
|
+
return this.explorerProviders[this.network].getExplorerTxUrl(txID);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get transaction history of a given address with pagination options.
|
|
75
|
+
* By default it will return the transaction history of the current wallet.
|
|
76
|
+
*
|
|
77
|
+
* @param {TxHistoryParams} params The options to get transaction history. (optional)
|
|
78
|
+
* @returns {TxsPage} The transaction history.
|
|
79
|
+
*/
|
|
80
|
+
getTransactions(params) {
|
|
81
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
const filteredParams = {
|
|
83
|
+
address: (params === null || params === void 0 ? void 0 : params.address) || (yield this.getAddress()),
|
|
84
|
+
offset: params === null || params === void 0 ? void 0 : params.offset,
|
|
85
|
+
limit: params === null || params === void 0 ? void 0 : params.limit,
|
|
86
|
+
startTime: params === null || params === void 0 ? void 0 : params.startTime,
|
|
87
|
+
asset: params === null || params === void 0 ? void 0 : params.asset,
|
|
88
|
+
};
|
|
89
|
+
return yield this.roundRobinGetTransactions(filteredParams);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the transaction details of a given transaction id.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} txId The transaction id.
|
|
96
|
+
* @returns {Tx} The transaction details of the given transaction id.
|
|
97
|
+
*/
|
|
98
|
+
getTransactionData(txId) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
return yield this.roundRobinGetTransactionData(txId);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Gets balance of a given address.
|
|
105
|
+
*
|
|
106
|
+
* @param {Address} address to get balances from
|
|
107
|
+
* @param {undefined} Needed for legacy only to be in common with `XChainClient` interface - will be removed by a next version
|
|
108
|
+
* @param {confirmedOnly} Flag to get balances of confirmed txs only
|
|
109
|
+
*
|
|
110
|
+
* @returns {Balance[]} BTC balances
|
|
111
|
+
*/
|
|
112
|
+
// TODO (@xchain-team|@veado) Change params to be an object to be extendable more easily
|
|
113
|
+
// see changes for `xchain-bitcoin` https://github.com/xchainjs/xchainjs-lib/pull/490
|
|
114
|
+
getBalance(address, _assets /* not used */, confirmedOnly) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
return yield this.roundRobinGetBalance(address);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
scanUTXOs(address, confirmedOnly = true) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
return this.roundRobinGetUnspentTxs(address, confirmedOnly);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
getFeesWithRates(options) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
const utxos = (options === null || options === void 0 ? void 0 : options.sender) ? yield this.scanUTXOs(options.sender, false) : [];
|
|
127
|
+
const compiledMemo = (options === null || options === void 0 ? void 0 : options.memo) ? this.compileMemo(options.memo) : null;
|
|
128
|
+
const rates = yield this.getFeeRates();
|
|
129
|
+
return {
|
|
130
|
+
fees: {
|
|
131
|
+
average: baseAmount(this.getFeeFromUtxos(utxos, rates.average, compiledMemo)),
|
|
132
|
+
fast: baseAmount(this.getFeeFromUtxos(utxos, rates.fast, compiledMemo)),
|
|
133
|
+
fastest: baseAmount(this.getFeeFromUtxos(utxos, rates.fastest, compiledMemo)),
|
|
134
|
+
type: FeeType.PerByte,
|
|
135
|
+
},
|
|
136
|
+
rates,
|
|
137
|
+
};
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
getFees(options) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
const { fees } = yield this.getFeesWithRates(options);
|
|
143
|
+
return fees;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Get fee rates
|
|
148
|
+
* @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers
|
|
149
|
+
*
|
|
150
|
+
* @returns {FeeRates} The fee rates (average, fast, fastest) in `Satoshis/byte`
|
|
151
|
+
*/
|
|
152
|
+
getFeeRates(protocol) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
if (!protocol) {
|
|
155
|
+
try {
|
|
156
|
+
const feeRates = yield this.roundRobinGetFeeRates();
|
|
157
|
+
return feeRates;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
console.warn('Can not retrieve fee rates from provider');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!protocol || Protocol.THORCHAIN) {
|
|
164
|
+
try {
|
|
165
|
+
const feeRate = yield this.getFeeRateFromThorchain();
|
|
166
|
+
return standardFeeRates(feeRate);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
console.warn(`Can not retrieve fee rates from Thorchain`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// TODO: Return default value
|
|
173
|
+
throw Error('Can not retrieve fee rates');
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
broadcastTx(txHex) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
return yield this.roundRobinBroadcastTx(txHex);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
roundRobinGetBalance(address) {
|
|
182
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
+
for (const provider of this.dataProviders) {
|
|
184
|
+
try {
|
|
185
|
+
const prov = provider[this.network];
|
|
186
|
+
if (prov)
|
|
187
|
+
return yield prov.getBalance(address, undefined);
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
console.warn(error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
throw Error('no provider able to get balance');
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
roundRobinGetUnspentTxs(address, confirmed) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
for (const provider of this.dataProviders) {
|
|
199
|
+
try {
|
|
200
|
+
const prov = provider[this.network];
|
|
201
|
+
if (prov) {
|
|
202
|
+
return confirmed ? yield prov.getConfirmedUnspentTxs(address) : yield prov.getUnspentTxs(address);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
console.warn(error);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
throw Error('no provider able to GetUnspentTxs');
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
roundRobinGetTransactionData(txid) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
for (const provider of this.dataProviders) {
|
|
215
|
+
try {
|
|
216
|
+
const prov = provider[this.network];
|
|
217
|
+
if (prov)
|
|
218
|
+
return yield prov.getTransactionData(txid);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
console.warn(error);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
throw Error('no provider able to GetTransactionData');
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
roundRobinGetTransactions(params) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
for (const provider of this.dataProviders) {
|
|
230
|
+
try {
|
|
231
|
+
const prov = provider[this.network];
|
|
232
|
+
if (prov)
|
|
233
|
+
return yield prov.getTransactions(params);
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
console.warn(error);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
throw Error('no provider able to GetTransactions');
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
roundRobinBroadcastTx(txHex) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
for (const provider of this.dataProviders) {
|
|
245
|
+
try {
|
|
246
|
+
const prov = provider[this.network];
|
|
247
|
+
if (prov)
|
|
248
|
+
return yield prov.broadcastTx(txHex);
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
console.warn(error);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
throw Error('no provider able to BroadcastTx');
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
roundRobinGetFeeRates() {
|
|
258
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
for (const provider of this.dataProviders) {
|
|
260
|
+
try {
|
|
261
|
+
const prov = provider[this.network];
|
|
262
|
+
if (prov)
|
|
263
|
+
return yield prov.getFeeRates();
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
console.warn(error);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
throw Error('no provider able to get fee rates');
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { Client };
|
|
275
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/client.ts"],"sourcesContent":["import {\n Balance,\n BaseXChainClient,\n ExplorerProviders,\n FeeEstimateOptions,\n FeeRate,\n FeeRates,\n FeeType,\n Fees,\n FeesWithRates,\n Protocol,\n Tx,\n TxHash,\n TxHistoryParams,\n TxsPage,\n standardFeeRates,\n} from '@xchainjs/xchain-client'\nimport { Address, Asset, Chain, baseAmount } from '@xchainjs/xchain-util'\nimport { UTXO, UtxoOnlineDataProviders } from '@xchainjs/xchain-utxo-providers'\n\nimport { UtxoClientParams } from './types'\n\nexport abstract class Client extends BaseXChainClient {\n protected explorerProviders: ExplorerProviders\n protected dataProviders: UtxoOnlineDataProviders[]\n\n /**\n * Constructor\n * Client is initialized with network type\n *\n * @param {Chain} chain Chain to instantiate the client with\n * @param {UtxoClientParams} params\n */\n constructor(chain: Chain, params: UtxoClientParams) {\n super(chain, {\n network: params.network,\n rootDerivationPaths: params.rootDerivationPaths,\n phrase: params.phrase,\n feeBounds: params.feeBounds,\n })\n this.explorerProviders = params.explorerProviders\n this.dataProviders = params.dataProviders\n }\n\n /**\n * Get the explorer url.\n *\n * @returns {string} The explorer url based on the network.\n */\n getExplorerUrl(): string {\n return this.explorerProviders[this.network].getExplorerUrl()\n }\n\n /**\n * Get the explorer url for the given address.\n *\n * @param {Address} address\n * @returns {string} The explorer url for the given address based on the network.\n */\n getExplorerAddressUrl(address: string): string {\n return this.explorerProviders[this.network].getExplorerAddressUrl(address)\n }\n\n /**\n * Get the explorer url for the given transaction id.\n *\n * @param {string} txID The transaction id\n * @returns {string} The explorer url for the given transaction id based on the network.\n */\n getExplorerTxUrl(txID: string): string {\n return this.explorerProviders[this.network].getExplorerTxUrl(txID)\n }\n\n /**\n * Get transaction history of a given address with pagination options.\n * By default it will return the transaction history of the current wallet.\n *\n * @param {TxHistoryParams} params The options to get transaction history. (optional)\n * @returns {TxsPage} The transaction history.\n */\n async getTransactions(params?: TxHistoryParams): Promise<TxsPage> {\n const filteredParams: TxHistoryParams = {\n address: params?.address || (await this.getAddress()),\n offset: params?.offset,\n limit: params?.limit,\n startTime: params?.startTime,\n asset: params?.asset,\n }\n\n return await this.roundRobinGetTransactions(filteredParams)\n }\n\n /**\n * Get the transaction details of a given transaction id.\n *\n * @param {string} txId The transaction id.\n * @returns {Tx} The transaction details of the given transaction id.\n */\n async getTransactionData(txId: string): Promise<Tx> {\n return await this.roundRobinGetTransactionData(txId)\n }\n\n /**\n * Gets balance of a given address.\n *\n * @param {Address} address to get balances from\n * @param {undefined} Needed for legacy only to be in common with `XChainClient` interface - will be removed by a next version\n * @param {confirmedOnly} Flag to get balances of confirmed txs only\n *\n * @returns {Balance[]} BTC balances\n */\n // TODO (@xchain-team|@veado) Change params to be an object to be extendable more easily\n // see changes for `xchain-bitcoin` https://github.com/xchainjs/xchainjs-lib/pull/490\n async getBalance(address: Address, _assets?: Asset[] /* not used */, confirmedOnly?: boolean): Promise<Balance[]> {\n // TODO figure this out ---> !!confirmedOnly)\n confirmedOnly\n return await this.roundRobinGetBalance(address)\n }\n\n protected async scanUTXOs(\n address: string,\n confirmedOnly = true, // default: scan only confirmed UTXOs\n ): Promise<UTXO[]> {\n return this.roundRobinGetUnspentTxs(address, confirmedOnly)\n }\n\n async getFeesWithRates(options?: FeeEstimateOptions): Promise<FeesWithRates> {\n const utxos = options?.sender ? await this.scanUTXOs(options.sender, false) : []\n const compiledMemo = options?.memo ? this.compileMemo(options.memo) : null\n\n const rates = await this.getFeeRates()\n\n return {\n fees: {\n average: baseAmount(this.getFeeFromUtxos(utxos, rates.average, compiledMemo)),\n fast: baseAmount(this.getFeeFromUtxos(utxos, rates.fast, compiledMemo)),\n fastest: baseAmount(this.getFeeFromUtxos(utxos, rates.fastest, compiledMemo)),\n type: FeeType.PerByte,\n },\n rates,\n }\n }\n\n async getFees(options?: FeeEstimateOptions): Promise<Fees> {\n const { fees } = await this.getFeesWithRates(options)\n return fees\n }\n\n /**\n * Get fee rates\n * @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers\n *\n * @returns {FeeRates} The fee rates (average, fast, fastest) in `Satoshis/byte`\n */\n async getFeeRates(protocol?: Protocol): Promise<FeeRates> {\n if (!protocol) {\n try {\n const feeRates = await this.roundRobinGetFeeRates()\n return feeRates\n } catch (error) {\n console.warn('Can not retrieve fee rates from provider')\n }\n }\n\n if (!protocol || Protocol.THORCHAIN) {\n try {\n const feeRate = await this.getFeeRateFromThorchain()\n return standardFeeRates(feeRate)\n } catch (error) {\n console.warn(`Can not retrieve fee rates from Thorchain`)\n }\n }\n // TODO: Return default value\n throw Error('Can not retrieve fee rates')\n }\n\n async broadcastTx(txHex: string): Promise<TxHash> {\n return await this.roundRobinBroadcastTx(txHex)\n }\n\n protected async roundRobinGetBalance(address: Address) {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) return await prov.getBalance(address, undefined)\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to get balance')\n }\n\n protected async roundRobinGetUnspentTxs(address: Address, confirmed: boolean) {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) {\n return confirmed ? await prov.getConfirmedUnspentTxs(address) : await prov.getUnspentTxs(address)\n }\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to GetUnspentTxs')\n }\n\n protected async roundRobinGetTransactionData(txid: string) {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) return await prov.getTransactionData(txid)\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to GetTransactionData')\n }\n\n protected async roundRobinGetTransactions(params: TxHistoryParams) {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) return await prov.getTransactions(params)\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to GetTransactions')\n }\n\n protected async roundRobinBroadcastTx(txHex: string) {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) return await prov.broadcastTx(txHex)\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to BroadcastTx')\n }\n\n protected abstract compileMemo(memo: string): Buffer\n protected abstract getFeeFromUtxos(inputs: UTXO[], feeRate: FeeRate, data: Buffer | null): number\n protected async roundRobinGetFeeRates(): Promise<FeeRates> {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) return await prov.getFeeRates()\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
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var xchainClient = require('@xchainjs/xchain-client');
|
|
6
|
+
var xchainUtil = require('@xchainjs/xchain-util');
|
|
7
|
+
|
|
8
|
+
/******************************************************************************
|
|
9
|
+
Copyright (c) Microsoft Corporation.
|
|
10
|
+
|
|
11
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
12
|
+
purpose with or without fee is hereby granted.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
15
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
16
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
17
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
18
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
19
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
20
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
21
|
+
***************************************************************************** */
|
|
22
|
+
|
|
23
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
24
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
27
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
28
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
class Client extends xchainClient.BaseXChainClient {
|
|
34
|
+
/**
|
|
35
|
+
* Constructor
|
|
36
|
+
* Client is initialized with network type
|
|
37
|
+
*
|
|
38
|
+
* @param {Chain} chain Chain to instantiate the client with
|
|
39
|
+
* @param {UtxoClientParams} params
|
|
40
|
+
*/
|
|
41
|
+
constructor(chain, params) {
|
|
42
|
+
super(chain, {
|
|
43
|
+
network: params.network,
|
|
44
|
+
rootDerivationPaths: params.rootDerivationPaths,
|
|
45
|
+
phrase: params.phrase,
|
|
46
|
+
feeBounds: params.feeBounds,
|
|
47
|
+
});
|
|
48
|
+
this.explorerProviders = params.explorerProviders;
|
|
49
|
+
this.dataProviders = params.dataProviders;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the explorer url.
|
|
53
|
+
*
|
|
54
|
+
* @returns {string} The explorer url based on the network.
|
|
55
|
+
*/
|
|
56
|
+
getExplorerUrl() {
|
|
57
|
+
return this.explorerProviders[this.network].getExplorerUrl();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the explorer url for the given address.
|
|
61
|
+
*
|
|
62
|
+
* @param {Address} address
|
|
63
|
+
* @returns {string} The explorer url for the given address based on the network.
|
|
64
|
+
*/
|
|
65
|
+
getExplorerAddressUrl(address) {
|
|
66
|
+
return this.explorerProviders[this.network].getExplorerAddressUrl(address);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the explorer url for the given transaction id.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} txID The transaction id
|
|
72
|
+
* @returns {string} The explorer url for the given transaction id based on the network.
|
|
73
|
+
*/
|
|
74
|
+
getExplorerTxUrl(txID) {
|
|
75
|
+
return this.explorerProviders[this.network].getExplorerTxUrl(txID);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Get transaction history of a given address with pagination options.
|
|
79
|
+
* By default it will return the transaction history of the current wallet.
|
|
80
|
+
*
|
|
81
|
+
* @param {TxHistoryParams} params The options to get transaction history. (optional)
|
|
82
|
+
* @returns {TxsPage} The transaction history.
|
|
83
|
+
*/
|
|
84
|
+
getTransactions(params) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const filteredParams = {
|
|
87
|
+
address: (params === null || params === void 0 ? void 0 : params.address) || (yield this.getAddress()),
|
|
88
|
+
offset: params === null || params === void 0 ? void 0 : params.offset,
|
|
89
|
+
limit: params === null || params === void 0 ? void 0 : params.limit,
|
|
90
|
+
startTime: params === null || params === void 0 ? void 0 : params.startTime,
|
|
91
|
+
asset: params === null || params === void 0 ? void 0 : params.asset,
|
|
92
|
+
};
|
|
93
|
+
return yield this.roundRobinGetTransactions(filteredParams);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get the transaction details of a given transaction id.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} txId The transaction id.
|
|
100
|
+
* @returns {Tx} The transaction details of the given transaction id.
|
|
101
|
+
*/
|
|
102
|
+
getTransactionData(txId) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
return yield this.roundRobinGetTransactionData(txId);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Gets balance of a given address.
|
|
109
|
+
*
|
|
110
|
+
* @param {Address} address to get balances from
|
|
111
|
+
* @param {undefined} Needed for legacy only to be in common with `XChainClient` interface - will be removed by a next version
|
|
112
|
+
* @param {confirmedOnly} Flag to get balances of confirmed txs only
|
|
113
|
+
*
|
|
114
|
+
* @returns {Balance[]} BTC balances
|
|
115
|
+
*/
|
|
116
|
+
// TODO (@xchain-team|@veado) Change params to be an object to be extendable more easily
|
|
117
|
+
// see changes for `xchain-bitcoin` https://github.com/xchainjs/xchainjs-lib/pull/490
|
|
118
|
+
getBalance(address, _assets /* not used */, confirmedOnly) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
return yield this.roundRobinGetBalance(address);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
scanUTXOs(address, confirmedOnly = true) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
return this.roundRobinGetUnspentTxs(address, confirmedOnly);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
getFeesWithRates(options) {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
const utxos = (options === null || options === void 0 ? void 0 : options.sender) ? yield this.scanUTXOs(options.sender, false) : [];
|
|
131
|
+
const compiledMemo = (options === null || options === void 0 ? void 0 : options.memo) ? this.compileMemo(options.memo) : null;
|
|
132
|
+
const rates = yield this.getFeeRates();
|
|
133
|
+
return {
|
|
134
|
+
fees: {
|
|
135
|
+
average: xchainUtil.baseAmount(this.getFeeFromUtxos(utxos, rates.average, compiledMemo)),
|
|
136
|
+
fast: xchainUtil.baseAmount(this.getFeeFromUtxos(utxos, rates.fast, compiledMemo)),
|
|
137
|
+
fastest: xchainUtil.baseAmount(this.getFeeFromUtxos(utxos, rates.fastest, compiledMemo)),
|
|
138
|
+
type: xchainClient.FeeType.PerByte,
|
|
139
|
+
},
|
|
140
|
+
rates,
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
getFees(options) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const { fees } = yield this.getFeesWithRates(options);
|
|
147
|
+
return fees;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get fee rates
|
|
152
|
+
* @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers
|
|
153
|
+
*
|
|
154
|
+
* @returns {FeeRates} The fee rates (average, fast, fastest) in `Satoshis/byte`
|
|
155
|
+
*/
|
|
156
|
+
getFeeRates(protocol) {
|
|
157
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
158
|
+
if (!protocol) {
|
|
159
|
+
try {
|
|
160
|
+
const feeRates = yield this.roundRobinGetFeeRates();
|
|
161
|
+
return feeRates;
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.warn('Can not retrieve fee rates from provider');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!protocol || xchainClient.Protocol.THORCHAIN) {
|
|
168
|
+
try {
|
|
169
|
+
const feeRate = yield this.getFeeRateFromThorchain();
|
|
170
|
+
return xchainClient.standardFeeRates(feeRate);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
console.warn(`Can not retrieve fee rates from Thorchain`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
// TODO: Return default value
|
|
177
|
+
throw Error('Can not retrieve fee rates');
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
broadcastTx(txHex) {
|
|
181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
return yield this.roundRobinBroadcastTx(txHex);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
roundRobinGetBalance(address) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
for (const provider of this.dataProviders) {
|
|
188
|
+
try {
|
|
189
|
+
const prov = provider[this.network];
|
|
190
|
+
if (prov)
|
|
191
|
+
return yield prov.getBalance(address, undefined);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
console.warn(error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
throw Error('no provider able to get balance');
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
roundRobinGetUnspentTxs(address, confirmed) {
|
|
201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
+
for (const provider of this.dataProviders) {
|
|
203
|
+
try {
|
|
204
|
+
const prov = provider[this.network];
|
|
205
|
+
if (prov) {
|
|
206
|
+
return confirmed ? yield prov.getConfirmedUnspentTxs(address) : yield prov.getUnspentTxs(address);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
console.warn(error);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
throw Error('no provider able to GetUnspentTxs');
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
roundRobinGetTransactionData(txid) {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
for (const provider of this.dataProviders) {
|
|
219
|
+
try {
|
|
220
|
+
const prov = provider[this.network];
|
|
221
|
+
if (prov)
|
|
222
|
+
return yield prov.getTransactionData(txid);
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
console.warn(error);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
throw Error('no provider able to GetTransactionData');
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
roundRobinGetTransactions(params) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
for (const provider of this.dataProviders) {
|
|
234
|
+
try {
|
|
235
|
+
const prov = provider[this.network];
|
|
236
|
+
if (prov)
|
|
237
|
+
return yield prov.getTransactions(params);
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
console.warn(error);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
throw Error('no provider able to GetTransactions');
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
roundRobinBroadcastTx(txHex) {
|
|
247
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
for (const provider of this.dataProviders) {
|
|
249
|
+
try {
|
|
250
|
+
const prov = provider[this.network];
|
|
251
|
+
if (prov)
|
|
252
|
+
return yield prov.broadcastTx(txHex);
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
console.warn(error);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
throw Error('no provider able to BroadcastTx');
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
roundRobinGetFeeRates() {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
for (const provider of this.dataProviders) {
|
|
264
|
+
try {
|
|
265
|
+
const prov = provider[this.network];
|
|
266
|
+
if (prov)
|
|
267
|
+
return yield prov.getFeeRates();
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
console.warn(error);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
throw Error('no provider able to get fee rates');
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
exports.Client = Client;
|
|
279
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/client.ts"],"sourcesContent":["import {\n Balance,\n BaseXChainClient,\n ExplorerProviders,\n FeeEstimateOptions,\n FeeRate,\n FeeRates,\n FeeType,\n Fees,\n FeesWithRates,\n Protocol,\n Tx,\n TxHash,\n TxHistoryParams,\n TxsPage,\n standardFeeRates,\n} from '@xchainjs/xchain-client'\nimport { Address, Asset, Chain, baseAmount } from '@xchainjs/xchain-util'\nimport { UTXO, UtxoOnlineDataProviders } from '@xchainjs/xchain-utxo-providers'\n\nimport { UtxoClientParams } from './types'\n\nexport abstract class Client extends BaseXChainClient {\n protected explorerProviders: ExplorerProviders\n protected dataProviders: UtxoOnlineDataProviders[]\n\n /**\n * Constructor\n * Client is initialized with network type\n *\n * @param {Chain} chain Chain to instantiate the client with\n * @param {UtxoClientParams} params\n */\n constructor(chain: Chain, params: UtxoClientParams) {\n super(chain, {\n network: params.network,\n rootDerivationPaths: params.rootDerivationPaths,\n phrase: params.phrase,\n feeBounds: params.feeBounds,\n })\n this.explorerProviders = params.explorerProviders\n this.dataProviders = params.dataProviders\n }\n\n /**\n * Get the explorer url.\n *\n * @returns {string} The explorer url based on the network.\n */\n getExplorerUrl(): string {\n return this.explorerProviders[this.network].getExplorerUrl()\n }\n\n /**\n * Get the explorer url for the given address.\n *\n * @param {Address} address\n * @returns {string} The explorer url for the given address based on the network.\n */\n getExplorerAddressUrl(address: string): string {\n return this.explorerProviders[this.network].getExplorerAddressUrl(address)\n }\n\n /**\n * Get the explorer url for the given transaction id.\n *\n * @param {string} txID The transaction id\n * @returns {string} The explorer url for the given transaction id based on the network.\n */\n getExplorerTxUrl(txID: string): string {\n return this.explorerProviders[this.network].getExplorerTxUrl(txID)\n }\n\n /**\n * Get transaction history of a given address with pagination options.\n * By default it will return the transaction history of the current wallet.\n *\n * @param {TxHistoryParams} params The options to get transaction history. (optional)\n * @returns {TxsPage} The transaction history.\n */\n async getTransactions(params?: TxHistoryParams): Promise<TxsPage> {\n const filteredParams: TxHistoryParams = {\n address: params?.address || (await this.getAddress()),\n offset: params?.offset,\n limit: params?.limit,\n startTime: params?.startTime,\n asset: params?.asset,\n }\n\n return await this.roundRobinGetTransactions(filteredParams)\n }\n\n /**\n * Get the transaction details of a given transaction id.\n *\n * @param {string} txId The transaction id.\n * @returns {Tx} The transaction details of the given transaction id.\n */\n async getTransactionData(txId: string): Promise<Tx> {\n return await this.roundRobinGetTransactionData(txId)\n }\n\n /**\n * Gets balance of a given address.\n *\n * @param {Address} address to get balances from\n * @param {undefined} Needed for legacy only to be in common with `XChainClient` interface - will be removed by a next version\n * @param {confirmedOnly} Flag to get balances of confirmed txs only\n *\n * @returns {Balance[]} BTC balances\n */\n // TODO (@xchain-team|@veado) Change params to be an object to be extendable more easily\n // see changes for `xchain-bitcoin` https://github.com/xchainjs/xchainjs-lib/pull/490\n async getBalance(address: Address, _assets?: Asset[] /* not used */, confirmedOnly?: boolean): Promise<Balance[]> {\n // TODO figure this out ---> !!confirmedOnly)\n confirmedOnly\n return await this.roundRobinGetBalance(address)\n }\n\n protected async scanUTXOs(\n address: string,\n confirmedOnly = true, // default: scan only confirmed UTXOs\n ): Promise<UTXO[]> {\n return this.roundRobinGetUnspentTxs(address, confirmedOnly)\n }\n\n async getFeesWithRates(options?: FeeEstimateOptions): Promise<FeesWithRates> {\n const utxos = options?.sender ? await this.scanUTXOs(options.sender, false) : []\n const compiledMemo = options?.memo ? this.compileMemo(options.memo) : null\n\n const rates = await this.getFeeRates()\n\n return {\n fees: {\n average: baseAmount(this.getFeeFromUtxos(utxos, rates.average, compiledMemo)),\n fast: baseAmount(this.getFeeFromUtxos(utxos, rates.fast, compiledMemo)),\n fastest: baseAmount(this.getFeeFromUtxos(utxos, rates.fastest, compiledMemo)),\n type: FeeType.PerByte,\n },\n rates,\n }\n }\n\n async getFees(options?: FeeEstimateOptions): Promise<Fees> {\n const { fees } = await this.getFeesWithRates(options)\n return fees\n }\n\n /**\n * Get fee rates\n * @param {Protocol} protocol Protocol to interact with. If there's no protocol provided, fee rates are retrieved from chain data providers\n *\n * @returns {FeeRates} The fee rates (average, fast, fastest) in `Satoshis/byte`\n */\n async getFeeRates(protocol?: Protocol): Promise<FeeRates> {\n if (!protocol) {\n try {\n const feeRates = await this.roundRobinGetFeeRates()\n return feeRates\n } catch (error) {\n console.warn('Can not retrieve fee rates from provider')\n }\n }\n\n if (!protocol || Protocol.THORCHAIN) {\n try {\n const feeRate = await this.getFeeRateFromThorchain()\n return standardFeeRates(feeRate)\n } catch (error) {\n console.warn(`Can not retrieve fee rates from Thorchain`)\n }\n }\n // TODO: Return default value\n throw Error('Can not retrieve fee rates')\n }\n\n async broadcastTx(txHex: string): Promise<TxHash> {\n return await this.roundRobinBroadcastTx(txHex)\n }\n\n protected async roundRobinGetBalance(address: Address) {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) return await prov.getBalance(address, undefined)\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to get balance')\n }\n\n protected async roundRobinGetUnspentTxs(address: Address, confirmed: boolean) {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) {\n return confirmed ? await prov.getConfirmedUnspentTxs(address) : await prov.getUnspentTxs(address)\n }\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to GetUnspentTxs')\n }\n\n protected async roundRobinGetTransactionData(txid: string) {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) return await prov.getTransactionData(txid)\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to GetTransactionData')\n }\n\n protected async roundRobinGetTransactions(params: TxHistoryParams) {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) return await prov.getTransactions(params)\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to GetTransactions')\n }\n\n protected async roundRobinBroadcastTx(txHex: string) {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) return await prov.broadcastTx(txHex)\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to BroadcastTx')\n }\n\n protected abstract compileMemo(memo: string): Buffer\n protected abstract getFeeFromUtxos(inputs: UTXO[], feeRate: FeeRate, data: Buffer | null): number\n protected async roundRobinGetFeeRates(): Promise<FeeRates> {\n for (const provider of this.dataProviders) {\n try {\n const prov = provider[this.network]\n if (prov) return await prov.getFeeRates()\n } catch (error) {\n console.warn(error)\n }\n }\n throw Error('no provider able to get fee rates')\n }\n}\n"],"names":["BaseXChainClient","baseAmount","FeeType","Protocol","standardFeeRates"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsBM,MAAgB,MAAO,SAAQA,6BAAgB,CAAA;AAInD;;;;;;AAMG;IACH,WAAY,CAAA,KAAY,EAAE,MAAwB,EAAA;QAChD,KAAK,CAAC,KAAK,EAAE;YACX,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,mBAAmB,EAAE,MAAM,CAAC,mBAAmB;YAC/C,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,SAAS,EAAE,MAAM,CAAC,SAAS;AAC5B,SAAA,CAAC,CAAA;AACF,QAAA,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAA;AACjD,QAAA,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAA;KAC1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ACd,oBAAA,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACpB,iBAAA;AACF,aAAA;AACD,YAAA,MAAM,KAAK,CAAC,iCAAiC,CAAC,CAAA;SAC/C,CAAA,CAAA;AAAA,KAAA;IAIe,qBAAqB,GAAA;;AACnC,YAAA,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,aAAa,EAAE;gBACzC,IAAI;oBACF,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;AACnC,oBAAA,IAAI,IAAI;AAAE,wBAAA,OAAO,MAAM,IAAI,CAAC,WAAW,EAAE,CAAA;AAC1C,iBAAA;AAAC,gBAAA,OAAO,KAAK,EAAE;AACd,oBAAA,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACpB,iBAAA;AACF,aAAA;AACD,YAAA,MAAM,KAAK,CAAC,mCAAmC,CAAC,CAAA;SACjD,CAAA,CAAA;AAAA,KAAA;AACF;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ExplorerProviders, PreparedTx as BasePreparedTx, XChainClientParams } from '@xchainjs/xchain-client';
|
|
2
|
+
import { UTXO, UtxoOnlineDataProviders, Witness } from '@xchainjs/xchain-utxo-providers';
|
|
3
|
+
export type UtxoClientParams = XChainClientParams & {
|
|
4
|
+
explorerProviders: ExplorerProviders;
|
|
5
|
+
dataProviders: UtxoOnlineDataProviders[];
|
|
6
|
+
};
|
|
7
|
+
export type PreparedTx = BasePreparedTx & {
|
|
8
|
+
utxos: UTXO[];
|
|
9
|
+
};
|
|
10
|
+
export { UTXO, Witness };
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xchainjs/xchain-utxo",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Genereic UTXO client for XChainJS",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"XChain",
|
|
7
|
+
"UTXO"
|
|
8
|
+
],
|
|
9
|
+
"author": "XChainJS",
|
|
10
|
+
"homepage": "https://github.com/xchainjs/xchainjs-lib",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"main": "lib/index.js",
|
|
13
|
+
"module": "lib/index.esm.js",
|
|
14
|
+
"typings": "lib/index.d.ts",
|
|
15
|
+
"directories": {
|
|
16
|
+
"lib": "lib",
|
|
17
|
+
"test": "__tests__"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git@github.com:xchainjs/xchainjs-lib.git"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"clean": "rimraf lib/**",
|
|
28
|
+
"build": "yarn clean && rollup -c",
|
|
29
|
+
"lint": "eslint \"{src,__tests__, __mocks__}/**/*.ts\" --fix --max-warnings 0",
|
|
30
|
+
"prepublishOnly": "yarn build"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@xchainjs/xchain-client": "^0.16.0",
|
|
37
|
+
"@xchainjs/xchain-crypto": "^0.3.0",
|
|
38
|
+
"@xchainjs/xchain-util": "^0.13.1",
|
|
39
|
+
"@xchainjs/xchain-utxo-providers": "^0.2.10",
|
|
40
|
+
"axios": "^1.3.6"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"@xchainjs/xchain-client": "^0.16.0",
|
|
44
|
+
"@xchainjs/xchain-crypto": "^0.3.0",
|
|
45
|
+
"@xchainjs/xchain-util": "^0.13.1",
|
|
46
|
+
"@xchainjs/xchain-utxo-providers": "^0.2.10",
|
|
47
|
+
"axios": "^1.3.6"
|
|
48
|
+
}
|
|
49
|
+
}
|