我正在使用BTCD并使用其客户端:“ github.com/btcsuite/btcd/rpcclient”
我正在连接到正确连接的BTC钱包。除了设置NotificationHandlers之外,我可以调用所有命令。 RPC客户端未收到除OnClientConnected以外的任何通知。我也在尝试这些:
ntfnHandlers := rpcclient.NotificationHandlers{
OnClientConnected: func() {
logs.Error("OK")
},
OnFilteredBlockConnected: func(height int32, header *wire.BlockHeader,
txs []*btcutil.Tx) {
logs.Debug("Block connected: %v (%d) %v", height, header, txs)
},
OnFilteredBlockDisconnected: func(height int32, header *wire.BlockHeader) {
logs.Debug("Block disconnected: (%d) %v", height, header)
},
OnRelevantTxAccepted: func(transaction []byte) {
logs.Debug("OnRecvTx: (%v)", transaction)
},
OnTxAccepted: func(hash *chainhash.Hash, amount btcutil.Amount) {
logs.Debug("OnTxAccepted: ", amount)
},
OnWalletLockState: func(locked bool) {
logs.Debug("OnWalletLockState: ", locked)
},
OnUnknownNotification: func(method string, params []json.RawMessage) {
logs.Debug("OnUnknownNotification: %v", method)
},
OnTxAcceptedVerbose: func(txDetails *btcjson.TxRawResult) {
logs.Debug("OnTxAcceptedVerbose: %v", txDetails.BlockHash)
},
}
// Notice the notification parameter is nil since notifications are
// not supported in HTTP POST mode.
RPCclient, err := rpcclient.New(c.rpcConf, &ntfnHandlers)
if err != nil {
logs.Error("RunProcess(): RPCclient.New %s\n", err.Error())
return err
}
if err := RPCclient.NotifyBlocks(); err != nil {
log.Fatal(err)
return err
}
logs.Info("NotifyBlocks: Registration Complete")
if err := RPCclient.NotifyNewTransactions(true); err != nil {
log.Fatal(err)
return err
}
logs.Info("NotifyNewTransactions: Registration Complete")
blockCount, err := RPCclient.GetBlockCount()
if err != nil {
log.Fatal(err)
return err
}
c.Client.WaitForShutdown()
这是我的配置:
connCfg := &rpcclient.ConnConfig{
Host: xxx,
User: xxx,
Pass: xxx,
Certificates: certificate,
Endpoint: "ws",
HTTPPostMode: false, // Bitcoin core only supports HTTP POST mode
DisableTLS: false, // Bitcoin core does not provide TLS by default
}
服务器消息:
web_1 | 2019/03/20 03:30:42.029 [E] [infrastructure.go:1035] OK
web_1 | 2019/03/20 03:30:42.115 [I] [asm_amd64.s:1333] NotifyBlocks: Registration Complete
web_1 | 2019/03/20 03:30:42.202 [I] [asm_amd64.s:1333] NotifyNewTransactions: Registration Complete
web_1 | 2019/03/20 03:30:42.305 [I] [asm_amd64.s:1333] Block count: 1485308