Skip to content

Commit

Permalink
Add timestamps to block(dis)connected notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Jun 18, 2015
1 parent 2ceb641 commit 0f60b62
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 6 additions & 2 deletions btcjson/chainsvrwsntfns.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,33 @@ const (
type BlockConnectedNtfn struct {
Hash string
Height int32
Time int64
}

// NewBlockConnectedNtfn returns a new instance which can be used to issue a
// blockconnected JSON-RPC notification.
func NewBlockConnectedNtfn(hash string, height int32) *BlockConnectedNtfn {
func NewBlockConnectedNtfn(hash string, height int32, time int64) *BlockConnectedNtfn {
return &BlockConnectedNtfn{
Hash: hash,
Height: height,
Time: time,
}
}

// BlockDisconnectedNtfn defines the blockdisconnected JSON-RPC notification.
type BlockDisconnectedNtfn struct {
Hash string
Height int32
Time int64
}

// NewBlockDisconnectedNtfn returns a new instance which can be used to issue a
// blockdisconnected JSON-RPC notification.
func NewBlockDisconnectedNtfn(hash string, height int32) *BlockDisconnectedNtfn {
func NewBlockDisconnectedNtfn(hash string, height int32, time int64) *BlockDisconnectedNtfn {
return &BlockDisconnectedNtfn{
Hash: hash,
Height: height,
Time: time,
}
}

Expand Down
14 changes: 8 additions & 6 deletions btcjson/chainsvrwsntfns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,31 @@ func TestChainSvrWsNtfns(t *testing.T) {
{
name: "blockconnected",
newNtfn: func() (interface{}, error) {
return btcjson.NewCmd("blockconnected", "123", 100000)
return btcjson.NewCmd("blockconnected", "123", 100000, 123456789)
},
staticNtfn: func() interface{} {
return btcjson.NewBlockConnectedNtfn("123", 100000)
return btcjson.NewBlockConnectedNtfn("123", 100000, 123456789)
},
marshalled: `{"jsonrpc":"1.0","method":"blockconnected","params":["123",100000],"id":null}`,
marshalled: `{"jsonrpc":"1.0","method":"blockconnected","params":["123",100000,123456789],"id":null}`,
unmarshalled: &btcjson.BlockConnectedNtfn{
Hash: "123",
Height: 100000,
Time: 123456789,
},
},
{
name: "blockdisconnected",
newNtfn: func() (interface{}, error) {
return btcjson.NewCmd("blockdisconnected", "123", 100000)
return btcjson.NewCmd("blockdisconnected", "123", 100000, 123456789)
},
staticNtfn: func() interface{} {
return btcjson.NewBlockDisconnectedNtfn("123", 100000)
return btcjson.NewBlockDisconnectedNtfn("123", 100000, 123456789)
},
marshalled: `{"jsonrpc":"1.0","method":"blockdisconnected","params":["123",100000],"id":null}`,
marshalled: `{"jsonrpc":"1.0","method":"blockdisconnected","params":["123",100000,123456789],"id":null}`,
unmarshalled: &btcjson.BlockDisconnectedNtfn{
Hash: "123",
Height: 100000,
Time: 123456789,
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions rpcwebsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func (*wsNotificationManager) notifyBlockConnected(clients map[chan struct{}]*ws

// Notify interested websocket clients about the connected block.
ntfn := btcjson.NewBlockConnectedNtfn(block.Sha().String(),
int32(block.Height()))
int32(block.Height()), block.MsgBlock().Header.Timestamp.Unix())
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
if err != nil {
rpcsLog.Error("Failed to marshal block connected notification: "+
Expand All @@ -435,7 +435,7 @@ func (*wsNotificationManager) notifyBlockDisconnected(clients map[chan struct{}]

// Notify interested websocket clients about the disconnected block.
ntfn := btcjson.NewBlockDisconnectedNtfn(block.Sha().String(),
int32(block.Height()))
int32(block.Height()), block.MsgBlock().Header.Timestamp.Unix())
marshalledJSON, err := btcjson.MarshalCmd(nil, ntfn)
if err != nil {
rpcsLog.Error("Failed to marshal block disconnected "+
Expand Down

0 comments on commit 0f60b62

Please sign in to comment.