Skip to content

Commit

Permalink
feat: improve naming and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba-4chain committed Jul 3, 2024
1 parent b49476c commit ab59e30
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/simple/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type SimplePeerHandler struct {
logger *slog.Logger
}

func (s *SimplePeerHandler) HandleTransactionsGet(msg []*wire.InvVect, peer p2p.PeerI) ([][]byte, error) {
s.logger.Info("Peer requested transactions", slog.Int("count", len(msg)), slog.String("peer", peer.String()))
func (s *SimplePeerHandler) HandleTransactionsGet(msgs []*wire.InvVect, peer p2p.PeerI) ([][]byte, error) {
s.logger.Info("Peer requested transactions", slog.Int("count", len(msgs)), slog.String("peer", peer.String()))
// You should implement a store and return the transactions bytes here.
return nil, fmt.Errorf("transactions not found")
}
Expand Down
6 changes: 2 additions & 4 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"github.com/libsv/go-p2p/wire"
)

var (
ErrPeerNetworkMismatch = fmt.Errorf("peer network mismatch")
)
var ErrPeerNetworkMismatch = fmt.Errorf("peer network mismatch")

type PeerManagerI interface {
AnnounceTransaction(txHash *chainhash.Hash, peers []PeerI) []PeerI
Expand All @@ -36,7 +34,7 @@ type PeerI interface {
}

type PeerHandlerI interface {
HandleTransactionsGet(msg []*wire.InvVect, peer PeerI) ([][]byte, error)
HandleTransactionsGet(msgs []*wire.InvVect, peer PeerI) ([][]byte, error)
HandleTransactionSent(msg *wire.MsgTx, peer PeerI) error
HandleTransactionAnnouncement(msg *wire.InvVect, peer PeerI) error
HandleTransactionRejection(rejMsg *wire.MsgReject, peer PeerI) error
Expand Down
2 changes: 1 addition & 1 deletion peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ func (p *Peer) handleGetDataMsg(dataMsg *wire.MsgGetData, logger *slog.Logger) {

rawTxs, err := p.peerHandler.HandleTransactionsGet(txRequests, p)
if err != nil {
logger.Warn("Unable to fetch txs from store", slog.String(errKey, err.Error()))
logger.Warn("Unable to fetch txs from store", slog.Int("count", len(txRequests)), slog.String(errKey, err.Error()))
return
}

Expand Down
20 changes: 10 additions & 10 deletions peer_handler_gen_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ab59e30

Please sign in to comment.