Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions zetaclient/chains/bitcoin/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,6 @@ func (ob *Observer) CheckReceiptForBtcTxHash(ctx context.Context, txHash string,
return "", fmt.Errorf("block %d is not confirmed yet", blockVb.Height)
}

// calculate depositor fee
depositorFee, err := bitcoin.CalcDepositorFee(ob.btcClient, tx, ob.netParams)
if err != nil {
return "", errors.Wrapf(err, "error calculating depositor fee for inbound %s", tx.Txid)
}

// #nosec G115 always positive
event, err := GetBtcEvent(
ob.btcClient,
Expand All @@ -268,7 +262,6 @@ func (ob *Observer) CheckReceiptForBtcTxHash(ctx context.Context, txHash string,
uint64(blockVb.Height),
ob.logger.Inbound,
ob.netParams,
depositorFee,
)
if err != nil {
return "", err
Expand Down Expand Up @@ -322,13 +315,7 @@ func FilterAndParseIncomingTx(
continue // the first tx is coinbase; we do not process coinbase tx
}

// calculate depositor fee
depositorFee, err := bitcoin.CalcDepositorFee(rpcClient, &txs[idx], netParams)
if err != nil {
return nil, errors.Wrapf(err, "error calculating depositor fee for inbound %s", tx.Txid)
}

event, err := GetBtcEvent(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee)
event, err := GetBtcEvent(rpcClient, tx, tssAddress, blockNumber, logger, netParams)
if err != nil {
// unable to parse the tx, the caller should retry
return nil, errors.Wrapf(err, "error getting btc event for tx %s in block %d", tx.Txid, blockNumber)
Expand Down Expand Up @@ -390,12 +377,11 @@ func GetBtcEvent(
blockNumber uint64,
logger zerolog.Logger,
netParams *chaincfg.Params,
depositorFee float64,
) (*BTCInboundEvent, error) {
if netParams.Name == chaincfg.MainNetParams.Name {
return GetBtcEventWithoutWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee)
return GetBtcEventWithoutWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams)
}
return GetBtcEventWithWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams, depositorFee)
return GetBtcEventWithWitness(rpcClient, tx, tssAddress, blockNumber, logger, netParams)
}

// GetBtcEventWithoutWitness either returns a valid BTCInboundEvent or nil
Expand All @@ -408,11 +394,14 @@ func GetBtcEventWithoutWitness(
blockNumber uint64,
logger zerolog.Logger,
netParams *chaincfg.Params,
depositorFee float64,
) (*BTCInboundEvent, error) {
found := false
var value float64
var memo []byte
var (
found = false
value float64
depositorFee float64
memo []byte
)

if len(tx.Vout) >= 2 {
// 1st vout must have tss address as receiver with p2wpkh scriptPubKey
vout0 := tx.Vout[0]
Expand All @@ -429,6 +418,12 @@ func GetBtcEventWithoutWitness(
return nil, nil
}

// calculate depositor fee
depositorFee, err := bitcoin.CalcDepositorFee(rpcClient, &tx, netParams)
if err != nil {
return nil, errors.Wrapf(err, "error calculating depositor fee for inbound %s", tx.Txid)
}

// deposit amount has to be no less than the minimum depositor fee
if vout0.Value < depositorFee {
logger.Info().
Expand Down
Loading