chain: extract ZMQ command strings into constants
This commit is contained in:
parent
7abdd4f8ad
commit
36ca842905
1 changed files with 23 additions and 12 deletions
|
@ -16,6 +16,16 @@ import (
|
||||||
"github.com/lightninglabs/gozmq"
|
"github.com/lightninglabs/gozmq"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// rawBlockZMQCommand is the command used to receive raw block
|
||||||
|
// notifications from bitcoind through ZMQ.
|
||||||
|
rawBlockZMQCommand = "rawblock"
|
||||||
|
|
||||||
|
// rawTxZMQCommand is the command used to receive raw transaction
|
||||||
|
// notifications from bitcoind through ZMQ.
|
||||||
|
rawTxZMQCommand = "rawtx"
|
||||||
|
)
|
||||||
|
|
||||||
// BitcoindConn represents a persistent client connection to a bitcoind node
|
// BitcoindConn represents a persistent client connection to a bitcoind node
|
||||||
// that listens for events read from a ZMQ connection.
|
// that listens for events read from a ZMQ connection.
|
||||||
type BitcoindConn struct {
|
type BitcoindConn struct {
|
||||||
|
@ -79,7 +89,7 @@ func NewBitcoindConn(chainParams *chaincfg.Params,
|
||||||
// concern to ensure one type of event isn't dropped from the connection
|
// concern to ensure one type of event isn't dropped from the connection
|
||||||
// queue due to another type of event filling it up.
|
// queue due to another type of event filling it up.
|
||||||
zmqBlockConn, err := gozmq.Subscribe(
|
zmqBlockConn, err := gozmq.Subscribe(
|
||||||
zmqBlockHost, []string{"rawblock"}, zmqPollInterval,
|
zmqBlockHost, []string{rawBlockZMQCommand}, zmqPollInterval,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to subscribe for zmq block "+
|
return nil, fmt.Errorf("unable to subscribe for zmq block "+
|
||||||
|
@ -87,7 +97,7 @@ func NewBitcoindConn(chainParams *chaincfg.Params,
|
||||||
}
|
}
|
||||||
|
|
||||||
zmqTxConn, err := gozmq.Subscribe(
|
zmqTxConn, err := gozmq.Subscribe(
|
||||||
zmqTxHost, []string{"rawtx"}, zmqPollInterval,
|
zmqTxHost, []string{rawTxZMQCommand}, zmqPollInterval,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
zmqBlockConn.Close()
|
zmqBlockConn.Close()
|
||||||
|
@ -190,8 +200,8 @@ func (c *BitcoindConn) blockEventHandler() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Errorf("Unable to receive ZMQ rawblock message: %v",
|
log.Errorf("Unable to receive ZMQ %v message: %v",
|
||||||
err)
|
rawBlockZMQCommand, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +210,7 @@ func (c *BitcoindConn) blockEventHandler() {
|
||||||
// clients.
|
// clients.
|
||||||
eventType := string(msgBytes[0])
|
eventType := string(msgBytes[0])
|
||||||
switch eventType {
|
switch eventType {
|
||||||
case "rawblock":
|
case rawBlockZMQCommand:
|
||||||
block := &wire.MsgBlock{}
|
block := &wire.MsgBlock{}
|
||||||
r := bytes.NewReader(msgBytes[1])
|
r := bytes.NewReader(msgBytes[1])
|
||||||
if err := block.Deserialize(r); err != nil {
|
if err := block.Deserialize(r); err != nil {
|
||||||
|
@ -229,8 +239,9 @@ func (c *BitcoindConn) blockEventHandler() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Warnf("Received unexpected event type from "+
|
log.Warnf("Received unexpected event type from %v "+
|
||||||
"rawblock subscription: %v", eventType)
|
"subscription: %v", rawBlockZMQCommand,
|
||||||
|
eventType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,8 +282,8 @@ func (c *BitcoindConn) txEventHandler() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Errorf("Unable to receive ZMQ rawtx message: %v",
|
log.Errorf("Unable to receive ZMQ %v message: %v",
|
||||||
err)
|
rawTxZMQCommand, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +292,7 @@ func (c *BitcoindConn) txEventHandler() {
|
||||||
// clients.
|
// clients.
|
||||||
eventType := string(msgBytes[0])
|
eventType := string(msgBytes[0])
|
||||||
switch eventType {
|
switch eventType {
|
||||||
case "rawtx":
|
case rawTxZMQCommand:
|
||||||
tx := &wire.MsgTx{}
|
tx := &wire.MsgTx{}
|
||||||
r := bytes.NewReader(msgBytes[1])
|
r := bytes.NewReader(msgBytes[1])
|
||||||
if err := tx.Deserialize(r); err != nil {
|
if err := tx.Deserialize(r); err != nil {
|
||||||
|
@ -310,8 +321,8 @@ func (c *BitcoindConn) txEventHandler() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Warnf("Received unexpected event type from rawtx "+
|
log.Warnf("Received unexpected event type from %v "+
|
||||||
"subscription: %v", eventType)
|
"subscription: %v", rawTxZMQCommand, eventType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue