remove serde for nssa::address

This commit is contained in:
Sergio Chouhy 2025-08-22 08:53:40 -03:00
parent 02ad6129d6
commit 1ca3d68d7e
3 changed files with 6 additions and 88 deletions

View File

@ -27,7 +27,7 @@ pub struct Account {
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct AccountForSerialization { pub struct AccountForSerialization {
pub key_holder: AddressKeyHolder, pub key_holder: AddressKeyHolder,
pub address: Address, pub address: String,
pub balance: u64, pub balance: u64,
pub utxos: HashMap<String, UTXO>, pub utxos: HashMap<String, UTXO>,
} }
@ -36,8 +36,8 @@ impl From<Account> for AccountForSerialization {
fn from(value: Account) -> Self { fn from(value: Account) -> Self {
AccountForSerialization { AccountForSerialization {
key_holder: value.key_holder, key_holder: value.key_holder,
address: value.address,
balance: value.balance, balance: value.balance,
address: value.address.to_string(),
utxos: value utxos: value
.utxos .utxos
.into_iter() .into_iter()
@ -49,9 +49,12 @@ impl From<Account> for AccountForSerialization {
impl From<AccountForSerialization> for Account { impl From<AccountForSerialization> for Account {
fn from(value: AccountForSerialization) -> Self { fn from(value: AccountForSerialization) -> Self {
let public_key =
nssa::PublicKey::new_from_private_key(value.key_holder.get_pub_account_signing_key());
let address = nssa::Address::from(&public_key);
Account { Account {
key_holder: value.key_holder, key_holder: value.key_holder,
address: value.address, address,
balance: value.balance, balance: value.balance,
utxos: value utxos: value
.utxos .utxos
@ -82,34 +85,6 @@ impl<'de> Deserialize<'de> for Account {
} }
} }
///A strucure, which represents all the visible(public) information
///
/// known to each node about account `address`
///
/// Main usage is to encode data for other account
#[derive(Serialize, Clone)]
pub struct AccountPublicMask {
pub nullifier_public_key: AffinePoint,
pub viewing_public_key: AffinePoint,
pub address: Address,
pub balance: u64,
}
impl AccountPublicMask {
pub fn encrypt_data(
ephemeral_key_holder: &EphemeralKeyHolder,
viewing_public_key_receiver: AffinePoint,
data: &[u8],
) -> (CipherText, Nonce) {
//Using of parent Account fuction
Account::encrypt_data(ephemeral_key_holder, viewing_public_key_receiver, data)
}
pub fn make_tag(&self) -> Tag {
self.address.value()[0]
}
}
impl Account { impl Account {
pub fn new() -> Self { pub fn new() -> Self {
let key_holder = AddressKeyHolder::new_os_random(); let key_holder = AddressKeyHolder::new_os_random();
@ -201,16 +176,6 @@ impl Account {
pub fn make_tag(&self) -> Tag { pub fn make_tag(&self) -> Tag {
self.address.value()[0] self.address.value()[0]
} }
///Produce account public mask
pub fn make_account_public_mask(&self) -> AccountPublicMask {
AccountPublicMask {
nullifier_public_key: self.key_holder.nullifer_public_key,
viewing_public_key: self.key_holder.viewing_public_key,
address: self.address,
balance: self.balance,
}
}
} }
impl Default for Account { impl Default for Account {
@ -253,25 +218,4 @@ mod tests {
assert_eq!(account.balance, 500); assert_eq!(account.balance, 500);
} }
#[test]
fn test_add_asset() {
let mut account = Account::new();
let asset = "dummy_asset";
let amount = 1000u128;
let result = account.add_asset(asset, amount, false);
assert!(result.is_ok());
assert_eq!(account.utxos.len(), 1);
}
#[test]
fn accounts_accounts_mask_tag_consistency() {
let account = Account::new();
let account_mask = account.make_account_public_mask();
assert_eq!(account.make_tag(), account_mask.make_tag());
}
} }

View File

@ -1,7 +1,5 @@
use std::{fmt::Display, str::FromStr}; use std::{fmt::Display, str::FromStr};
use serde::{Deserialize, Serialize};
use crate::signature::PublicKey; use crate::signature::PublicKey;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
@ -59,28 +57,6 @@ impl Display for Address {
} }
} }
impl Serialize for Address {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let hex_string = self.to_string();
hex_string.serialize(serializer)
}
}
impl<'de> Deserialize<'de> for Address {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let hex_string = String::deserialize(deserializer)?;
Address::from_str(&hex_string).map_err(serde::de::Error::custom)
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{Address, address::AddressError}; use crate::{Address, address::AddressError};

View File

@ -547,6 +547,4 @@ mod tests {
} }
} }
// //