From 861f2a7f8b5028836a091a3ef332c8a0e48cefeb Mon Sep 17 00:00:00 2001 From: charliec Date: Fri, 22 Sep 2023 16:15:30 -0500 Subject: [PATCH] allow 0-value UTXO in unspent list --- zetaclient/bitcoin_client.go | 5 ++--- zetaclient/utils.go | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/zetaclient/bitcoin_client.go b/zetaclient/bitcoin_client.go index bc79712283..b90428a544 100644 --- a/zetaclient/bitcoin_client.go +++ b/zetaclient/bitcoin_client.go @@ -940,9 +940,8 @@ func (ob *BitcoinChainClient) ValidateCctxParams(params *types.OutboundTxParams) } // validate amount - _, err = getSatoshis(float64(params.Amount.Uint64()) / 1e8) - if err != nil { - return fmt.Errorf("ValidateCctxParams: invalid amount %d", params.Amount) + if params.Amount.Uint64() == 0 { + return fmt.Errorf("ValidateCctxParams: zero amount not allowed in cctx") } return nil } diff --git a/zetaclient/utils.go b/zetaclient/utils.go index 108ce4239c..3b01d3262a 100644 --- a/zetaclient/utils.go +++ b/zetaclient/utils.go @@ -16,7 +16,7 @@ const ( func getSatoshis(btc float64) (int64, error) { // The amount is only considered invalid if it cannot be represented // as an integer type. This may happen if f is NaN or +-Infinity. - // BTC max amount is 21 mil and its at least 10^(-8) or one satoshi. + // BTC max amount is 21 mil and its at least 0 (Note: bitcoin allows creating 0 value outputs) switch { case math.IsNaN(btc): fallthrough @@ -26,8 +26,8 @@ func getSatoshis(btc float64) (int64, error) { return 0, errors.New("invalid bitcoin amount") case btc > 21000000.0: return 0, errors.New("exceeded max bitcoin amount") - case btc < 0.00000001: - return 0, errors.New("cannot be less than 1 satoshi") + case btc < 0.0: + return 0, errors.New("cannot be less than zero") } return round(btc * satoshiPerBitcoin), nil }