Skip to content

Commit

Permalink
chore: Add more info to error (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
gitferry committed Jul 17, 2023
1 parent 4103f9c commit 72e9e2b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions submitter/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ func (rl *Relayer) ChainTwoTxAndSend(
data1,
)
if err != nil {
return nil, nil, err
return nil, nil, fmt.Errorf("failed to add data to tx1: %w", err)
}

tx1.TxId, err = rl.sendTxToBTC(tx1.Tx)
if err != nil {
return nil, nil, err
return nil, nil, fmt.Errorf("failed to send tx1 to BTC: %w", err)
}

changeUtxo := &types.UTXO{
Expand All @@ -326,12 +326,12 @@ func (rl *Relayer) ChainTwoTxAndSend(
data2,
)
if err != nil {
return nil, nil, err
return nil, nil, fmt.Errorf("failed to add data to tx2: %w", err)
}

tx2.TxId, err = rl.sendTxToBTC(tx2.Tx)
if err != nil {
return nil, nil, err
return nil, nil, fmt.Errorf("failed to send tx2 to BTC: %w", err)
}

// TODO: if tx1 succeeds but tx2 fails, we should not resent tx1
Expand All @@ -341,10 +341,9 @@ func (rl *Relayer) ChainTwoTxAndSend(

// PickHighUTXO picks a UTXO that has the highest amount
func (rl *Relayer) PickHighUTXO() (*types.UTXO, error) {
log.Logger.Debugf("Searching for unspent transactions...")
utxos, err := rl.ListUnspent()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to list unspent UTXOs: %w", err)
}

if len(utxos) == 0 {
Expand Down Expand Up @@ -431,7 +430,7 @@ func (rl *Relayer) buildTxWithData(
// build txout for change
changeAddr, err := rl.GetChangeAddress()
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get change address: %w", err)
}
log.Logger.Debugf("Got a change address %v", changeAddr.String())
changeScript, err := txscript.PayToAddrScript(changeAddr)
Expand All @@ -455,7 +454,7 @@ func (rl *Relayer) buildTxWithData(
// sign tx
tx, err = rl.dumpPrivKeyAndSignTx(tx, utxo)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to sign tx: %w", err)
}

// serialization
Expand Down

0 comments on commit 72e9e2b

Please sign in to comment.