Send each log as a separate notifications. (#7175)
This commit is contained in:
parent
3284020b04
commit
d5c21c9707
@ -153,9 +153,9 @@ impl<C> ChainNotificationHandler<C> {
|
|||||||
self.remote.spawn(logs
|
self.remote.spawn(logs
|
||||||
.map(move |logs| {
|
.map(move |logs| {
|
||||||
let logs = logs.into_iter().flat_map(|log| log).collect();
|
let logs = logs.into_iter().flat_map(|log| log).collect();
|
||||||
let logs = limit_logs(logs, limit);
|
|
||||||
if !logs.is_empty() {
|
for log in limit_logs(logs, limit) {
|
||||||
Self::notify(&remote, &subscriber, pubsub::Result::Logs(logs));
|
Self::notify(&remote, &subscriber, pubsub::Result::Log(log))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map_err(|e| warn!("Unable to fetch latest logs: {:?}", e))
|
.map_err(|e| warn!("Unable to fetch latest logs: {:?}", e))
|
||||||
|
@ -127,17 +127,17 @@ fn should_subscribe_to_logs() {
|
|||||||
// Check notifications (enacted)
|
// Check notifications (enacted)
|
||||||
handler.new_blocks(vec![], vec![], vec![h1], vec![], vec![], vec![], 0);
|
handler.new_blocks(vec![], vec![], vec![h1], vec![], vec![], vec![], 0);
|
||||||
let (res, receiver) = receiver.into_future().wait().unwrap();
|
let (res, receiver) = receiver.into_future().wait().unwrap();
|
||||||
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":[{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned()
|
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned()
|
||||||
+ &format!("0x{:?}", tx_hash)
|
+ &format!("0x{:?}", tx_hash)
|
||||||
+ r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"}],"subscription":"0x416d77337e24399d"}}"#;
|
+ r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"mined"},"subscription":"0x416d77337e24399d"}}"#;
|
||||||
assert_eq!(res, Some(response.into()));
|
assert_eq!(res, Some(response.into()));
|
||||||
|
|
||||||
// Check notifications (retracted)
|
// Check notifications (retracted)
|
||||||
handler.new_blocks(vec![], vec![], vec![], vec![h1], vec![], vec![], 0);
|
handler.new_blocks(vec![], vec![], vec![], vec![h1], vec![], vec![], 0);
|
||||||
let (res, receiver) = receiver.into_future().wait().unwrap();
|
let (res, receiver) = receiver.into_future().wait().unwrap();
|
||||||
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":[{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned()
|
let response = r#"{"jsonrpc":"2.0","method":"eth_subscription","params":{"result":{"address":"0x0000000000000000000000000000000000000005","blockHash":"0x3457d2fa2e3dd33c78ac681cf542e429becf718859053448748383af67e23218","blockNumber":"0x1","data":"0x","logIndex":"0x0","topics":["0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"],"transactionHash":""#.to_owned()
|
||||||
+ &format!("0x{:?}", tx_hash)
|
+ &format!("0x{:?}", tx_hash)
|
||||||
+ r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"removed"}],"subscription":"0x416d77337e24399d"}}"#;
|
+ r#"","transactionIndex":"0x0","transactionLogIndex":"0x0","type":"removed"},"subscription":"0x416d77337e24399d"}}"#;
|
||||||
assert_eq!(res, Some(response.into()));
|
assert_eq!(res, Some(response.into()));
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ use v1::types::{RichHeader, Filter, Log};
|
|||||||
pub enum Result {
|
pub enum Result {
|
||||||
/// New block header.
|
/// New block header.
|
||||||
Header(RichHeader),
|
Header(RichHeader),
|
||||||
/// Logs
|
/// Log
|
||||||
Logs(Vec<Log>),
|
Log(Log),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Serialize for Result {
|
impl Serialize for Result {
|
||||||
@ -36,7 +36,7 @@ impl Serialize for Result {
|
|||||||
{
|
{
|
||||||
match *self {
|
match *self {
|
||||||
Result::Header(ref header) => header.serialize(serializer),
|
Result::Header(ref header) => header.serialize(serializer),
|
||||||
Result::Logs(ref logs) => logs.serialize(serializer),
|
Result::Log(ref log) => log.serialize(serializer),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user