diff --git a/btcjson/chainsvrwsntfns.go b/btcjson/chainsvrwsntfns.go index 30f3c95c..c7e9b5aa 100644 --- a/btcjson/chainsvrwsntfns.go +++ b/btcjson/chainsvrwsntfns.go @@ -50,14 +50,16 @@ 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, } } @@ -65,14 +67,16 @@ func NewBlockConnectedNtfn(hash string, height int32) *BlockConnectedNtfn { 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, } } diff --git a/btcjson/chainsvrwsntfns_test.go b/btcjson/chainsvrwsntfns_test.go index f09c0d06..70c0241a 100644 --- a/btcjson/chainsvrwsntfns_test.go +++ b/btcjson/chainsvrwsntfns_test.go @@ -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, }, }, { diff --git a/docs/json_rpc_api.md b/docs/json_rpc_api.md index b331059f..7d3620f4 100644 --- a/docs/json_rpc_api.md +++ b/docs/json_rpc_api.md @@ -818,9 +818,9 @@ The following is an overview of the JSON-RPC notifications used for Websocket co |---|---| |Method|blockconnected| |Request|[notifyblocks](#notifyblocks)| -|Parameters|1. BlockHash (string) hex-encoded bytes of the attached block hash
2. BlockHeight (numeric) height of the attached block| +|Parameters|1. BlockHash (string) hex-encoded bytes of the attached block hash
2. BlockHeight (numeric) height of the attached block
3. BlockTime (numeric) unix time of the attached block| |Description|Notifies when a block has been added to the main chain. Notification is sent to all connected clients.| -|Example|Example blockconnected notification for mainnet block 280330 (newlines added for readability):
`{`
 `"jsonrpc": "1.0",`
 `"method": "blockconnected",`
 `"params":`
  `[`
   `"000000000000000004cbdfe387f4df44b914e464ca79838a8ab777b3214dbffd",`
   `280330`
  `],`
 `"id": null`
`}`| +|Example|Example blockconnected notification for mainnet block 280330 (newlines added for readability):
`{`
 `"jsonrpc": "1.0",`
 `"method": "blockconnected",`
 `"params":`
  `[`
   `"000000000000000004cbdfe387f4df44b914e464ca79838a8ab777b3214dbffd",`
   `280330,`
   `1389636265`
  `],`
 `"id": null`
`}`| [Return to Overview](#NotificationOverview)
*** @@ -831,9 +831,9 @@ The following is an overview of the JSON-RPC notifications used for Websocket co |---|---| |Method|blockdisconnected| |Request|[notifyblocks](#notifyblocks)| -|Parameters|1. BlockHash (string) hex-encoded bytes of the disconnected block hash
2. BlockHeight (numeric) height of the disconnected block| +|Parameters|1. BlockHash (string) hex-encoded bytes of the disconnected block hash
2. BlockHeight (numeric) height of the disconnected block
3. BlockTime (numeric) unix time of the disconnected block| |Description|Notifies when a block has been removed from the main chain. Notification is sent to all connected clients.| -|Example|Example blockdisconnected notification for mainnet block 280330 (newlines added for readability):
`{`
 `"jsonrpc": "1.0",`
 `"method": "blockdisconnected",`
 `"params":`
  `[`
   `"000000000000000004cbdfe387f4df44b914e464ca79838a8ab777b3214dbffd",`
   `280330`
  `],`
 `"id": null`
`}`| +|Example|Example blockdisconnected notification for mainnet block 280330 (newlines added for readability):
`{`
 `"jsonrpc": "1.0",`
 `"method": "blockdisconnected",`
 `"params":`
  `[`
   `"000000000000000004cbdfe387f4df44b914e464ca79838a8ab777b3214dbffd",`
   `280330,`
   `1389636265`
  `],`
 `"id": null`
`}`| [Return to Overview](#NotificationOverview)
*** diff --git a/rpcwebsocket.go b/rpcwebsocket.go index e97e9d22..5b2ec323 100644 --- a/rpcwebsocket.go +++ b/rpcwebsocket.go @@ -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: "+ @@ -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 "+