Use btcws package for wallet notifications.

This commit is contained in:
Josh Rickmar 2013-11-08 12:43:10 -05:00
parent af311078b4
commit 41838b83b0

View file

@ -1262,38 +1262,20 @@ func (s *rpcServer) NotifyBlockConnected(block *btcutil.Block) {
return return
} }
var id interface{} = "btcd:blockconnected" // TODO: remove int32 type conversion.
ntfn := btcjson.Reply{ ntfn := btcws.NewBlockConnectedNtfn(hash.String(),
Result: struct { int32(block.Height()))
Hash string `json:"hash"` mntfn, _ := json.Marshal(ntfn)
Height int64 `json:"height"` s.ws.walletNotificationMaster <- mntfn
MinedTXs []string `json:"minedtxs"`
}{
Hash: hash.String(),
Height: block.Height(),
},
Id: &id,
}
m, _ := json.Marshal(ntfn)
s.ws.walletNotificationMaster <- m
// Inform any interested parties about txs mined in this block. // Inform any interested parties about txs mined in this block.
for _, tx := range block.Transactions() { for _, tx := range block.Transactions() {
if clist, ok := s.ws.minedTxNotifications[*tx.Sha()]; ok { if clist, ok := s.ws.minedTxNotifications[*tx.Sha()]; ok {
for e := clist.Front(); e != nil; e = e.Next() { for e := clist.Front(); e != nil; e = e.Next() {
ctx := e.Value.(*notificationCtx) ctx := e.Value.(*notificationCtx)
ntfn := btcws.NewTxMinedNtfn(tx.Sha().String())
var id interface{} = "btcd:txmined" mntfn, _ := json.Marshal(ntfn)
reply := btcjson.Reply{ ctx.connection <- mntfn
Result: tx.Sha().String(),
Id: &id,
}
replyBytes, err := json.Marshal(reply)
if err != nil {
log.Errorf("RPCS: Unable to marshal mined tx notification: %v", err)
continue
}
ctx.connection <- replyBytes
s.ws.RemoveMinedTxRequest(ctx.connection, ctx.rc, s.ws.RemoveMinedTxRequest(ctx.connection, ctx.rc,
tx.Sha()) tx.Sha())
} }
@ -1306,24 +1288,17 @@ func (s *rpcServer) NotifyBlockConnected(block *btcutil.Block) {
// of a new block disconnected from the main chain. The notification is sent // of a new block disconnected from the main chain. The notification is sent
// to each connected wallet. // to each connected wallet.
func (s *rpcServer) NotifyBlockDisconnected(block *btcutil.Block) { func (s *rpcServer) NotifyBlockDisconnected(block *btcutil.Block) {
var id interface{} = "btcd:blockdisconnected"
hash, err := block.Sha() hash, err := block.Sha()
if err != nil { if err != nil {
log.Error("Bad block; connected block notification dropped.") log.Error("Bad block; connected block notification dropped.")
return return
} }
ntfn := btcjson.Reply{
Result: struct { // TODO: remove int32 type conversion.
Hash string `json:"hash"` ntfn := btcws.NewBlockDisconnectedNtfn(hash.String(),
Height int64 `json:"height"` int32(block.Height()))
}{ mntfn, _ := json.Marshal(ntfn)
Hash: hash.String(), s.ws.walletNotificationMaster <- mntfn
Height: block.Height(),
},
Id: &id,
}
m, _ := json.Marshal(ntfn)
s.ws.walletNotificationMaster <- m
} }
// NotifyBlockTXs creates and marshals a JSON message to notify wallets // NotifyBlockTXs creates and marshals a JSON message to notify wallets