mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +00:00
Pool: A bunch of tests and fixes (#914)
* Implement Ready/Future events. * Trigger invalid notification. * Clearing stale transactions test. * Fix RPC test.
This commit is contained in:
@@ -22,7 +22,7 @@ use futures::{
|
||||
};
|
||||
|
||||
/// Possible extrinsic status events
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum Status<H, H2> {
|
||||
/// Extrinsic is part of the future queue.
|
||||
@@ -37,6 +37,8 @@ pub enum Status<H, H2> {
|
||||
Broadcast(Vec<String>),
|
||||
/// Extrinsic has been dropped from the pool because of the limit.
|
||||
Dropped,
|
||||
/// Extrinsic was detected as invalid.
|
||||
Invalid,
|
||||
}
|
||||
|
||||
/// Extrinsic watcher.
|
||||
@@ -45,9 +47,15 @@ pub enum Status<H, H2> {
|
||||
#[derive(Debug)]
|
||||
pub struct Watcher<H, H2> {
|
||||
receiver: mpsc::UnboundedReceiver<Status<H, H2>>,
|
||||
hash: H,
|
||||
}
|
||||
|
||||
impl<H, H2> Watcher<H, H2> {
|
||||
/// Returns the transaction hash.
|
||||
pub fn hash(&self) -> &H {
|
||||
&self.hash
|
||||
}
|
||||
|
||||
/// Pipe the notifications to given sink.
|
||||
///
|
||||
/// Make sure to drive the future to completion.
|
||||
@@ -75,14 +83,25 @@ impl<H, H2> Default for Sender<H, H2> {
|
||||
|
||||
impl<H: Clone, H2: Clone> Sender<H, H2> {
|
||||
/// Add a new watcher to this sender object.
|
||||
pub fn new_watcher(&mut self) -> Watcher<H, H2> {
|
||||
pub fn new_watcher(&mut self, hash: H) -> Watcher<H, H2> {
|
||||
let (tx, receiver) = mpsc::unbounded();
|
||||
self.receivers.push(tx);
|
||||
Watcher {
|
||||
receiver,
|
||||
hash,
|
||||
}
|
||||
}
|
||||
|
||||
/// Transaction became ready.
|
||||
pub fn ready(&mut self) {
|
||||
self.send(Status::Ready)
|
||||
}
|
||||
|
||||
/// Transaction was moved to future.
|
||||
pub fn future(&mut self) {
|
||||
self.send(Status::Future)
|
||||
}
|
||||
|
||||
/// Some state change (perhaps another extrinsic was included) rendered this extrinsic invalid.
|
||||
pub fn usurped(&mut self, hash: H) {
|
||||
self.send(Status::Usurped(hash))
|
||||
@@ -94,6 +113,13 @@ impl<H: Clone, H2: Clone> Sender<H, H2> {
|
||||
self.finalised = true;
|
||||
}
|
||||
|
||||
/// Extrinsic has been marked as invalid by the block builder.
|
||||
pub fn invalid(&mut self) {
|
||||
self.send(Status::Invalid);
|
||||
// we mark as finalised as there are no more notifications
|
||||
self.finalised = true;
|
||||
}
|
||||
|
||||
/// Transaction has been dropped from the pool because of the limit.
|
||||
pub fn dropped(&mut self) {
|
||||
self.send(Status::Dropped);
|
||||
|
||||
Reference in New Issue
Block a user