pallet_gear_eth_bridge_primitives/
lib.rs1#![cfg_attr(not(feature = "std"), no_std)]
7#![warn(missing_docs)]
8#![doc(html_logo_url = "https://gear-tech.io/logo.png")]
9#![doc(html_favicon_url = "https://gear-tech.io/favicon.ico")]
10#![cfg_attr(docsrs, feature(doc_cfg))]
11
12extern crate alloc;
13
14use alloc::vec::Vec;
15use binary_merkle_tree::MerkleProof;
16use gprimitives::{ActorId, H160, H256, U256};
17use parity_scale_codec::{Decode, Encode};
18use scale_info::TypeInfo;
19
20#[derive(Clone, Debug, Default, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, TypeInfo)]
22#[cfg_attr(feature = "std", derive(serde::Deserialize, serde::Serialize))]
23pub struct Proof {
24 pub root: H256,
26 pub proof: Vec<H256>,
28 pub number_of_leaves: u64,
30 pub leaf_index: u64,
32 pub leaf: H256,
34}
35
36impl From<MerkleProof<H256, H256>> for Proof {
37 fn from(value: MerkleProof<H256, H256>) -> Self {
38 Self {
39 root: value.root,
40 proof: value.proof,
41 number_of_leaves: value.number_of_leaves as u64,
42 leaf_index: value.leaf_index as u64,
43 leaf: value.leaf,
44 }
45 }
46}
47
48#[derive(Clone, Debug, Default, Encode, Decode, PartialEq, Eq, PartialOrd, Ord, TypeInfo)]
50pub struct EthMessage {
51 nonce: U256,
52 source: H256,
53 destination: H160,
54 payload: Vec<u8>,
55}
56
57impl EthMessage {
58 pub unsafe fn new_unchecked(
66 nonce: U256,
67 source: ActorId,
68 destination: H160,
69 payload: Vec<u8>,
70 ) -> Self {
71 Self {
72 nonce,
73 source: source.into_bytes().into(),
74 destination,
75 payload,
76 }
77 }
78
79 pub fn nonce(&self) -> U256 {
81 self.nonce
82 }
83
84 pub fn source(&self) -> H256 {
86 self.source
87 }
88
89 pub fn destination(&self) -> H160 {
91 self.destination
92 }
93
94 pub fn payload(&self) -> &[u8] {
96 &self.payload
97 }
98}