zcash_client_backend: Implement `TreeState::orchard_tree`
This commit is contained in:
parent
5ed788dc79
commit
9c3467e941
|
@ -81,6 +81,7 @@ and this library adheres to Rust's notion of
|
||||||
- `PROPOSAL_SER_V1`
|
- `PROPOSAL_SER_V1`
|
||||||
- `ProposalDecodingError`
|
- `ProposalDecodingError`
|
||||||
- `proposal` module, for parsing and serializing transaction proposals.
|
- `proposal` module, for parsing and serializing transaction proposals.
|
||||||
|
- `service::TreeState::orchard_tree` (behind the `orchard` feature flag)
|
||||||
- `impl Clone for zcash_client_backend::{
|
- `impl Clone for zcash_client_backend::{
|
||||||
zip321::{Payment, TransactionRequest, Zip321Error, parse::Param, parse::IndexedParam},
|
zip321::{Payment, TransactionRequest, Zip321Error, parse::Param, parse::IndexedParam},
|
||||||
wallet::WalletTransparentOutput,
|
wallet::WalletTransparentOutput,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! Generated code for handling light client protobuf structs.
|
//! Generated code for handling light client protobuf structs.
|
||||||
|
|
||||||
|
use incrementalmerkletree::frontier::CommitmentTree;
|
||||||
|
use nonempty::NonEmpty;
|
||||||
use std::{
|
use std::{
|
||||||
array::TryFromSliceError,
|
array::TryFromSliceError,
|
||||||
collections::BTreeMap,
|
collections::BTreeMap,
|
||||||
|
@ -7,10 +9,8 @@ use std::{
|
||||||
io,
|
io,
|
||||||
};
|
};
|
||||||
|
|
||||||
use incrementalmerkletree::frontier::CommitmentTree;
|
use sapling::{self, note::ExtractedNoteCommitment, Node};
|
||||||
|
use zcash_note_encryption::{EphemeralKeyBytes, COMPACT_NOTE_SIZE};
|
||||||
use nonempty::NonEmpty;
|
|
||||||
use sapling::{self, note::ExtractedNoteCommitment, Node, Nullifier, NOTE_COMMITMENT_TREE_DEPTH};
|
|
||||||
use zcash_primitives::{
|
use zcash_primitives::{
|
||||||
block::{BlockHash, BlockHeader},
|
block::{BlockHash, BlockHeader},
|
||||||
consensus::{self, BlockHeight, Parameters},
|
consensus::{self, BlockHeight, Parameters},
|
||||||
|
@ -19,8 +19,6 @@ use zcash_primitives::{
|
||||||
transaction::{components::amount::NonNegativeAmount, fees::StandardFeeRule, TxId},
|
transaction::{components::amount::NonNegativeAmount, fees::StandardFeeRule, TxId},
|
||||||
};
|
};
|
||||||
|
|
||||||
use zcash_note_encryption::{EphemeralKeyBytes, COMPACT_NOTE_SIZE};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
data_api::InputSource,
|
data_api::InputSource,
|
||||||
fees::{ChangeValue, TransactionBalance},
|
fees::{ChangeValue, TransactionBalance},
|
||||||
|
@ -32,6 +30,9 @@ use crate::{
|
||||||
#[cfg(feature = "transparent-inputs")]
|
#[cfg(feature = "transparent-inputs")]
|
||||||
use zcash_primitives::transaction::components::OutPoint;
|
use zcash_primitives::transaction::components::OutPoint;
|
||||||
|
|
||||||
|
#[cfg(feature = "orchard")]
|
||||||
|
use orchard::tree::MerkleHashOrchard;
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[allow(unknown_lints)]
|
#[allow(unknown_lints)]
|
||||||
#[allow(clippy::derive_partial_eq_without_eq)]
|
#[allow(clippy::derive_partial_eq_without_eq)]
|
||||||
|
@ -169,8 +170,8 @@ impl TryFrom<compact_formats::CompactSaplingOutput>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl compact_formats::CompactSaplingSpend {
|
impl compact_formats::CompactSaplingSpend {
|
||||||
pub fn nf(&self) -> Result<Nullifier, ()> {
|
pub fn nf(&self) -> Result<sapling::Nullifier, ()> {
|
||||||
Nullifier::from_slice(&self.nf).map_err(|_| ())
|
sapling::Nullifier::from_slice(&self.nf).map_err(|_| ())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,14 +199,35 @@ impl<SpendAuth> From<&orchard::Action<SpendAuth>> for compact_formats::CompactOr
|
||||||
|
|
||||||
impl service::TreeState {
|
impl service::TreeState {
|
||||||
/// Deserializes and returns the Sapling note commitment tree field of the tree state.
|
/// Deserializes and returns the Sapling note commitment tree field of the tree state.
|
||||||
pub fn sapling_tree(&self) -> io::Result<CommitmentTree<Node, NOTE_COMMITMENT_TREE_DEPTH>> {
|
pub fn sapling_tree(
|
||||||
|
&self,
|
||||||
|
) -> io::Result<CommitmentTree<Node, { sapling::NOTE_COMMITMENT_TREE_DEPTH }>> {
|
||||||
let sapling_tree_bytes = hex::decode(&self.sapling_tree).map_err(|e| {
|
let sapling_tree_bytes = hex::decode(&self.sapling_tree).map_err(|e| {
|
||||||
io::Error::new(
|
io::Error::new(
|
||||||
io::ErrorKind::InvalidData,
|
io::ErrorKind::InvalidData,
|
||||||
format!("Hex decoding of Sapling tree bytes failed: {:?}", e),
|
format!("Hex decoding of Sapling tree bytes failed: {:?}", e),
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
read_commitment_tree::<Node, _, NOTE_COMMITMENT_TREE_DEPTH>(&sapling_tree_bytes[..])
|
read_commitment_tree::<Node, _, { sapling::NOTE_COMMITMENT_TREE_DEPTH }>(
|
||||||
|
&sapling_tree_bytes[..],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deserializes and returns the Sapling note commitment tree field of the tree state.
|
||||||
|
#[cfg(feature = "orchard")]
|
||||||
|
pub fn orchard_tree(
|
||||||
|
&self,
|
||||||
|
) -> io::Result<CommitmentTree<MerkleHashOrchard, { orchard::NOTE_COMMITMENT_TREE_DEPTH as u8 }>>
|
||||||
|
{
|
||||||
|
let orchard_tree_bytes = hex::decode(&self.orchard_tree).map_err(|e| {
|
||||||
|
io::Error::new(
|
||||||
|
io::ErrorKind::InvalidData,
|
||||||
|
format!("Hex decoding of Orchard tree bytes failed: {:?}", e),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
read_commitment_tree::<MerkleHashOrchard, _, { orchard::NOTE_COMMITMENT_TREE_DEPTH as u8 }>(
|
||||||
|
&orchard_tree_bytes[..],
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue