Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions bchain/coins/btc/bitcoinrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,33 @@ type BitcoinRPC struct {

// Configuration represents json config file
type Configuration struct {
CoinName string `json:"coin_name"`
CoinShortcut string `json:"coin_shortcut"`
RPCURL string `json:"rpc_url"`
RPCUser string `json:"rpc_user"`
RPCPass string `json:"rpc_pass"`
RPCTimeout int `json:"rpc_timeout"`
AddressAliases bool `json:"address_aliases,omitempty"`
Parse bool `json:"parse"`
MessageQueueBinding string `json:"message_queue_binding"`
Subversion string `json:"subversion"`
BlockAddressesToKeep int `json:"block_addresses_to_keep"`
MempoolWorkers int `json:"mempool_workers"`
MempoolSubWorkers int `json:"mempool_sub_workers"`
AddressFormat string `json:"address_format"`
SupportsEstimateFee bool `json:"supports_estimate_fee"`
SupportsEstimateSmartFee bool `json:"supports_estimate_smart_fee"`
XPubMagic uint32 `json:"xpub_magic,omitempty"`
XPubMagicSegwitP2sh uint32 `json:"xpub_magic_segwit_p2sh,omitempty"`
XPubMagicSegwitNative uint32 `json:"xpub_magic_segwit_native,omitempty"`
Slip44 uint32 `json:"slip44,omitempty"`
AlternativeEstimateFee string `json:"alternative_estimate_fee,omitempty"`
AlternativeEstimateFeeParams string `json:"alternative_estimate_fee_params,omitempty"`
MinimumCoinbaseConfirmations int `json:"minimumCoinbaseConfirmations,omitempty"`
MempoolGolombFilterP uint8 `json:"mempool_golomb_filter_p,omitempty"`
MempoolFilterScripts string `json:"mempool_filter_scripts,omitempty"`
MempoolFilterUseZeroedKey bool `json:"mempool_filter_use_zeroed_key,omitempty"`
CoinName string `json:"coin_name"`
CoinShortcut string `json:"coin_shortcut"`
RPCURL string `json:"rpc_url"`
RPCUser string `json:"rpc_user"`
RPCPass string `json:"rpc_pass"`
RPCTimeout int `json:"rpc_timeout"`
AddressAliases bool `json:"address_aliases,omitempty"`
Parse bool `json:"parse"`
MessageQueueBinding string `json:"message_queue_binding"`
MessageQueueCurve *bchain.CurveConfig `json:"message_queue_curve"`
Subversion string `json:"subversion"`
BlockAddressesToKeep int `json:"block_addresses_to_keep"`
MempoolWorkers int `json:"mempool_workers"`
MempoolSubWorkers int `json:"mempool_sub_workers"`
AddressFormat string `json:"address_format"`
SupportsEstimateFee bool `json:"supports_estimate_fee"`
SupportsEstimateSmartFee bool `json:"supports_estimate_smart_fee"`
XPubMagic uint32 `json:"xpub_magic,omitempty"`
XPubMagicSegwitP2sh uint32 `json:"xpub_magic_segwit_p2sh,omitempty"`
XPubMagicSegwitNative uint32 `json:"xpub_magic_segwit_native,omitempty"`
Slip44 uint32 `json:"slip44,omitempty"`
AlternativeEstimateFee string `json:"alternative_estimate_fee,omitempty"`
AlternativeEstimateFeeParams string `json:"alternative_estimate_fee_params,omitempty"`
MinimumCoinbaseConfirmations int `json:"minimumCoinbaseConfirmations,omitempty"`
MempoolGolombFilterP uint8 `json:"mempool_golomb_filter_p,omitempty"`
MempoolFilterScripts string `json:"mempool_filter_scripts,omitempty"`
MempoolFilterUseZeroedKey bool `json:"mempool_filter_use_zeroed_key,omitempty"`
}

// NewBitcoinRPC returns new BitcoinRPC instance.
Expand Down Expand Up @@ -190,7 +191,7 @@ func (b *BitcoinRPC) InitializeMempool(addrDescForOutpoint bchain.AddrDescForOut
b.Mempool.OnNewTxAddr = onNewTxAddr
b.Mempool.OnNewTx = onNewTx
if b.mq == nil {
mq, err := bchain.NewMQ(b.ChainConfig.MessageQueueBinding, b.pushHandler)
mq, err := bchain.NewMQ(b.ChainConfig.MessageQueueBinding, b.ChainConfig.MessageQueueCurve, b.pushHandler)
if err != nil {
glog.Error("mq: ", err)
return err
Expand Down
34 changes: 33 additions & 1 deletion bchain/mq.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ type MQ struct {
binding string
}

type CurveConfig struct {
PublicKey string `json:"public_key"`
PrivateKey string `json:"private_key"`
ServerKey string `json:"server_key"`
}

// NotificationType is type of notification
type NotificationType int

Expand All @@ -32,7 +38,7 @@ const (

// NewMQ creates new Bitcoind ZeroMQ listener
// callback function receives messages
func NewMQ(binding string, callback func(NotificationType)) (*MQ, error) {
func NewMQ(binding string, curve *CurveConfig, callback func(NotificationType)) (*MQ, error) {
context, err := zmq.NewContext()
if err != nil {
return nil, err
Expand All @@ -49,6 +55,32 @@ func NewMQ(binding string, callback func(NotificationType)) (*MQ, error) {
if err != nil {
return nil, err
}

if curve != nil {
err = socket.SetCurveServerkey(curve.ServerKey)
if err != nil {
return nil, err
}
publicKey := curve.PublicKey
secretKey := curve.PrivateKey
if publicKey == "" || secretKey == "" {
// generate new keypair
publicKey, secretKey, err = zmq.NewCurveKeypair()
if err != nil {
return nil, err
}
}

err = socket.SetCurvePublickey(publicKey)
if err != nil {
return nil, err
}
err = socket.SetCurveSecretkey(secretKey)
if err != nil {
return nil, err
}
}

// for now do not use raw subscriptions - we would have to handle skipped/lost notifications from zeromq
// on each notification we do sync or syncmempool respectively
// socket.SetSubscribe("rawblock")
Expand Down