mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-03-28 13:13:08 +00:00
AccountForSerialization struct for Account serialization
This commit is contained in:
parent
720263ae2d
commit
222b0136bf
@ -16,7 +16,7 @@ use crate::key_management::{
|
|||||||
pub type PublicKey = AffinePoint;
|
pub type PublicKey = AffinePoint;
|
||||||
pub type AccountAddress = TreeHashType;
|
pub type AccountAddress = TreeHashType;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Account {
|
pub struct Account {
|
||||||
pub key_holder: AddressKeyHolder,
|
pub key_holder: AddressKeyHolder,
|
||||||
pub address: AccountAddress,
|
pub address: AccountAddress,
|
||||||
@ -24,6 +24,64 @@ pub struct Account {
|
|||||||
pub utxos: HashMap<TreeHashType, UTXO>,
|
pub utxos: HashMap<TreeHashType, UTXO>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
pub struct AccountForSerialization {
|
||||||
|
pub key_holder: AddressKeyHolder,
|
||||||
|
pub address: AccountAddress,
|
||||||
|
pub balance: u64,
|
||||||
|
pub utxos: HashMap<String, UTXO>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<Account> for AccountForSerialization {
|
||||||
|
fn from(value: Account) -> Self {
|
||||||
|
AccountForSerialization {
|
||||||
|
key_holder: value.key_holder,
|
||||||
|
address: value.address,
|
||||||
|
balance: value.balance,
|
||||||
|
utxos: value
|
||||||
|
.utxos
|
||||||
|
.into_iter()
|
||||||
|
.map(|(key, val)| (hex::encode(key), val))
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<AccountForSerialization> for Account {
|
||||||
|
fn from(value: AccountForSerialization) -> Self {
|
||||||
|
Account {
|
||||||
|
key_holder: value.key_holder,
|
||||||
|
address: value.address,
|
||||||
|
balance: value.balance,
|
||||||
|
utxos: value
|
||||||
|
.utxos
|
||||||
|
.into_iter()
|
||||||
|
.map(|(key, val)| (hex::decode(key).unwrap().try_into().unwrap(), val))
|
||||||
|
.collect(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Serialize for Account {
|
||||||
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
S: serde::Serializer,
|
||||||
|
{
|
||||||
|
let account_for_serialization: AccountForSerialization = From::from(self.clone());
|
||||||
|
account_for_serialization.serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for Account {
|
||||||
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
|
where
|
||||||
|
D: serde::Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let account_for_serialization = <AccountForSerialization>::deserialize(deserializer)?;
|
||||||
|
Ok(account_for_serialization.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///A strucure, which represents all the visible(public) information
|
///A strucure, which represents all the visible(public) information
|
||||||
///
|
///
|
||||||
/// known to each node about account `address`
|
/// known to each node about account `address`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user