@xchainjs/xchain-client
Advanced tools
Comparing version 0.13.5 to 0.13.6
@@ -6,1 +6,3 @@ export * from './BaseXChainClient'; | ||
export * from './fees'; | ||
export * from './explorer-provider'; | ||
export * from './provider-types'; |
@@ -18,2 +18,4 @@ "use strict"; | ||
__exportStar(require("./fees"), exports); | ||
__exportStar(require("./explorer-provider"), exports); | ||
__exportStar(require("./provider-types"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -0,6 +1,67 @@ | ||
import { Address, Asset, Chain } from '@xchainjs/xchain-util'; | ||
import { BaseXChainClient as Client } from './BaseXChainClient'; | ||
import { Fee, FeeRate, FeeRates, Fees, FeesWithRates } from './types'; | ||
import { ExplorerProviders, UTXO, UtxoOnlineDataProviders } from './provider-types'; | ||
import { Balance, Fee, FeeRate, FeeRates, Fees, FeesWithRates, Tx, TxHistoryParams, TxsPage, XChainClientParams } from './types'; | ||
export declare type UtxoClientParams = XChainClientParams & { | ||
explorerProviders: ExplorerProviders; | ||
dataProviders: UtxoOnlineDataProviders[]; | ||
}; | ||
export declare abstract class UTXOClient extends Client { | ||
protected explorerProviders: ExplorerProviders; | ||
protected dataProviders: UtxoOnlineDataProviders[]; | ||
protected abstract getSuggestedFeeRate(): Promise<FeeRate>; | ||
protected abstract calcFee(feeRate: FeeRate, memo?: string): Promise<Fee>; | ||
/** | ||
* Constructor | ||
* Client is initialised with network type | ||
* | ||
* @param {UtxoClientParams} params | ||
*/ | ||
constructor(chain: Chain, params: UtxoClientParams); | ||
/** | ||
* Get the explorer url. | ||
* | ||
* @returns {string} The explorer url based on the network. | ||
*/ | ||
getExplorerUrl(): string; | ||
/** | ||
* Get the explorer url for the given address. | ||
* | ||
* @param {Address} address | ||
* @returns {string} The explorer url for the given address based on the network. | ||
*/ | ||
getExplorerAddressUrl(address: string): string; | ||
/** | ||
* Get the explorer url for the given transaction id. | ||
* | ||
* @param {string} txID The transaction id | ||
* @returns {string} The explorer url for the given transaction id based on the network. | ||
*/ | ||
getExplorerTxUrl(txID: string): string; | ||
/** | ||
* Get transaction history of a given address with pagination options. | ||
* By default it will return the transaction history of the current wallet. | ||
* | ||
* @param {TxHistoryParams} params The options to get transaction history. (optional) | ||
* @returns {TxsPage} The transaction history. | ||
*/ | ||
getTransactions(params?: TxHistoryParams): Promise<TxsPage>; | ||
/** | ||
* Get the transaction details of a given transaction id. | ||
* | ||
* @param {string} txId The transaction id. | ||
* @returns {Tx} The transaction details of the given transaction id. | ||
*/ | ||
getTransactionData(txId: string): Promise<Tx>; | ||
/** | ||
* Gets BTC balances of a given address. | ||
* | ||
* @param {Address} BTC address to get balances from | ||
* @param {undefined} Needed for legacy only to be in common with `XChainClient` interface - will be removed by a next version | ||
* @param {confirmedOnly} Flag to get balances of confirmed txs only | ||
* | ||
* @returns {Balance[]} BTC balances | ||
*/ | ||
getBalance(address: Address, _assets?: Asset[], confirmedOnly?: boolean): Promise<Balance[]>; | ||
protected scanUTXOs(address: string, confirmedOnly?: boolean): Promise<UTXO[]>; | ||
getFeesWithRates(memo?: string): Promise<FeesWithRates>; | ||
@@ -13,2 +74,7 @@ getFees(memo?: string): Promise<Fees>; | ||
getFeeRates(): Promise<FeeRates>; | ||
protected roundRobinGetBalance(address: Address): Promise<Balance[]>; | ||
protected roundRobinGetUnspentTxs(address: Address, confirmed: boolean): Promise<UTXO[]>; | ||
protected roundRobinGetTransactionData(txid: string): Promise<Tx>; | ||
protected roundRobinGetTransactions(params: TxHistoryParams): Promise<TxsPage>; | ||
protected roundRobinBroadcastTx(txHex: string): Promise<string>; | ||
} |
@@ -60,5 +60,119 @@ "use strict"; | ||
__extends(UTXOClient, _super); | ||
function UTXOClient() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
/** | ||
* Constructor | ||
* Client is initialised with network type | ||
* | ||
* @param {UtxoClientParams} params | ||
*/ | ||
function UTXOClient(chain, params) { | ||
var _this = _super.call(this, chain, { | ||
network: params.network, | ||
rootDerivationPaths: params.rootDerivationPaths, | ||
phrase: params.phrase, | ||
feeBounds: params.feeBounds, | ||
}) || this; | ||
_this.explorerProviders = params.explorerProviders; | ||
_this.dataProviders = params.dataProviders; | ||
return _this; | ||
} | ||
/** | ||
* Get the explorer url. | ||
* | ||
* @returns {string} The explorer url based on the network. | ||
*/ | ||
UTXOClient.prototype.getExplorerUrl = function () { | ||
return this.explorerProviders[this.network].getExplorerUrl(); | ||
}; | ||
/** | ||
* Get the explorer url for the given address. | ||
* | ||
* @param {Address} address | ||
* @returns {string} The explorer url for the given address based on the network. | ||
*/ | ||
UTXOClient.prototype.getExplorerAddressUrl = function (address) { | ||
return this.explorerProviders[this.network].getExplorerAddressUrl(address); | ||
}; | ||
/** | ||
* Get the explorer url for the given transaction id. | ||
* | ||
* @param {string} txID The transaction id | ||
* @returns {string} The explorer url for the given transaction id based on the network. | ||
*/ | ||
UTXOClient.prototype.getExplorerTxUrl = function (txID) { | ||
return this.explorerProviders[this.network].getExplorerTxUrl(txID); | ||
}; | ||
/** | ||
* Get transaction history of a given address with pagination options. | ||
* By default it will return the transaction history of the current wallet. | ||
* | ||
* @param {TxHistoryParams} params The options to get transaction history. (optional) | ||
* @returns {TxsPage} The transaction history. | ||
*/ | ||
UTXOClient.prototype.getTransactions = function (params) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var filteredParams; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
filteredParams = { | ||
address: (params === null || params === void 0 ? void 0 : params.address) || this.getAddress(), | ||
offset: params === null || params === void 0 ? void 0 : params.offset, | ||
limit: params === null || params === void 0 ? void 0 : params.limit, | ||
startTime: params === null || params === void 0 ? void 0 : params.startTime, | ||
asset: params === null || params === void 0 ? void 0 : params.asset, | ||
}; | ||
return [4 /*yield*/, this.roundRobinGetTransactions(filteredParams)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Get the transaction details of a given transaction id. | ||
* | ||
* @param {string} txId The transaction id. | ||
* @returns {Tx} The transaction details of the given transaction id. | ||
*/ | ||
UTXOClient.prototype.getTransactionData = function (txId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.roundRobinGetTransactionData(txId)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Gets BTC balances of a given address. | ||
* | ||
* @param {Address} BTC address to get balances from | ||
* @param {undefined} Needed for legacy only to be in common with `XChainClient` interface - will be removed by a next version | ||
* @param {confirmedOnly} Flag to get balances of confirmed txs only | ||
* | ||
* @returns {Balance[]} BTC balances | ||
*/ | ||
// TODO (@xchain-team|@veado) Change params to be an object to be extendable more easily | ||
// see changes for `xchain-bitcoin` https://github.com/xchainjs/xchainjs-lib/pull/490 | ||
UTXOClient.prototype.getBalance = function (address, _assets /* not used */, confirmedOnly) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
// TODO figure this out ---> !!confirmedOnly) | ||
confirmedOnly; | ||
return [4 /*yield*/, this.roundRobinGetBalance(address)]; | ||
case 1: return [2 /*return*/, _a.sent()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
UTXOClient.prototype.scanUTXOs = function (address, confirmedOnly) { | ||
if (confirmedOnly === void 0) { confirmedOnly = true; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, this.roundRobinGetUnspentTxs(address, confirmedOnly)]; | ||
}); | ||
}); | ||
}; | ||
UTXOClient.prototype.getFeesWithRates = function (memo) { | ||
@@ -141,2 +255,165 @@ return __awaiter(this, void 0, void 0, function () { | ||
}; | ||
UTXOClient.prototype.roundRobinGetBalance = function (address) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _i, _a, provider, prov, error_2; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_i = 0, _a = this.dataProviders; | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 7]; | ||
provider = _a[_i]; | ||
_b.label = 2; | ||
case 2: | ||
_b.trys.push([2, 5, , 6]); | ||
prov = provider[this.network]; | ||
if (!prov) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, prov.getBalance(address, undefined)]; | ||
case 3: return [2 /*return*/, _b.sent()]; | ||
case 4: return [3 /*break*/, 6]; | ||
case 5: | ||
error_2 = _b.sent(); | ||
console.warn(error_2); | ||
return [3 /*break*/, 6]; | ||
case 6: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 7: throw Error('no provider able to get balance'); | ||
} | ||
}); | ||
}); | ||
}; | ||
UTXOClient.prototype.roundRobinGetUnspentTxs = function (address, confirmed) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _i, _a, provider, prov, _b, error_3; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
_i = 0, _a = this.dataProviders; | ||
_c.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 10]; | ||
provider = _a[_i]; | ||
_c.label = 2; | ||
case 2: | ||
_c.trys.push([2, 8, , 9]); | ||
prov = provider[this.network]; | ||
if (!prov) return [3 /*break*/, 7]; | ||
if (!confirmed) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, prov.getConfirmedUnspentTxs(address)]; | ||
case 3: | ||
_b = _c.sent(); | ||
return [3 /*break*/, 6]; | ||
case 4: return [4 /*yield*/, prov.getUnspentTxs(address)]; | ||
case 5: | ||
_b = _c.sent(); | ||
_c.label = 6; | ||
case 6: return [2 /*return*/, _b]; | ||
case 7: return [3 /*break*/, 9]; | ||
case 8: | ||
error_3 = _c.sent(); | ||
console.warn(error_3); | ||
return [3 /*break*/, 9]; | ||
case 9: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 10: throw Error('no provider able to GetUnspentTxs'); | ||
} | ||
}); | ||
}); | ||
}; | ||
UTXOClient.prototype.roundRobinGetTransactionData = function (txid) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _i, _a, provider, prov, error_4; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_i = 0, _a = this.dataProviders; | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 7]; | ||
provider = _a[_i]; | ||
_b.label = 2; | ||
case 2: | ||
_b.trys.push([2, 5, , 6]); | ||
prov = provider[this.network]; | ||
if (!prov) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, prov.getTransactionData(txid)]; | ||
case 3: return [2 /*return*/, _b.sent()]; | ||
case 4: return [3 /*break*/, 6]; | ||
case 5: | ||
error_4 = _b.sent(); | ||
console.warn(error_4); | ||
return [3 /*break*/, 6]; | ||
case 6: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 7: throw Error('no provider able to GetTransactionData'); | ||
} | ||
}); | ||
}); | ||
}; | ||
UTXOClient.prototype.roundRobinGetTransactions = function (params) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _i, _a, provider, prov, error_5; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_i = 0, _a = this.dataProviders; | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 7]; | ||
provider = _a[_i]; | ||
_b.label = 2; | ||
case 2: | ||
_b.trys.push([2, 5, , 6]); | ||
prov = provider[this.network]; | ||
if (!prov) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, prov.getTransactions(params)]; | ||
case 3: return [2 /*return*/, _b.sent()]; | ||
case 4: return [3 /*break*/, 6]; | ||
case 5: | ||
error_5 = _b.sent(); | ||
console.warn(error_5); | ||
return [3 /*break*/, 6]; | ||
case 6: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 7: throw Error('no provider able to GetTransactions'); | ||
} | ||
}); | ||
}); | ||
}; | ||
UTXOClient.prototype.roundRobinBroadcastTx = function (txHex) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _i, _a, provider, prov, error_6; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_i = 0, _a = this.dataProviders; | ||
_b.label = 1; | ||
case 1: | ||
if (!(_i < _a.length)) return [3 /*break*/, 7]; | ||
provider = _a[_i]; | ||
_b.label = 2; | ||
case 2: | ||
_b.trys.push([2, 5, , 6]); | ||
prov = provider[this.network]; | ||
if (!prov) return [3 /*break*/, 4]; | ||
return [4 /*yield*/, prov.broadcastTx(txHex)]; | ||
case 3: return [2 /*return*/, _b.sent()]; | ||
case 4: return [3 /*break*/, 6]; | ||
case 5: | ||
error_6 = _b.sent(); | ||
console.warn(error_6); | ||
return [3 /*break*/, 6]; | ||
case 6: | ||
_i++; | ||
return [3 /*break*/, 1]; | ||
case 7: throw Error('no provider able to BroadcastTx'); | ||
} | ||
}); | ||
}); | ||
}; | ||
return UTXOClient; | ||
@@ -143,0 +420,0 @@ }(BaseXChainClient_1.BaseXChainClient)); |
{ | ||
"name": "@xchainjs/xchain-client", | ||
"version": "0.13.5", | ||
"version": "0.13.6", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "main": "lib/index", |
@@ -10,1 +10,2 @@ # XChainJS Wallet Client Interface | ||
[`Interface of xchain-client`](http://docs.xchainjs.org/xchain-client/interface.html) | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
61841
26
1112
11
1