@xchainjs/xchain-bitcoin 0.18.2 → 0.20.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 +5 -13
- package/lib/const.d.ts +2 -0
- package/lib/index.esm.js +42 -141
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +34 -131
- package/lib/index.js.map +1 -1
- package/lib/types/client-types.d.ts +2 -1
- package/lib/types/haskoin-api-types.d.ts +1 -1
- package/lib/utils.d.ts +2 -2
- package/package.json +5 -5
- package/CHANGELOG.md +0 -307
package/lib/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Asset } from '@xchainjs/xchain-util';
|
|
1
|
+
import { Balance, Fee, FeeRate, Tx, TxHash, TxHistoryParams, TxParams, TxsPage, UTXOClient, XChainClientParams } from '@xchainjs/xchain-client';
|
|
2
|
+
import { Address, Asset } from '@xchainjs/xchain-util';
|
|
3
3
|
import { ClientUrl } from './types/client-types';
|
|
4
4
|
export declare type BitcoinClientParams = XChainClientParams & {
|
|
5
5
|
sochainUrl?: string;
|
|
@@ -17,7 +17,7 @@ declare class Client extends UTXOClient {
|
|
|
17
17
|
*
|
|
18
18
|
* @param {BitcoinClientParams} params
|
|
19
19
|
*/
|
|
20
|
-
constructor({ network, sochainUrl, haskoinUrl, rootDerivationPaths, phrase, }: BitcoinClientParams);
|
|
20
|
+
constructor({ network, feeBounds, sochainUrl, haskoinUrl, rootDerivationPaths, phrase, }: BitcoinClientParams);
|
|
21
21
|
/**
|
|
22
22
|
* Set/Update the sochain url.
|
|
23
23
|
*
|
|
@@ -108,19 +108,11 @@ declare class Client extends UTXOClient {
|
|
|
108
108
|
*
|
|
109
109
|
* @param {TxParams&FeeRate} params The transfer options.
|
|
110
110
|
* @returns {TxHash} The transaction hash.
|
|
111
|
+
*
|
|
112
|
+
* @throws {"memo too long"} Thrown if memo longer than 80 chars.
|
|
111
113
|
*/
|
|
112
114
|
transfer(params: TxParams & {
|
|
113
115
|
feeRate?: FeeRate;
|
|
114
116
|
}): Promise<TxHash>;
|
|
115
|
-
/**
|
|
116
|
-
* Transaction to THORChain inbound address.
|
|
117
|
-
*
|
|
118
|
-
* @param {DepositParams} params The transaction options.
|
|
119
|
-
* @returns {TxHash} The transaction hash.
|
|
120
|
-
*
|
|
121
|
-
* @throws {"halted chain"} Thrown if chain is halted.
|
|
122
|
-
* @throws {"halted trading"} Thrown if trading is halted.
|
|
123
|
-
*/
|
|
124
|
-
deposit({ walletIndex, asset, amount, memo }: DepositParams): Promise<TxHash>;
|
|
125
117
|
}
|
|
126
118
|
export { Client };
|
package/lib/const.d.ts
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Network, standardFeeRates, FeeOption, calcFees, UTXOClient, TxType } from '@xchainjs/xchain-client';
|
|
1
|
+
import { Network, standardFeeRates, FeeOption, calcFees, UTXOClient, TxType, checkFeeBounds } from '@xchainjs/xchain-client';
|
|
2
2
|
import buffer from 'buffer';
|
|
3
3
|
import events from 'events';
|
|
4
4
|
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.
|
|
@@ -64849,27 +64849,29 @@ const fixedBN = (value, decimalPlaces = 2) => {
|
|
|
64849
64849
|
|
|
64850
64850
|
var Chain;
|
|
64851
64851
|
(function (Chain) {
|
|
64852
|
+
Chain["Avalanche"] = "AVAX";
|
|
64852
64853
|
Chain["Binance"] = "BNB";
|
|
64853
64854
|
Chain["Bitcoin"] = "BTC";
|
|
64854
64855
|
Chain["Ethereum"] = "ETH";
|
|
64855
64856
|
Chain["THORChain"] = "THOR";
|
|
64856
64857
|
Chain["Cosmos"] = "GAIA";
|
|
64857
|
-
Chain["Polkadot"] = "POLKA";
|
|
64858
64858
|
Chain["BitcoinCash"] = "BCH";
|
|
64859
64859
|
Chain["Litecoin"] = "LTC";
|
|
64860
64860
|
Chain["Terra"] = "TERRA";
|
|
64861
64861
|
Chain["Doge"] = "DOGE";
|
|
64862
|
+
Chain["Avax"] = "AVAX";
|
|
64862
64863
|
})(Chain || (Chain = {}));
|
|
64864
|
+
const AvalancheChain = Chain.Avalanche;
|
|
64863
64865
|
const BNBChain = Chain.Binance;
|
|
64864
64866
|
const BTCChain = Chain.Bitcoin;
|
|
64865
64867
|
const ETHChain = Chain.Ethereum;
|
|
64866
64868
|
const THORChain = Chain.THORChain;
|
|
64867
64869
|
const CosmosChain = Chain.Cosmos;
|
|
64868
|
-
const PolkadotChain = Chain.Polkadot;
|
|
64869
64870
|
const BCHChain = Chain.BitcoinCash;
|
|
64870
64871
|
const LTCChain = Chain.Litecoin;
|
|
64871
64872
|
const TerraChain = Chain.Terra;
|
|
64872
64873
|
const DOGEChain = Chain.Doge;
|
|
64874
|
+
const AVAXChain = Chain.Avax;
|
|
64873
64875
|
/**
|
|
64874
64876
|
* Convert chain to string.
|
|
64875
64877
|
*
|
|
@@ -64881,6 +64883,7 @@ const chainToString = Object.assign((chainId) => {
|
|
|
64881
64883
|
return 'unknown chain';
|
|
64882
64884
|
return chainToString[chainId];
|
|
64883
64885
|
}, {
|
|
64886
|
+
[Chain.Avalanche]: 'Avalanche',
|
|
64884
64887
|
[Chain.THORChain]: 'Thorchain',
|
|
64885
64888
|
[Chain.Bitcoin]: 'Bitcoin',
|
|
64886
64889
|
[Chain.BitcoinCash]: 'Bitcoin Cash',
|
|
@@ -64888,10 +64891,9 @@ const chainToString = Object.assign((chainId) => {
|
|
|
64888
64891
|
[Chain.Ethereum]: 'Ethereum',
|
|
64889
64892
|
[Chain.Binance]: 'Binance Chain',
|
|
64890
64893
|
[Chain.Cosmos]: 'Cosmos',
|
|
64891
|
-
[Chain.Polkadot]: 'Polkadot',
|
|
64892
64894
|
[Chain.Terra]: 'Terra',
|
|
64893
64895
|
[Chain.Doge]: 'Dogecoin',
|
|
64894
|
-
});
|
|
64896
|
+
});
|
|
64895
64897
|
|
|
64896
64898
|
var Denomination;
|
|
64897
64899
|
(function (Denomination) {
|
|
@@ -64914,7 +64916,7 @@ var Denomination;
|
|
|
64914
64916
|
const isBigNumberValue = (v) => typeof v === 'string' || typeof v === 'number' || v instanceof bignumber$1;
|
|
64915
64917
|
/**
|
|
64916
64918
|
* Default number of asset decimals
|
|
64917
|
-
* For history reason and by starting the project on Binance chain assets, it's 8 decimal.
|
|
64919
|
+
* For history reason and by starting the project on Binance chain assets, it's 8 decimal.F
|
|
64918
64920
|
*
|
|
64919
64921
|
* For example:
|
|
64920
64922
|
* ```
|
|
@@ -64985,6 +64987,11 @@ const assetToBase = (asset) => {
|
|
|
64985
64987
|
.integerValue();
|
|
64986
64988
|
return baseAmount(value, asset.decimal);
|
|
64987
64989
|
};
|
|
64990
|
+
/**
|
|
64991
|
+
* Base "chain" asset of Avalanche chain.
|
|
64992
|
+
*
|
|
64993
|
+
*/
|
|
64994
|
+
const AssetAVAX = { chain: Chain.Avalanche, symbol: 'AVAX', ticker: 'AVAX', synth: false };
|
|
64988
64995
|
/**
|
|
64989
64996
|
* Base "chain" asset of Binance chain.
|
|
64990
64997
|
*
|
|
@@ -65072,27 +65079,8 @@ const AssetRuneERC20Testnet = {
|
|
|
65072
65079
|
ticker: RUNE_TICKER,
|
|
65073
65080
|
synth: false,
|
|
65074
65081
|
};
|
|
65075
|
-
const
|
|
65076
|
-
const
|
|
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
|
-
};
|
|
65082
|
+
const AssetAtom = { chain: Chain.Cosmos, symbol: 'ATOM', ticker: 'ATOM', synth: false };
|
|
65083
|
+
const AssetLUNA = { chain: Chain.Terra, symbol: 'LUNA', ticker: 'LUNA', synth: false };
|
|
65096
65084
|
/**
|
|
65097
65085
|
* Currency symbols currently supported
|
|
65098
65086
|
*/
|
|
@@ -65103,77 +65091,7 @@ var AssetCurrencySymbol;
|
|
|
65103
65091
|
AssetCurrencySymbol["SATOSHI"] = "\u26A1";
|
|
65104
65092
|
AssetCurrencySymbol["ETH"] = "\u039E";
|
|
65105
65093
|
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
|
-
});
|
|
65094
|
+
})(AssetCurrencySymbol || (AssetCurrencySymbol = {}));
|
|
65177
65095
|
|
|
65178
65096
|
var inherits_browser$1 = createCommonjsModule$1(function (module) {
|
|
65179
65097
|
if (typeof Object.create === 'function') {
|
|
@@ -85152,7 +85070,9 @@ var src_12 = src$3.TransactionBuilder;
|
|
|
85152
85070
|
* @see https://github.com/bitcoin/bitcoin/blob/db88db47278d2e7208c50d16ab10cb355067d071/src/validation.h#L56
|
|
85153
85071
|
*/
|
|
85154
85072
|
const MIN_TX_FEE = 1000;
|
|
85155
|
-
const BTC_DECIMAL = 8;
|
|
85073
|
+
const BTC_DECIMAL = 8;
|
|
85074
|
+
const LOWER_FEE_BOUND = 1;
|
|
85075
|
+
const UPPER_FEE_BOUND = 500;
|
|
85156
85076
|
|
|
85157
85077
|
const DEFAULT_SUGGESTED_TRANSACTION_FEE = 127;
|
|
85158
85078
|
const toSochainNetwork = (network) => {
|
|
@@ -85176,7 +85096,7 @@ const toSochainNetwork = (network) => {
|
|
|
85176
85096
|
*/
|
|
85177
85097
|
const getAddress = ({ sochainUrl, network, address }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85178
85098
|
const url = `${sochainUrl}/address/${toSochainNetwork(network)}/${address}`;
|
|
85179
|
-
const response = yield axios
|
|
85099
|
+
const response = yield axios.get(url);
|
|
85180
85100
|
const addressResponse = response.data;
|
|
85181
85101
|
return addressResponse.data;
|
|
85182
85102
|
});
|
|
@@ -85192,7 +85112,7 @@ const getAddress = ({ sochainUrl, network, address }) => __awaiter(void 0, void
|
|
|
85192
85112
|
*/
|
|
85193
85113
|
const getTx = ({ sochainUrl, network, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85194
85114
|
const url = `${sochainUrl}/get_tx/${toSochainNetwork(network)}/${hash}`;
|
|
85195
|
-
const response = yield axios
|
|
85115
|
+
const response = yield axios.get(url);
|
|
85196
85116
|
const tx = response.data;
|
|
85197
85117
|
return tx.data;
|
|
85198
85118
|
});
|
|
@@ -85209,7 +85129,7 @@ const getTx = ({ sochainUrl, network, hash }) => __awaiter(void 0, void 0, void
|
|
|
85209
85129
|
*/
|
|
85210
85130
|
const getBalance = ({ sochainUrl, network, address, confirmedOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85211
85131
|
const url = `${sochainUrl}/get_address_balance/${toSochainNetwork(network)}/${address}`;
|
|
85212
|
-
const response = yield axios
|
|
85132
|
+
const response = yield axios.get(url);
|
|
85213
85133
|
const balanceResponse = response.data;
|
|
85214
85134
|
const confirmed = assetAmount(balanceResponse.data.confirmed_balance, BTC_DECIMAL);
|
|
85215
85135
|
const unconfirmed = assetAmount(balanceResponse.data.unconfirmed_balance, BTC_DECIMAL);
|
|
@@ -85237,7 +85157,7 @@ const getUnspentTxs = ({ sochainUrl, network, address, startingFromTxId, }) => _
|
|
|
85237
85157
|
]
|
|
85238
85158
|
.filter((v) => !!v)
|
|
85239
85159
|
.join('/');
|
|
85240
|
-
const resp = yield axios
|
|
85160
|
+
const resp = yield axios.get(url);
|
|
85241
85161
|
const response = resp.data;
|
|
85242
85162
|
const txs = response.data.txs;
|
|
85243
85163
|
if (txs.length === 100) {
|
|
@@ -85266,7 +85186,7 @@ const getUnspentTxs = ({ sochainUrl, network, address, startingFromTxId, }) => _
|
|
|
85266
85186
|
* @returns {TxConfirmedStatus}
|
|
85267
85187
|
*/
|
|
85268
85188
|
const getIsTxConfirmed = ({ sochainUrl, network, hash }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85269
|
-
const { data } = yield axios
|
|
85189
|
+
const { data } = yield axios.get(`${sochainUrl}/is_tx_confirmed/${toSochainNetwork(network)}/${hash}`);
|
|
85270
85190
|
return data.data;
|
|
85271
85191
|
});
|
|
85272
85192
|
/**
|
|
@@ -85333,7 +85253,7 @@ const getSuggestedTxFee = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
85333
85253
|
//So use Bitgo API for fee estimation
|
|
85334
85254
|
//Refer: https://app.bitgo.com/docs/#operation/v2.tx.getfeeestimate
|
|
85335
85255
|
try {
|
|
85336
|
-
const response = yield axios
|
|
85256
|
+
const response = yield axios.get('https://app.bitgo.com/api/v2/btc/tx/fee');
|
|
85337
85257
|
return response.data.feePerKb / 1000; // feePerKb to feePerByte
|
|
85338
85258
|
}
|
|
85339
85259
|
catch (error) {
|
|
@@ -85460,13 +85380,13 @@ var accumulative = function accumulative (utxos, outputs, feeRate) {
|
|
|
85460
85380
|
*
|
|
85461
85381
|
*/
|
|
85462
85382
|
const getBalance$1 = ({ haskoinUrl, address, confirmedOnly, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85463
|
-
const { data: { confirmed, unconfirmed }, } = yield axios
|
|
85383
|
+
const { data: { confirmed, unconfirmed }, } = yield axios.get(`${haskoinUrl}/address/${address}/balance`);
|
|
85464
85384
|
const confirmedAmount = baseAmount(confirmed, BTC_DECIMAL);
|
|
85465
85385
|
const unconfirmedAmount = baseAmount(unconfirmed, BTC_DECIMAL);
|
|
85466
85386
|
return confirmedOnly ? confirmedAmount : confirmedAmount.plus(unconfirmedAmount);
|
|
85467
85387
|
});
|
|
85468
85388
|
const getUnspentTxs$1 = ({ haskoinUrl, address, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85469
|
-
const { data: response } = yield axios
|
|
85389
|
+
const { data: response } = yield axios.get(`${haskoinUrl}/address/${address}/unspent`);
|
|
85470
85390
|
return response;
|
|
85471
85391
|
});
|
|
85472
85392
|
const getConfirmedUnspentTxs$1 = ({ haskoinUrl, sochainUrl, address, network, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -85497,7 +85417,7 @@ const getConfirmedUnspentTxs$1 = ({ haskoinUrl, sochainUrl, address, network, })
|
|
|
85497
85417
|
* @returns {TxHash} Transaction hash.
|
|
85498
85418
|
*/
|
|
85499
85419
|
const broadcastTx = ({ txHex, haskoinUrl }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
85500
|
-
const instance = axios
|
|
85420
|
+
const instance = axios.create();
|
|
85501
85421
|
const MAX = 5;
|
|
85502
85422
|
let counter = 0;
|
|
85503
85423
|
const onFullfilled = (res) => res;
|
|
@@ -85710,8 +85630,11 @@ withTxHex = false, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
85710
85630
|
// search only confirmed UTXOs if pending UTXO is not allowed
|
|
85711
85631
|
const confirmedOnly = !spendPendingUTXO;
|
|
85712
85632
|
const utxos = yield scanUTXOs({ sochainUrl, haskoinUrl, network, address: sender, confirmedOnly, withTxHex });
|
|
85633
|
+
if (memo && memo.length > 80) {
|
|
85634
|
+
throw new Error('memo too long, must not be longer than 80 chars.');
|
|
85635
|
+
}
|
|
85713
85636
|
if (utxos.length === 0)
|
|
85714
|
-
throw new Error('No
|
|
85637
|
+
throw new Error('No confirmed UTXOs. Please wait until your balance has been confirmed on-chain.');
|
|
85715
85638
|
if (!validateAddress(recipient, network))
|
|
85716
85639
|
throw new Error('Invalid address');
|
|
85717
85640
|
const feeRateWhole = Math.ceil(feeRate);
|
|
@@ -85825,7 +85748,10 @@ class Client extends UTXOClient {
|
|
|
85825
85748
|
*
|
|
85826
85749
|
* @param {BitcoinClientParams} params
|
|
85827
85750
|
*/
|
|
85828
|
-
constructor({ network = Network.Testnet,
|
|
85751
|
+
constructor({ network = Network.Testnet, feeBounds = {
|
|
85752
|
+
lower: LOWER_FEE_BOUND,
|
|
85753
|
+
upper: UPPER_FEE_BOUND,
|
|
85754
|
+
}, sochainUrl = 'https://sochain.com/api/v2', haskoinUrl = {
|
|
85829
85755
|
[Network.Testnet]: 'https://api.haskoin.com/btctest',
|
|
85830
85756
|
[Network.Mainnet]: 'https://api.haskoin.com/btc',
|
|
85831
85757
|
[Network.Stagenet]: 'https://api.haskoin.com/btc',
|
|
@@ -85834,7 +85760,7 @@ class Client extends UTXOClient {
|
|
|
85834
85760
|
[Network.Testnet]: `84'/1'/0'/0/`,
|
|
85835
85761
|
[Network.Stagenet]: `84'/0'/0'/0/`,
|
|
85836
85762
|
}, phrase = '', }) {
|
|
85837
|
-
super(Chain.Bitcoin, { network, rootDerivationPaths, phrase });
|
|
85763
|
+
super(Chain.Bitcoin, { network, rootDerivationPaths, phrase, feeBounds });
|
|
85838
85764
|
this.sochainUrl = '';
|
|
85839
85765
|
this.setSochainUrl(sochainUrl);
|
|
85840
85766
|
this.haskoinUrl = haskoinUrl;
|
|
@@ -86052,12 +85978,15 @@ class Client extends UTXOClient {
|
|
|
86052
85978
|
*
|
|
86053
85979
|
* @param {TxParams&FeeRate} params The transfer options.
|
|
86054
85980
|
* @returns {TxHash} The transaction hash.
|
|
85981
|
+
*
|
|
85982
|
+
* @throws {"memo too long"} Thrown if memo longer than 80 chars.
|
|
86055
85983
|
*/
|
|
86056
85984
|
transfer(params) {
|
|
86057
85985
|
return __awaiter(this, void 0, void 0, function* () {
|
|
86058
85986
|
const fromAddressIndex = (params === null || params === void 0 ? void 0 : params.walletIndex) || 0;
|
|
86059
85987
|
// set the default fee rate to `fast`
|
|
86060
85988
|
const feeRate = params.feeRate || (yield this.getFeeRates())[FeeOption.Fast];
|
|
85989
|
+
checkFeeBounds(this.feeBounds, feeRate);
|
|
86061
85990
|
/**
|
|
86062
85991
|
* do not spend pending UTXOs when adding a memo
|
|
86063
85992
|
* https://github.com/xchainjs/xchainjs-lib/issues/330
|
|
@@ -86072,35 +86001,7 @@ class Client extends UTXOClient {
|
|
|
86072
86001
|
return yield broadcastTx$1({ txHex, haskoinUrl });
|
|
86073
86002
|
});
|
|
86074
86003
|
}
|
|
86075
|
-
/**
|
|
86076
|
-
* Transaction to THORChain inbound address.
|
|
86077
|
-
*
|
|
86078
|
-
* @param {DepositParams} params The transaction options.
|
|
86079
|
-
* @returns {TxHash} The transaction hash.
|
|
86080
|
-
*
|
|
86081
|
-
* @throws {"halted chain"} Thrown if chain is halted.
|
|
86082
|
-
* @throws {"halted trading"} Thrown if trading is halted.
|
|
86083
|
-
*/
|
|
86084
|
-
deposit({ walletIndex = 0, asset = AssetBTC, amount, memo }) {
|
|
86085
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
86086
|
-
const inboundDetails = yield getInboundDetails(asset.chain, this.network);
|
|
86087
|
-
if (inboundDetails.haltedChain) {
|
|
86088
|
-
throw new Error(`Halted chain for ${assetToString(asset)}`);
|
|
86089
|
-
}
|
|
86090
|
-
if (inboundDetails.haltedTrading) {
|
|
86091
|
-
throw new Error(`Halted trading for ${assetToString(asset)}`);
|
|
86092
|
-
}
|
|
86093
|
-
const txHash = yield this.transfer({
|
|
86094
|
-
walletIndex,
|
|
86095
|
-
asset,
|
|
86096
|
-
amount,
|
|
86097
|
-
recipient: inboundDetails.vault,
|
|
86098
|
-
memo,
|
|
86099
|
-
});
|
|
86100
|
-
return txHash;
|
|
86101
|
-
});
|
|
86102
|
-
}
|
|
86103
86004
|
}
|
|
86104
86005
|
|
|
86105
|
-
export { BTC_DECIMAL, Client, MIN_TX_FEE, broadcastTx$1 as broadcastTx, buildTx, calcFee, getBalance$2 as getBalance, getDefaultFees, getDefaultFeesWithRates, getPrefix, scanUTXOs, validateAddress };
|
|
86006
|
+
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 };
|
|
86106
86007
|
//# sourceMappingURL=index.esm.js.map
|