Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Aug 15, 2024
1 parent 24dc4c7 commit 6ecb235
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
23 changes: 7 additions & 16 deletions submitter/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,16 @@ func (rl *Relayer) ChainTwoTxAndSend(
return nil, nil, fmt.Errorf("failed to send tx1 to BTC: %w", err)
}

var txOut *wire.TxOut
if len(tx1.Tx.TxOut[0].PkScript) == addrSize {
txOut = tx1.Tx.TxOut[0]
} else {
txOut = tx1.Tx.TxOut[1]
changeIdx, err := IndexOfTxOut(tx1.Tx.TxOut, addrSize)
if err != nil {
return nil, nil, err
}

changeUtxo := &types.UTXO{
TxID: tx1.TxId,
Vout: 1,
ScriptPK: txOut.PkScript,
Amount: btcutil.Amount(txOut.Value),
ScriptPK: tx1.Tx.TxOut[changeIdx].PkScript,
Amount: btcutil.Amount(tx1.Tx.TxOut[changeIdx].Value),
Addr: tx1.ChangeAddress,
}

Expand Down Expand Up @@ -391,22 +389,15 @@ func (rl *Relayer) buildTxWithData(
rl.logger.Debugf("Building a BTC tx using %v with data %x", utxo.TxID.String(), data)
tx := wire.NewMsgTx(wire.TxVersion)

//outPoint := wire.NewOutPoint(utxo.TxID, utxo.Vout)
//txIn := wire.NewTxIn(outPoint, nil, nil)
// Enable replace-by-fee
// See https://river.com/learn/terms/r/replace-by-fee-rbf
//txIn.Sequence = math.MaxUint32 - 2
//tx.AddTxIn(txIn)

// build txout for data
// build txOut for data
builder := txscript.NewScriptBuilder()
dataScript, err := builder.AddOp(txscript.OP_RETURN).AddData(data).Script()
if err != nil {
return nil, err
}
tx.AddTxOut(wire.NewTxOut(0, dataScript))

// build txout for change
// build txOut for change
changeAddr, err := rl.GetChangeAddress()
if err != nil {
return nil, fmt.Errorf("failed to get change address: %w", err)
Expand Down
22 changes: 10 additions & 12 deletions types/utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
)

type UTXO struct {
TxID *chainhash.Hash
Vout uint32
ScriptPK []byte
Amount btcutil.Amount
Addr btcutil.Address
RedeemScript string
TxID *chainhash.Hash
Vout uint32
ScriptPK []byte
Amount btcutil.Amount
Addr btcutil.Address
}

func NewUTXO(r *btcjson.ListUnspentResult, net *chaincfg.Params) (*UTXO, error) {
Expand All @@ -38,12 +37,11 @@ func NewUTXO(r *btcjson.ListUnspentResult, net *chaincfg.Params) (*UTXO, error)
}

utxo := &UTXO{
TxID: txID,
Vout: r.Vout,
ScriptPK: prevPKScript,
Amount: amount,
Addr: prevAddr,
RedeemScript: r.RedeemScript,
TxID: txID,
Vout: r.Vout,
ScriptPK: prevPKScript,
Amount: amount,
Addr: prevAddr,
}
return utxo, nil
}
Expand Down

0 comments on commit 6ecb235

Please sign in to comment.