1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use cfx_types::H256;
use primitives::TransactionWithSignature;

/// Messages to broadcast via chain
#[allow(dead_code)]
pub enum ChainMessageType {
    /// Consensus message
    Consensus(Vec<u8>),
    /// Message with private transaction
    PrivateTransaction(H256, Vec<u8>),
    /// Message with signed private transaction
    SignedPrivateTransaction(H256, Vec<u8>),
}

/// Used by `ChainNotify` `new_blocks()`
#[allow(dead_code)]
pub struct NewBlocks {}

impl NewBlocks {
    /// Constructor
    #[allow(dead_code)]
    pub fn new() -> NewBlocks { NewBlocks {} }
}

#[allow(unused)]
pub trait ChainNotify: Send + Sync {
    /// fires when chain has new blocks.
    fn new_blocks(&self, _new_blocks: NewBlocks) {
        // does nothing by default
    }

    /// fires when chain achieves active mode
    fn start(&self) {
        // does nothing by default
    }

    /// fires when chain achieves passive mode
    fn stop(&self) {
        // does nothing by default
    }

    /// fires when chain broadcasts a message
    fn broadcast(&self, _message_type: ChainMessageType) {
        // does nothing by default
    }

    /// fires when new transactions are received from a peer
    fn transactions_received(
        &self, _txs: &[TransactionWithSignature], _peer_id: usize,
    ) {
        // does nothing by default
    }
}