Skip to content

Commit

Permalink
allow 0-value UTXO in unspent list
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Sep 22, 2023
1 parent 9c1364d commit 861f2a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 2 additions & 3 deletions zetaclient/bitcoin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions zetaclient/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 861f2a7

Please sign in to comment.