@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/client.d.ts CHANGED
@@ -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,6 +108,8 @@ 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;
@@ -120,6 +122,7 @@ declare class Client extends UTXOClient {
120
122
  *
121
123
  * @throws {"halted chain"} Thrown if chain is halted.
122
124
  * @throws {"halted trading"} Thrown if trading is halted.
125
+ * @throws {"memo too long"} Thrown if memo longer than 80 chars.
123
126
  */
124
127
  deposit({ walletIndex, asset, amount, memo }: DepositParams): Promise<TxHash>;
125
128
  }
package/lib/const.d.ts CHANGED
@@ -5,3 +5,5 @@
5
5
  */
6
6
  export declare const MIN_TX_FEE = 1000;
7
7
  export declare const BTC_DECIMAL = 8;
8
+ export declare const LOWER_FEE_BOUND = 1;
9
+ export declare const UPPER_FEE_BOUND = 500;
package/lib/index.esm.js CHANGED
@@ -1,4 +1,4 @@
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';
@@ -85152,7 +85152,9 @@ var src_12 = src$3.TransactionBuilder;
85152
85152
  * @see https://github.com/bitcoin/bitcoin/blob/db88db47278d2e7208c50d16ab10cb355067d071/src/validation.h#L56
85153
85153
  */
85154
85154
  const MIN_TX_FEE = 1000;
85155
- const BTC_DECIMAL = 8;
85155
+ const BTC_DECIMAL = 8;
85156
+ const LOWER_FEE_BOUND = 1;
85157
+ const UPPER_FEE_BOUND = 500;
85156
85158
 
85157
85159
  const DEFAULT_SUGGESTED_TRANSACTION_FEE = 127;
85158
85160
  const toSochainNetwork = (network) => {
@@ -85710,8 +85712,11 @@ withTxHex = false, }) => __awaiter(void 0, void 0, void 0, function* () {
85710
85712
  // search only confirmed UTXOs if pending UTXO is not allowed
85711
85713
  const confirmedOnly = !spendPendingUTXO;
85712
85714
  const utxos = yield scanUTXOs({ sochainUrl, haskoinUrl, network, address: sender, confirmedOnly, withTxHex });
85715
+ if (memo && memo.length > 80) {
85716
+ throw new Error('memo too long, must not be longer than 80 chars.');
85717
+ }
85713
85718
  if (utxos.length === 0)
85714
- throw new Error('No utxos to send');
85719
+ throw new Error('No confirmed UTXOs. Please wait until your balance has been confirmed on-chain.');
85715
85720
  if (!validateAddress(recipient, network))
85716
85721
  throw new Error('Invalid address');
85717
85722
  const feeRateWhole = Math.ceil(feeRate);
@@ -85825,7 +85830,10 @@ class Client extends UTXOClient {
85825
85830
  *
85826
85831
  * @param {BitcoinClientParams} params
85827
85832
  */
85828
- constructor({ network = Network.Testnet, sochainUrl = 'https://sochain.com/api/v2', haskoinUrl = {
85833
+ constructor({ network = Network.Testnet, feeBounds = {
85834
+ lower: LOWER_FEE_BOUND,
85835
+ upper: UPPER_FEE_BOUND,
85836
+ }, sochainUrl = 'https://sochain.com/api/v2', haskoinUrl = {
85829
85837
  [Network.Testnet]: 'https://api.haskoin.com/btctest',
85830
85838
  [Network.Mainnet]: 'https://api.haskoin.com/btc',
85831
85839
  [Network.Stagenet]: 'https://api.haskoin.com/btc',
@@ -85834,7 +85842,7 @@ class Client extends UTXOClient {
85834
85842
  [Network.Testnet]: `84'/1'/0'/0/`,
85835
85843
  [Network.Stagenet]: `84'/0'/0'/0/`,
85836
85844
  }, phrase = '', }) {
85837
- super(Chain.Bitcoin, { network, rootDerivationPaths, phrase });
85845
+ super(Chain.Bitcoin, { network, rootDerivationPaths, phrase, feeBounds });
85838
85846
  this.sochainUrl = '';
85839
85847
  this.setSochainUrl(sochainUrl);
85840
85848
  this.haskoinUrl = haskoinUrl;
@@ -86052,12 +86060,15 @@ class Client extends UTXOClient {
86052
86060
  *
86053
86061
  * @param {TxParams&FeeRate} params The transfer options.
86054
86062
  * @returns {TxHash} The transaction hash.
86063
+ *
86064
+ * @throws {"memo too long"} Thrown if memo longer than 80 chars.
86055
86065
  */
86056
86066
  transfer(params) {
86057
86067
  return __awaiter(this, void 0, void 0, function* () {
86058
86068
  const fromAddressIndex = (params === null || params === void 0 ? void 0 : params.walletIndex) || 0;
86059
86069
  // set the default fee rate to `fast`
86060
86070
  const feeRate = params.feeRate || (yield this.getFeeRates())[FeeOption.Fast];
86071
+ checkFeeBounds(this.feeBounds, feeRate);
86061
86072
  /**
86062
86073
  * do not spend pending UTXOs when adding a memo
86063
86074
  * https://github.com/xchainjs/xchainjs-lib/issues/330
@@ -86080,6 +86091,7 @@ class Client extends UTXOClient {
86080
86091
  *
86081
86092
  * @throws {"halted chain"} Thrown if chain is halted.
86082
86093
  * @throws {"halted trading"} Thrown if trading is halted.
86094
+ * @throws {"memo too long"} Thrown if memo longer than 80 chars.
86083
86095
  */
86084
86096
  deposit({ walletIndex = 0, asset = AssetBTC, amount, memo }) {
86085
86097
  return __awaiter(this, void 0, void 0, function* () {
@@ -86102,5 +86114,5 @@ class Client extends UTXOClient {
86102
86114
  }
86103
86115
  }
86104
86116
 
86105
- export { BTC_DECIMAL, Client, MIN_TX_FEE, broadcastTx$1 as broadcastTx, buildTx, calcFee, getBalance$2 as getBalance, getDefaultFees, getDefaultFeesWithRates, getPrefix, scanUTXOs, validateAddress };
86117
+ 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
86118
  //# sourceMappingURL=index.esm.js.map