Watch existing extrinsics RPC (#3873)

* Transaction pool watch intristics.

* Track extrinsic rpc methods.

* Test for pool watcher.

* Track extrinsic rpc test.

* Fix rpc naming.

* review fixes

* Update jsonrpc and use une subcription.

* Naming and dependencies.
This commit is contained in:
Nikolay Volf
2019-10-27 14:55:44 +03:00
committed by Gavin Wood
parent f7ee9ab235
commit d149c2f719
15 changed files with 194 additions and 73 deletions
@@ -165,6 +165,17 @@ impl<B: ChainApi> Pool<B> {
)
}
/// Watch existing transaction
///
/// Get notified when some existing transaction is finished verifying or gets finalized
/// in a new block.
pub fn watch(
&self,
hash: ExHash<B>,
) -> Watcher<ExHash<B>, BlockHash<B>> {
self.validated_pool.watch(hash)
}
/// Prunes ready transactions.
///
/// Used to clear the pool from transactions that were part of recently imported block.
@@ -783,7 +794,6 @@ mod tests {
// when
pool.validated_pool.remove_invalid(&[*watcher.hash()]);
// then
let mut stream = futures::executor::block_on_stream(watcher.into_stream());
assert_eq!(stream.next(), Some(watcher::Status::Ready));
@@ -907,5 +917,37 @@ mod tests {
assert_eq!(pool.status().ready, 1);
assert_eq!(pool.status().future, 0);
}
#[test]
fn should_watch_existing() {
let limit = Limit {
count: 1,
total_bytes: 1000,
};
let pool = Pool::new(Options {
ready: limit.clone(),
future: limit.clone(),
}, TestApi::default());
let xt = uxt(Transfer {
from: AccountId::from_h256(H256::from_low_u64_be(1)),
to: AccountId::from_h256(H256::from_low_u64_be(2)),
amount: 5,
nonce: 0,
});
let hash = block_on(pool.submit_one(&BlockId::Number(0), xt)).expect("Failed to submit");
assert_eq!(pool.status().ready, 1);
let watcher = pool.watch(hash);
block_on(pool.prune_tags(&BlockId::Number(2), vec![], vec![hash]))
.expect("Failed to prune tags");
let mut stream = futures::executor::block_on_stream(
watcher.into_stream()
);
assert_eq!(stream.next(), Some(watcher::Status::Finalized(H256::from_low_u64_be(2).into())));
assert_eq!(stream.next(), None);
}
}
}