@xchainjs/xchain-bitcoin 0.18.2 → 0.18.4

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/index.js CHANGED
@@ -85166,7 +85166,9 @@ var src_12 = src$3.TransactionBuilder;
85166
85166
  * @see https://github.com/bitcoin/bitcoin/blob/db88db47278d2e7208c50d16ab10cb355067d071/src/validation.h#L56
85167
85167
  */
85168
85168
  const MIN_TX_FEE = 1000;
85169
- const BTC_DECIMAL = 8;
85169
+ const BTC_DECIMAL = 8;
85170
+ const LOWER_FEE_BOUND = 1;
85171
+ const UPPER_FEE_BOUND = 500;
85170
85172
 
85171
85173
  const DEFAULT_SUGGESTED_TRANSACTION_FEE = 127;
85172
85174
  const toSochainNetwork = (network) => {
@@ -85724,8 +85726,11 @@ withTxHex = false, }) => __awaiter(void 0, void 0, void 0, function* () {
85724
85726
  // search only confirmed UTXOs if pending UTXO is not allowed
85725
85727
  const confirmedOnly = !spendPendingUTXO;
85726
85728
  const utxos = yield scanUTXOs({ sochainUrl, haskoinUrl, network, address: sender, confirmedOnly, withTxHex });
85729
+ if (memo && memo.length > 80) {
85730
+ throw new Error('memo too long, must not be longer than 80 chars.');
85731
+ }
85727
85732
  if (utxos.length === 0)
85728
- throw new Error('No utxos to send');
85733
+ throw new Error('No confirmed UTXOs. Please wait until your balance has been confirmed on-chain.');
85729
85734
  if (!validateAddress(recipient, network))
85730
85735
  throw new Error('Invalid address');
85731
85736
  const feeRateWhole = Math.ceil(feeRate);
@@ -85839,7 +85844,10 @@ class Client extends xchainClient.UTXOClient {
85839
85844
  *
85840
85845
  * @param {BitcoinClientParams} params
85841
85846
  */
85842
- constructor({ network = xchainClient.Network.Testnet, sochainUrl = 'https://sochain.com/api/v2', haskoinUrl = {
85847
+ constructor({ network = xchainClient.Network.Testnet, feeBounds = {
85848
+ lower: LOWER_FEE_BOUND,
85849
+ upper: UPPER_FEE_BOUND,
85850
+ }, sochainUrl = 'https://sochain.com/api/v2', haskoinUrl = {
85843
85851
  [xchainClient.Network.Testnet]: 'https://api.haskoin.com/btctest',
85844
85852
  [xchainClient.Network.Mainnet]: 'https://api.haskoin.com/btc',
85845
85853
  [xchainClient.Network.Stagenet]: 'https://api.haskoin.com/btc',
@@ -85848,7 +85856,7 @@ class Client extends xchainClient.UTXOClient {
85848
85856
  [xchainClient.Network.Testnet]: `84'/1'/0'/0/`,
85849
85857
  [xchainClient.Network.Stagenet]: `84'/0'/0'/0/`,
85850
85858
  }, phrase = '', }) {
85851
- super(Chain.Bitcoin, { network, rootDerivationPaths, phrase });
85859
+ super(Chain.Bitcoin, { network, rootDerivationPaths, phrase, feeBounds });
85852
85860
  this.sochainUrl = '';
85853
85861
  this.setSochainUrl(sochainUrl);
85854
85862
  this.haskoinUrl = haskoinUrl;
@@ -86066,12 +86074,15 @@ class Client extends xchainClient.UTXOClient {
86066
86074
  *
86067
86075
  * @param {TxParams&FeeRate} params The transfer options.
86068
86076
  * @returns {TxHash} The transaction hash.
86077
+ *
86078
+ * @throws {"memo too long"} Thrown if memo longer than 80 chars.
86069
86079
  */
86070
86080
  transfer(params) {
86071
86081
  return __awaiter(this, void 0, void 0, function* () {
86072
86082
  const fromAddressIndex = (params === null || params === void 0 ? void 0 : params.walletIndex) || 0;
86073
86083
  // set the default fee rate to `fast`
86074
86084
  const feeRate = params.feeRate || (yield this.getFeeRates())[xchainClient.FeeOption.Fast];
86085
+ xchainClient.checkFeeBounds(this.feeBounds, feeRate);
86075
86086
  /**
86076
86087
  * do not spend pending UTXOs when adding a memo
86077
86088
  * https://github.com/xchainjs/xchainjs-lib/issues/330
@@ -86094,6 +86105,7 @@ class Client extends xchainClient.UTXOClient {
86094
86105
  *
86095
86106
  * @throws {"halted chain"} Thrown if chain is halted.
86096
86107
  * @throws {"halted trading"} Thrown if trading is halted.
86108
+ * @throws {"memo too long"} Thrown if memo longer than 80 chars.
86097
86109
  */
86098
86110
  deposit({ walletIndex = 0, asset = AssetBTC, amount, memo }) {
86099
86111
  return __awaiter(this, void 0, void 0, function* () {
@@ -86118,7 +86130,9 @@ class Client extends xchainClient.UTXOClient {
86118
86130
 
86119
86131
  exports.BTC_DECIMAL = BTC_DECIMAL;
86120
86132
  exports.Client = Client;
86133
+ exports.LOWER_FEE_BOUND = LOWER_FEE_BOUND;
86121
86134
  exports.MIN_TX_FEE = MIN_TX_FEE;
86135
+ exports.UPPER_FEE_BOUND = UPPER_FEE_BOUND;
86122
86136
  exports.broadcastTx = broadcastTx$1;
86123
86137
  exports.buildTx = buildTx;
86124
86138
  exports.calcFee = calcFee;