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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#![allow(dead_code)]

use std::fmt::Debug;

use lifeline::Message;
use postage::broadcast;
use serde::{Deserialize, Serialize};

use client_darwinia::types::runtime_types::darwinia_bridge_ethereum::EthereumRelayHeaderParcel;
use client_darwinia::types::{EcdsaMessage, EthereumReceiptProofThing};
use thegraph_liketh::types::TransactionEntity;

use crate::bridge::DarwiniaEthereumBus;

#[derive(Debug, Clone)]
pub enum DarwiniaEthereumMessage {
    Scan(EthereumScanMessage),
    ToDarwinia(ToDarwiniaLinkedMessage),
}

impl Message<DarwiniaEthereumBus> for DarwiniaEthereumMessage {
    type Channel = broadcast::Sender<Self>;
}

#[derive(Debug, Clone)]
pub enum EthereumScanMessage {
    Start,
    Stop,
}

#[derive(Debug, Clone)]
pub enum ToDarwiniaLinkedMessage {
    SendExtrinsic,
}

// *** ToRelayMessage ***
#[derive(Clone, Debug)]
pub enum ToRelayMessage {
    EthereumBlockNumber(u64),
}

impl Message<DarwiniaEthereumBus> for ToRelayMessage {
    type Channel = broadcast::Sender<Self>;
}

// *** ToExtrinsicsMessage **
#[derive(Clone, Debug)]
pub enum ToExtrinsicsMessage {
    Extrinsic(Extrinsic),
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum Extrinsic {
    Affirm(EthereumRelayHeaderParcel),
    Redeem(EthereumReceiptProofThing, TransactionEntity),
    GuardVote(u64, bool),
    SignAndSendMmrRoot(u32),
    SignAndSendAuthorities(EcdsaMessage),
}

impl PartialEq for Extrinsic {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (Extrinsic::Affirm(left), Extrinsic::Affirm(right)) => {
                left.header.number == right.header.number
            }
            (Extrinsic::Redeem(_, l_entity), Extrinsic::Redeem(_, r_entity)) => {
                l_entity.tx_hash == r_entity.tx_hash
            }
            (Extrinsic::GuardVote(l_u, l_b), Extrinsic::GuardVote(r_u, r_b)) => {
                l_u == r_u && l_b == r_b
            }
            (Extrinsic::SignAndSendMmrRoot(left), Extrinsic::SignAndSendMmrRoot(right)) => {
                left == right
            }
            (Extrinsic::SignAndSendAuthorities(left), Extrinsic::SignAndSendAuthorities(right)) => {
                left == right
            }
            (_, _) => false,
        }
    }
}

impl Message<DarwiniaEthereumBus> for ToExtrinsicsMessage {
    type Channel = broadcast::Sender<Self>;
}

// *** ToGuardMessage **
#[derive(Clone, Debug)]
pub enum ToGuardMessage {
    StartGuard,
}

impl Message<DarwiniaEthereumBus> for ToGuardMessage {
    type Channel = broadcast::Sender<Self>;
}