/home/runner/work/creditcoin/creditcoin/node/rpc/src/friendly.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::{AccountId, BlockNumber, Hash, Moment}; |
2 | | use pallet_creditcoin::*; |
3 | | use serde::{Deserialize, Serialize}; |
4 | | |
5 | 0 | #[derive(Serialize, Deserialize, Clone, Debug, PartialEq)] |
6 | | #[serde(rename_all = "camelCase")] |
7 | | pub enum Event { |
8 | | CtcTransfer { |
9 | | from: AccountId, |
10 | | to: AccountId, |
11 | | amount: String, |
12 | | }, |
13 | | CtcDeposit { |
14 | | into: AccountId, |
15 | | amount: String, |
16 | | }, |
17 | | CtcWithdraw { |
18 | | from: AccountId, |
19 | | amount: String, |
20 | | }, |
21 | | RewardIssued { |
22 | | to: AccountId, |
23 | | amount: String, |
24 | | }, |
25 | | AddressRegistered { |
26 | | address_id: AddressId<Hash>, |
27 | | address: Address<AccountId>, |
28 | | }, |
29 | | |
30 | | TransferRegistered { |
31 | | transfer_id: TransferId<Hash>, |
32 | | transfer: Transfer<AccountId, BlockNumber, Hash, Moment>, |
33 | | }, |
34 | | TransferVerified { |
35 | | transfer_id: TransferId<Hash>, |
36 | | transfer: Transfer<AccountId, BlockNumber, Hash, Moment>, |
37 | | }, |
38 | | TransferProcessed { |
39 | | transfer_id: TransferId<Hash>, |
40 | | transfer: Transfer<AccountId, BlockNumber, Hash, Moment>, |
41 | | }, |
42 | | |
43 | | AskOrderAdded { |
44 | | ask_id: AskOrderId<BlockNumber, Hash>, |
45 | | ask: AskOrder<AccountId, BlockNumber, Hash>, |
46 | | }, |
47 | | |
48 | | BidOrderAdded { |
49 | | bid_id: BidOrderId<BlockNumber, Hash>, |
50 | | bid: BidOrder<AccountId, BlockNumber, Hash>, |
51 | | }, |
52 | | |
53 | | OfferAdded { |
54 | | offer_id: OfferId<BlockNumber, Hash>, |
55 | | offer: Offer<AccountId, BlockNumber, Hash>, |
56 | | }, |
57 | | |
58 | | DealOrderAdded { |
59 | | deal_id: DealOrderId<BlockNumber, Hash>, |
60 | | deal: DealOrder<AccountId, BlockNumber, Hash, Moment>, |
61 | | }, |
62 | | DealOrderFunded { |
63 | | deal_id: DealOrderId<BlockNumber, Hash>, |
64 | | deal: DealOrder<AccountId, BlockNumber, Hash, Moment>, |
65 | | }, |
66 | | DealOrderClosed { |
67 | | deal_id: DealOrderId<BlockNumber, Hash>, |
68 | | deal: DealOrder<AccountId, BlockNumber, Hash, Moment>, |
69 | | }, |
70 | | |
71 | | LoanExempted { |
72 | | deal_id: DealOrderId<BlockNumber, Hash>, |
73 | | }, |
74 | | |
75 | | LegacyWalletClaimed { |
76 | | new_account_id: AccountId, |
77 | | legacy_sighash: LegacySighash, |
78 | | claimed_balance: String, |
79 | | }, |
80 | | } |
81 | | |
82 | | impl Event { |
83 | 0 | pub fn from_runtime(event: creditcoin_node_runtime::Event) -> Option<Self> { |
84 | 0 | Some(match event { |
85 | 0 | creditcoin_node_runtime::Event::System(_) => None?, |
86 | 0 | creditcoin_node_runtime::Event::Balances(e) => match e { |
87 | 0 | pallet_balances::Event::Transfer { from, to, amount } => { |
88 | 0 | Event::CtcTransfer { from, to, amount: amount.to_string() } |
89 | | }, |
90 | 0 | pallet_balances::Event::Deposit { who, amount } => { |
91 | 0 | Event::CtcDeposit { into: who, amount: amount.to_string() } |
92 | | }, |
93 | 0 | pallet_balances::Event::Withdraw { who, amount } => { |
94 | 0 | Event::CtcWithdraw { from: who, amount: amount.to_string() } |
95 | | }, |
96 | 0 | _ => None?, |
97 | | }, |
98 | 0 | creditcoin_node_runtime::Event::Rewards(e) => match e { |
99 | 0 | pallet_rewards::Event::RewardIssued(to, amount) => { |
100 | 0 | Event::RewardIssued { to, amount: amount.to_string() } |
101 | | }, |
102 | 0 | _ => None?, |
103 | | }, |
104 | 0 | creditcoin_node_runtime::Event::Sudo(_) => None?, |
105 | 0 | creditcoin_node_runtime::Event::Creditcoin(e) => match e { |
106 | 0 | pallet_creditcoin::Event::AddressRegistered(address_id, address) => { |
107 | 0 | Event::AddressRegistered { address_id, address } |
108 | | }, |
109 | 0 | pallet_creditcoin::Event::TransferRegistered(transfer_id, transfer) => { |
110 | 0 | Event::TransferRegistered { transfer_id, transfer } |
111 | | }, |
112 | 0 | pallet_creditcoin::Event::TransferVerified(transfer_id, transfer) => { |
113 | 0 | Event::TransferVerified { transfer_id, transfer } |
114 | | }, |
115 | 0 | pallet_creditcoin::Event::TransferProcessed(transfer_id, transfer) => { |
116 | 0 | Event::TransferProcessed { transfer_id, transfer } |
117 | | }, |
118 | 0 | pallet_creditcoin::Event::AskOrderAdded(ask_id, ask) => { |
119 | 0 | Event::AskOrderAdded { ask_id, ask } |
120 | | }, |
121 | 0 | pallet_creditcoin::Event::BidOrderAdded(bid_id, bid) => { |
122 | 0 | Event::BidOrderAdded { bid_id, bid } |
123 | | }, |
124 | 0 | pallet_creditcoin::Event::OfferAdded(offer_id, offer) => { |
125 | 0 | Event::OfferAdded { offer_id, offer } |
126 | | }, |
127 | 0 | pallet_creditcoin::Event::DealOrderAdded(deal_id, deal) => { |
128 | 0 | Event::DealOrderAdded { deal_id, deal } |
129 | | }, |
130 | 0 | pallet_creditcoin::Event::DealOrderFunded(deal_id, deal) => { |
131 | 0 | Event::DealOrderFunded { deal_id, deal } |
132 | | }, |
133 | 0 | pallet_creditcoin::Event::DealOrderClosed(deal_id, deal) => { |
134 | 0 | Event::DealOrderClosed { deal_id, deal } |
135 | | }, |
136 | 0 | pallet_creditcoin::Event::LoanExempted(deal_id) => Event::LoanExempted { deal_id }, |
137 | | pallet_creditcoin::Event::LegacyWalletClaimed( |
138 | 0 | new_account_id, |
139 | 0 | legacy_sighash, |
140 | 0 | claimed_balance, |
141 | 0 | ) => Event::LegacyWalletClaimed { |
142 | 0 | new_account_id, |
143 | 0 | legacy_sighash, |
144 | 0 | claimed_balance: claimed_balance.to_string(), |
145 | 0 | }, |
146 | 0 | _ => None?, |
147 | | }, |
148 | | }) |
149 | 0 | } |
150 | | } |