From d1ee438dd430ba7ce48eac02b82382700d6a8a5a Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 16 Sep 2024 18:44:59 -0400 Subject: [PATCH] beginning of transparent tables --- zcash_client_memory/src/types/mod.rs | 3 + .../src/types/serialization/mod.rs | 3 + .../src/types/serialization/transaction.rs | 63 +++++++++++++++++-- .../src/types/serialization/transparent.rs | 25 ++++++++ zcash_client_memory/src/types/transparent.rs | 60 ++++++++++++++++++ zcash_client_memory/src/wallet_write.rs | 26 +++++++- 6 files changed, 173 insertions(+), 7 deletions(-) create mode 100644 zcash_client_memory/src/types/serialization/transparent.rs create mode 100644 zcash_client_memory/src/types/transparent.rs diff --git a/zcash_client_memory/src/types/mod.rs b/zcash_client_memory/src/types/mod.rs index 1a2e35a042..7d5a9035b7 100644 --- a/zcash_client_memory/src/types/mod.rs +++ b/zcash_client_memory/src/types/mod.rs @@ -12,3 +12,6 @@ pub(crate) use notes::*; pub(crate) use nullifier::*; pub(crate) use transaction::*; + +pub(crate) mod transparent; +pub(crate) use transparent::*; diff --git a/zcash_client_memory/src/types/serialization/mod.rs b/zcash_client_memory/src/types/serialization/mod.rs index 8dcc1c80f8..127ffa7ff3 100644 --- a/zcash_client_memory/src/types/serialization/mod.rs +++ b/zcash_client_memory/src/types/serialization/mod.rs @@ -18,6 +18,9 @@ pub use memo::*; pub use array::*; pub use bytes::*; +mod transparent; +pub use transparent::*; + impl ToArray for BlockHash { fn to_array(&self) -> [u8; 32] { self.0 diff --git a/zcash_client_memory/src/types/serialization/transaction.rs b/zcash_client_memory/src/types/serialization/transaction.rs index 506b85ed3f..249b558dc8 100644 --- a/zcash_client_memory/src/types/serialization/transaction.rs +++ b/zcash_client_memory/src/types/serialization/transaction.rs @@ -1,13 +1,15 @@ -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Deserializer, Serialize}; -use serde_with::serde_as; - -use serde_with::FromInto; - -use zcash_primitives::transaction::TxId; +use serde_with::{serde_as, TryFromInto}; +use serde_with::{DeserializeAs, SerializeAs}; use super::FromArray; use super::ToArray; +use serde_with::FromInto; +use zcash_primitives::legacy::Script; +use zcash_primitives::transaction::components::amount::NonNegativeAmount; +use zcash_primitives::transaction::components::TxOut; +use zcash_primitives::transaction::TxId; impl ToArray for TxId { fn to_array(&self) -> [u8; 32] { @@ -35,3 +37,52 @@ pub enum TransactionStatusDef { /// block at the provided height. Mined(#[serde_as(as = "FromInto")] zcash_primitives::consensus::BlockHeight), } + +#[serde_as] +#[derive(Serialize, Deserialize)] +#[serde(remote = "TxOut")] +pub struct TxOutDef { + #[serde_as(as = "TryFromInto")] + pub value: NonNegativeAmount, + #[serde_as(as = "ScriptDef")] + pub script_pubkey: Script, +} + +impl SerializeAs for TxOutDef { + fn serialize_as(value: &TxOut, serializer: S) -> Result + where + S: serde::Serializer, + { + TxOutDef::serialize(value, serializer) + } +} + +impl<'de> DeserializeAs<'de, TxOut> for TxOutDef { + fn deserialize_as(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + TxOutDef::deserialize(deserializer) + } +} + +#[derive(Serialize, Deserialize)] +#[serde(remote = "Script")] +pub struct ScriptDef(pub Vec); +impl SerializeAs