cfx_rpc_eth_types/
authorization.rs1use cfx_types::{Address, U256, U64};
2use primitives::transaction::AuthorizationListItem;
3
4#[derive(
5 Debug, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize, Clone,
6)]
7#[serde(rename_all = "camelCase")]
8pub struct Authorization {
9 pub chain_id: U256,
11 pub address: Address,
13 pub nonce: U64,
15}
16
17#[derive(
18 Debug, Default, PartialEq, Eq, serde::Deserialize, serde::Serialize, Clone,
19)]
20#[serde(rename_all = "camelCase")]
21pub struct SignedAuthorization {
22 #[serde(flatten)]
24 inner: Authorization,
25 pub y_parity: U64,
29 pub r: U256,
31 pub s: U256,
33}
34
35impl SignedAuthorization {
36 pub const fn inner(&self) -> &Authorization { &self.inner }
38
39 pub fn y_parity(&self) -> u8 { self.y_parity.as_u32() as u8 }
41
42 pub const fn r(&self) -> U256 { self.r }
44
45 pub const fn s(&self) -> U256 { self.s }
47}
48
49impl From<AuthorizationListItem> for SignedAuthorization {
50 fn from(item: AuthorizationListItem) -> Self {
51 Self {
52 inner: Authorization {
53 chain_id: item.chain_id.into(),
54 address: item.address.into(),
55 nonce: item.nonce.into(),
56 },
57 y_parity: item.y_parity.into(),
58 r: item.r,
59 s: item.s,
60 }
61 }
62}
63
64impl Into<AuthorizationListItem> for SignedAuthorization {
65 fn into(self) -> AuthorizationListItem {
66 AuthorizationListItem {
67 chain_id: self.inner.chain_id,
68 address: self.inner.address,
69 nonce: self.inner.nonce.as_u64(),
70 y_parity: self.y_parity(),
71 r: self.r,
72 s: self.s,
73 }
74 }
75}