@xchainjs/xchain-bitcoin 0.18.4 → 0.19.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/lib/client.d.ts +1 -12
- package/lib/index.esm.js +12 -132
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +4 -124
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
package/lib/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address, Balance,
|
|
1
|
+
import { Address, Balance, Fee, FeeRate, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, UTXOClient, XChainClientParams } from '@xchainjs/xchain-client';
|
|
2
2
|
import { Asset } from '@xchainjs/xchain-util';
|
|
3
3
|
import { ClientUrl } from './types/client-types';
|
|
4
4
|
export declare type BitcoinClientParams = XChainClientParams & {
|
|
@@ -114,16 +114,5 @@ declare class Client extends UTXOClient {
|
|
|
114
114
|
transfer(params: TxParams & {
|
|
115
115
|
feeRate?: FeeRate;
|
|
116
116
|
}): Promise<TxHash>;
|
|
117
|
-
/**
|
|
118
|
-
* Transaction to THORChain inbound address.
|
|
119
|
-
*
|
|
120
|
-
* @param {DepositParams} params The transaction options.
|
|
121
|
-
* @returns {TxHash} The transaction hash.
|
|
122
|
-
*
|
|
123
|
-
* @throws {"halted chain"} Thrown if chain is halted.
|
|
124
|
-
* @throws {"halted trading"} Thrown if trading is halted.
|
|
125
|
-
* @throws {"memo too long"} Thrown if memo longer than 80 chars.
|
|
126
|
-
*/
|
|
127
|
-
deposit({ walletIndex, asset, amount, memo }: DepositParams): Promise<TxHash>;
|
|
128
117
|
}
|
|
129
118
|
export { Client };
|
package/lib/index.esm.js
CHANGED
|
@@ -5,7 +5,7 @@ import stream from 'stream';
|
|
|
5
5
|
import string_decoder$1 from 'string_decoder';
|
|
6
6
|
import crypto$1$1 from 'crypto';
|
|
7
7
|
import readableStream from 'readable-stream';
|
|
8
|
-
import axios
|
|
8
|
+
import axios from 'axios';
|
|
9
9
|
|
|
10
10
|
/*! *****************************************************************************
|
|
11
11
|
Copyright (c) Microsoft Corporation.
|
|
@@ -64891,7 +64891,7 @@ const chainToString = Object.assign((chainId) => {
|
|
|
64891
64891
|
[Chain.Polkadot]: 'Polkadot',
|
|
64892
64892
|
[Chain.Terra]: 'Terra',
|
|
64893
64893
|
[Chain.Doge]: 'Dogecoin',
|
|
64894
|
-
});
|
|
64894
|
+
});
|
|
64895
64895
|
|
|
64896
64896
|
var Denomination;
|
|
64897
64897
|
(function (Denomination) {
|
|
@@ -65072,27 +65072,6 @@ const AssetRuneERC20Testnet = {
|
|
|
65072
65072
|
ticker: RUNE_TICKER,
|
|
65073
65073
|
synth: false,
|
|
65074
65074
|
};
|
|
65075
|
-
const SYNTH_DELIMITER = '/';
|
|
65076
|
-
const NON_SYNTH_DELIMITER = '.';
|
|
65077
|
-
/**
|
|
65078
|
-
* Returns an `Asset` as a string using following naming convention:
|
|
65079
|
-
*
|
|
65080
|
-
* `AAA.BBB-CCC`
|
|
65081
|
-
* where
|
|
65082
|
-
* chain: `AAA`
|
|
65083
|
-
* ticker (optional): `BBB`
|
|
65084
|
-
* symbol: `BBB-CCC` or `CCC` (if no ticker available)
|
|
65085
|
-
* symbol (synth): `BBB/CCC` or `CCC` (if no ticker available)
|
|
65086
|
-
*
|
|
65087
|
-
* @see https://docs.thorchain.org/developers/transaction-memos#asset-notation
|
|
65088
|
-
*
|
|
65089
|
-
* @param {Asset} asset The given asset.
|
|
65090
|
-
* @returns {string} The string from the given asset.
|
|
65091
|
-
*/
|
|
65092
|
-
const assetToString = ({ chain, symbol, synth }) => {
|
|
65093
|
-
const delimiter = synth ? SYNTH_DELIMITER : NON_SYNTH_DELIMITER;
|
|
65094
|
-
return `${chain}${delimiter}${symbol}`;
|
|
65095
|
-
};
|
|
65096
65075
|
/**
|
|
65097
65076
|
* Currency symbols currently supported
|
|
65098
65077
|
*/
|
|
@@ -65103,77 +65082,7 @@ var AssetCurrencySymbol;
|
|
|
65103
65082
|
AssetCurrencySymbol["SATOSHI"] = "\u26A1";
|
|
65104
65083
|
AssetCurrencySymbol["ETH"] = "\u039E";
|
|
65105
65084
|
AssetCurrencySymbol["USD"] = "$";
|
|
65106
|
-
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));
|
|
65107
|
-
|
|
65108
|
-
/*! *****************************************************************************
|
|
65109
|
-
Copyright (c) Microsoft Corporation.
|
|
65110
|
-
|
|
65111
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
65112
|
-
purpose with or without fee is hereby granted.
|
|
65113
|
-
|
|
65114
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
65115
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
65116
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
65117
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
65118
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
65119
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
65120
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
65121
|
-
***************************************************************************** */
|
|
65122
|
-
|
|
65123
|
-
function __awaiter$1(thisArg, _arguments, P, generator) {
|
|
65124
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
65125
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
65126
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
65127
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
65128
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
65129
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
65130
|
-
});
|
|
65131
|
-
}
|
|
65132
|
-
|
|
65133
|
-
const axios = require('axios');
|
|
65134
|
-
const midgardBaseUrls = {
|
|
65135
|
-
[Network.Testnet]: ['https://testnet.midgard.thorchain.info'],
|
|
65136
|
-
[Network.Mainnet]: ['https://midgard.ninerealms.com', 'https://midgard.thorswap.net'],
|
|
65137
|
-
};
|
|
65138
|
-
const getMimirDetails = (network = Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65139
|
-
const path = '/v2/thorchain/mimir';
|
|
65140
|
-
for (const baseUrl of midgardBaseUrls[network]) {
|
|
65141
|
-
try {
|
|
65142
|
-
const { data } = yield axios.get(`${baseUrl}${path}`);
|
|
65143
|
-
return data;
|
|
65144
|
-
}
|
|
65145
|
-
catch (e) {
|
|
65146
|
-
console.error(e);
|
|
65147
|
-
}
|
|
65148
|
-
}
|
|
65149
|
-
throw new Error('Midgard not responding');
|
|
65150
|
-
});
|
|
65151
|
-
const getAllInboundDetails = (network = Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65152
|
-
const path = '/v2/thorchain/inbound_addresses';
|
|
65153
|
-
for (const baseUrl of midgardBaseUrls[network]) {
|
|
65154
|
-
try {
|
|
65155
|
-
const { data } = yield axios.get(`${baseUrl}${path}`);
|
|
65156
|
-
return data;
|
|
65157
|
-
}
|
|
65158
|
-
catch (e) {
|
|
65159
|
-
console.error(e);
|
|
65160
|
-
}
|
|
65161
|
-
}
|
|
65162
|
-
throw new Error('Midgard not responding');
|
|
65163
|
-
});
|
|
65164
|
-
const getInboundDetails = (chain, network = Network.Mainnet) => __awaiter$1(void 0, void 0, void 0, function* () {
|
|
65165
|
-
const [mimirDetails, allInboundDetails] = yield Promise.all([getMimirDetails(network), getAllInboundDetails(network)]);
|
|
65166
|
-
const inboundDetail = allInboundDetails === null || allInboundDetails === void 0 ? void 0 : allInboundDetails.find((item) => item.chain === chain);
|
|
65167
|
-
const details = {
|
|
65168
|
-
vault: (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.address) || '',
|
|
65169
|
-
haltedChain: (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.halted) || !!mimirDetails[`HALT${chain}CHAIN`] || !!mimirDetails['HALTCHAINGLOBAL'],
|
|
65170
|
-
haltedTrading: !!mimirDetails['HALTTRADING'] || !!mimirDetails[`HALT${chain}TRADING`],
|
|
65171
|
-
haltedLP: !!mimirDetails['PAUSELP'] || !!mimirDetails[`PAUSELP${chain}`],
|
|
65172
|
-
};
|
|
65173
|
-
if (inboundDetail === null || inboundDetail === void 0 ? void 0 : inboundDetail.router)
|
|
65174
|
-
details.router = inboundDetail.router;
|
|
65175
|
-
return details;
|
|
65176
|
-
});
|
|
65085
|
+
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));
|
|
65177
65086
|
|
|
65178
65087
|
var inherits_browser$1 = createCommonjsModule$1(function (module) {
|
|
65179
65088
|
if (typeof Object.create === 'function') {
|
|
@@ -85178,7 +85087,7 @@ const toSochainNetwork = (network) => {
|
|
|
85178
85087
|
*/
|
|
85179
85088
|
const getAddress = ({ sochainUrl, network, address }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85180
85089
|
const url = `${sochainUrl}/address/${toSochainNetwork(network)}/${address}`;
|
|
85181
|
-
const response = yield axios
|
|
85090
|
+
const response = yield axios.get(url);
|
|
85182
85091
|
const addressResponse = response.data;
|
|
85183
85092
|
return addressResponse.data;
|
|
85184
85093
|
});
|
|
@@ -85194,7 +85103,7 @@ const getAddress = ({ sochainUrl, network, address }) => __awaiter(void 0, void
|
|
|
85194
85103
|
*/
|
|
85195
85104
|
const getTx = ({ sochainUrl, network, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85196
85105
|
const url = `${sochainUrl}/get_tx/${toSochainNetwork(network)}/${hash}`;
|
|
85197
|
-
const response = yield axios
|
|
85106
|
+
const response = yield axios.get(url);
|
|
85198
85107
|
const tx = response.data;
|
|
85199
85108
|
return tx.data;
|
|
85200
85109
|
});
|
|
@@ -85211,7 +85120,7 @@ const getTx = ({ sochainUrl, network, hash }) => __awaiter(void 0, void 0, void
|
|
|
85211
85120
|
*/
|
|
85212
85121
|
const getBalance = ({ sochainUrl, network, address, confirmedOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85213
85122
|
const url = `${sochainUrl}/get_address_balance/${toSochainNetwork(network)}/${address}`;
|
|
85214
|
-
const response = yield axios
|
|
85123
|
+
const response = yield axios.get(url);
|
|
85215
85124
|
const balanceResponse = response.data;
|
|
85216
85125
|
const confirmed = assetAmount(balanceResponse.data.confirmed_balance, BTC_DECIMAL);
|
|
85217
85126
|
const unconfirmed = assetAmount(balanceResponse.data.unconfirmed_balance, BTC_DECIMAL);
|
|
@@ -85239,7 +85148,7 @@ const getUnspentTxs = ({ sochainUrl, network, address, startingFromTxId, }) => _
|
|
|
85239
85148
|
]
|
|
85240
85149
|
.filter((v) => !!v)
|
|
85241
85150
|
.join('/');
|
|
85242
|
-
const resp = yield axios
|
|
85151
|
+
const resp = yield axios.get(url);
|
|
85243
85152
|
const response = resp.data;
|
|
85244
85153
|
const txs = response.data.txs;
|
|
85245
85154
|
if (txs.length === 100) {
|
|
@@ -85268,7 +85177,7 @@ const getUnspentTxs = ({ sochainUrl, network, address, startingFromTxId, }) => _
|
|
|
85268
85177
|
* @returns {TxConfirmedStatus}
|
|
85269
85178
|
*/
|
|
85270
85179
|
const getIsTxConfirmed = ({ sochainUrl, network, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85271
|
-
const { data } = yield axios
|
|
85180
|
+
const { data } = yield axios.get(`${sochainUrl}/is_tx_confirmed/${toSochainNetwork(network)}/${hash}`);
|
|
85272
85181
|
return data.data;
|
|
85273
85182
|
});
|
|
85274
85183
|
/**
|
|
@@ -85335,7 +85244,7 @@ const getSuggestedTxFee = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
85335
85244
|
//So use Bitgo API for fee estimation
|
|
85336
85245
|
//Refer: https://app.bitgo.com/docs/#operation/v2.tx.getfeeestimate
|
|
85337
85246
|
try {
|
|
85338
|
-
const response = yield axios
|
|
85247
|
+
const response = yield axios.get('https://app.bitgo.com/api/v2/btc/tx/fee');
|
|
85339
85248
|
return response.data.feePerKb / 1000; // feePerKb to feePerByte
|
|
85340
85249
|
}
|
|
85341
85250
|
catch (error) {
|
|
@@ -85462,13 +85371,13 @@ var accumulative = function accumulative (utxos, outputs, feeRate) {
|
|
|
85462
85371
|
*
|
|
85463
85372
|
*/
|
|
85464
85373
|
const getBalance$1 = ({ haskoinUrl, address, confirmedOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85465
|
-
const { data: { confirmed, unconfirmed }, } = yield axios
|
|
85374
|
+
const { data: { confirmed, unconfirmed }, } = yield axios.get(`${haskoinUrl}/address/${address}/balance`);
|
|
85466
85375
|
const confirmedAmount = baseAmount(confirmed, BTC_DECIMAL);
|
|
85467
85376
|
const unconfirmedAmount = baseAmount(unconfirmed, BTC_DECIMAL);
|
|
85468
85377
|
return confirmedOnly ? confirmedAmount : confirmedAmount.plus(unconfirmedAmount);
|
|
85469
85378
|
});
|
|
85470
85379
|
const getUnspentTxs$1 = ({ haskoinUrl, address, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85471
|
-
const { data: response } = yield axios
|
|
85380
|
+
const { data: response } = yield axios.get(`${haskoinUrl}/address/${address}/unspent`);
|
|
85472
85381
|
return response;
|
|
85473
85382
|
});
|
|
85474
85383
|
const getConfirmedUnspentTxs$1 = ({ haskoinUrl, sochainUrl, address, network, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -85499,7 +85408,7 @@ const getConfirmedUnspentTxs$1 = ({ haskoinUrl, sochainUrl, address, network, })
|
|
|
85499
85408
|
* @returns {TxHash} Transaction hash.
|
|
85500
85409
|
*/
|
|
85501
85410
|
const broadcastTx = ({ txHex, haskoinUrl }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85502
|
-
const instance = axios
|
|
85411
|
+
const instance = axios.create();
|
|
85503
85412
|
const MAX = 5;
|
|
85504
85413
|
let counter = 0;
|
|
85505
85414
|
const onFullfilled = (res) => res;
|
|
@@ -86083,35 +85992,6 @@ class Client extends UTXOClient {
|
|
|
86083
85992
|
return yield broadcastTx$1({ txHex, haskoinUrl });
|
|
86084
85993
|
});
|
|
86085
85994
|
}
|
|
86086
|
-
/**
|
|
86087
|
-
* Transaction to THORChain inbound address.
|
|
86088
|
-
*
|
|
86089
|
-
* @param {DepositParams} params The transaction options.
|
|
86090
|
-
* @returns {TxHash} The transaction hash.
|
|
86091
|
-
*
|
|
86092
|
-
* @throws {"halted chain"} Thrown if chain is halted.
|
|
86093
|
-
* @throws {"halted trading"} Thrown if trading is halted.
|
|
86094
|
-
* @throws {"memo too long"} Thrown if memo longer than 80 chars.
|
|
86095
|
-
*/
|
|
86096
|
-
deposit({ walletIndex = 0, asset = AssetBTC, amount, memo }) {
|
|
86097
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86098
|
-
const inboundDetails = yield getInboundDetails(asset.chain, this.network);
|
|
86099
|
-
if (inboundDetails.haltedChain) {
|
|
86100
|
-
throw new Error(`Halted chain for ${assetToString(asset)}`);
|
|
86101
|
-
}
|
|
86102
|
-
if (inboundDetails.haltedTrading) {
|
|
86103
|
-
throw new Error(`Halted trading for ${assetToString(asset)}`);
|
|
86104
|
-
}
|
|
86105
|
-
const txHash = yield this.transfer({
|
|
86106
|
-
walletIndex,
|
|
86107
|
-
asset,
|
|
86108
|
-
amount,
|
|
86109
|
-
recipient: inboundDetails.vault,
|
|
86110
|
-
memo,
|
|
86111
|
-
});
|
|
86112
|
-
return txHash;
|
|
86113
|
-
});
|
|
86114
|
-
}
|
|
86115
85995
|
}
|
|
86116
85996
|
|
|
86117
85997
|
export { BTC_DECIMAL, Client, LOWER_FEE_BOUND, MIN_TX_FEE, UPPER_FEE_BOUND, broadcastTx$1 as broadcastTx, buildTx, calcFee, getBalance$2 as getBalance, getDefaultFees, getDefaultFeesWithRates, getPrefix, scanUTXOs, validateAddress };
|