Skip to content

Commit

Permalink
chain+wallet: add TestMempoolAccept to chain interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Jan 5, 2024
1 parent c662e15 commit 7312742
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
10 changes: 10 additions & 0 deletions chain/bitcoind_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ func (c *BitcoindClient) SendRawTransaction(tx *wire.MsgTx,
return c.chainConn.client.SendRawTransaction(tx, allowHighFees)
}

// TestMempoolAcceptCmd returns result of mempool acceptance tests indicating
// if raw transaction(s) would be accepted by mempool.
//
// NOTE: This is part of the chain.Interface interface.
func (c *BitcoindClient) TestMempoolAccept(txns []*wire.MsgTx,
maxFeeRate float64) ([]*btcjson.TestMempoolAcceptResult, error) {

return c.chainConn.client.TestMempoolAccept(txns, maxFeeRate)
}

// Notifications returns a channel to retrieve notifications from.
//
// NOTE: This is part of the chain.Interface interface.
Expand Down
4 changes: 4 additions & 0 deletions chain/btcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type RPCClient struct {
quitMtx sync.Mutex
}

// A compile-time check to ensure that RPCClient satisfies the chain.Interface
// interface.
var _ Interface = (*RPCClient)(nil)

// NewRPCClient creates a client connection to the server described by the
// connect string. If disableTLS is false, the remote RPC certificate must be
// provided in the certs slice. The connection is not established immediately,
Expand Down
2 changes: 2 additions & 0 deletions chain/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package chain
import (
"time"

"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
Expand Down Expand Up @@ -47,6 +48,7 @@ type Interface interface {
NotifyBlocks() error
Notifications() <-chan interface{}
BackEnd() string
TestMempoolAccept([]*wire.MsgTx, float64) ([]*btcjson.TestMempoolAcceptResult, error)
}

// Notification types. These are defined here and processed from from reading
Expand Down
19 changes: 19 additions & 0 deletions chain/neutrino.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sync"
"time"

"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/btcutil/gcs"
"github.com/btcsuite/btcd/btcutil/gcs/builder"
Expand All @@ -20,6 +21,10 @@ import (
"github.com/lightninglabs/neutrino/headerfs"
)

// ErrUnimplemented is returned when a certain method is not implemented for a
// given interface.
var ErrUnimplemented = errors.New("unimplemented")

// NeutrinoClient is an implementation of the btcwallet chain.Interface interface.
type NeutrinoClient struct {
CS NeutrinoChainService
Expand Down Expand Up @@ -63,6 +68,10 @@ type NeutrinoClient struct {
clientMtx sync.Mutex
}

// A compile-time check to ensure that RPCClient satisfies the chain.Interface
// interface.
var _ Interface = (*NeutrinoClient)(nil)

// NewNeutrinoClient creates a new NeutrinoClient struct with a backing
// ChainService.
func NewNeutrinoClient(chainParams *chaincfg.Params,
Expand Down Expand Up @@ -217,6 +226,16 @@ func (s *NeutrinoClient) SendRawTransaction(tx *wire.MsgTx, allowHighFees bool)
return &hash, nil
}

// TestMempoolAcceptCmd returns result of mempool acceptance tests indicating
// if raw transaction(s) would be accepted by mempool.
//
// NOTE: This is part of the chain.Interface interface.
func (s *NeutrinoClient) TestMempoolAccept(txns []*wire.MsgTx,
maxFeeRate float64) ([]*btcjson.TestMempoolAcceptResult, error) {

return nil, ErrUnimplemented
}

// FilterBlocks scans the blocks contained in the FilterBlocksRequest for any
// addresses of interest. For each requested block, the corresponding compact
// filter will first be checked for matches, skipping those that do not report
Expand Down
11 changes: 11 additions & 0 deletions wallet/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wallet
import (
"time"

"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
Expand Down Expand Up @@ -83,3 +84,13 @@ func (m *mockChainClient) Notifications() <-chan interface{} {
func (m *mockChainClient) BackEnd() string {
return "mock"
}

// TestMempoolAcceptCmd returns result of mempool acceptance tests indicating
// if raw transaction(s) would be accepted by mempool.
//
// NOTE: This is part of the chain.Interface interface.
func (m *mockChainClient) TestMempoolAccept(txns []*wire.MsgTx,
maxFeeRate float64) ([]*btcjson.TestMempoolAcceptResult, error) {

return nil, nil
}

0 comments on commit 7312742

Please sign in to comment.