From 633e12ced8ccd92cbd70856b2f08c2864b8836f7 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 23 Feb 2024 22:30:20 +0800 Subject: [PATCH] chain: use `GetTxSpendingPrevOut` in bitcoind events --- chain/bitcoind_zmq_events.go | 40 +----------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/chain/bitcoind_zmq_events.go b/chain/bitcoind_zmq_events.go index 0f8b2f5b91..66e1f3388c 100644 --- a/chain/bitcoind_zmq_events.go +++ b/chain/bitcoind_zmq_events.go @@ -2,7 +2,6 @@ package chain import ( "bytes" - "encoding/json" "fmt" "io" "math/rand" @@ -219,22 +218,6 @@ func (b *bitcoindZMQEvents) BlockNotifications() <-chan *wire.MsgBlock { return b.blockNtfns } -// getTxSpendingPrevOutReq is the rpc request format for bitcoind's -// gettxspendingprevout call. -type getTxSpendingPrevOutReq struct { - Txid string `json:"txid"` - Vout uint32 `json:"vout"` -} - -// getTxSpendingPrevOutResp is the rpc response format for bitcoind's -// gettxspendingprevout call. It returns the "spendingtxid" if one exists in -// the mempool. -type getTxSpendingPrevOutResp struct { - Txid string `json:"txid"` - Vout float64 `json:"vout"` - SpendingTxid string `json:"spendingtxid"` -} - // LookupInputSpend returns the transaction that spends the given outpoint // found in the mempool. func (b *bitcoindZMQEvents) LookupInputSpend( @@ -501,28 +484,7 @@ func (b *bitcoindZMQEvents) mempoolPoller() { func getTxSpendingPrevOut(op wire.OutPoint, client *rpcclient.Client) (chainhash.Hash, bool) { - prevoutReq := &getTxSpendingPrevOutReq{ - Txid: op.Hash.String(), Vout: op.Index, - } - - // The RPC takes an array of prevouts so we have an array with a single - // item since we don't yet batch calls to LookupInputSpend. - prevoutArr := []*getTxSpendingPrevOutReq{prevoutReq} - - req, err := json.Marshal(prevoutArr) - if err != nil { - return chainhash.Hash{}, false - } - - resp, err := client.RawRequest( - "gettxspendingprevout", []json.RawMessage{req}, - ) - if err != nil { - return chainhash.Hash{}, false - } - - var prevoutResps []getTxSpendingPrevOutResp - err = json.Unmarshal(resp, &prevoutResps) + prevoutResps, err := client.GetTxSpendingPrevOut([]wire.OutPoint{op}) if err != nil { return chainhash.Hash{}, false }