use zcash_note_encryption::EphemeralKeyBytes;
use zcash_primitives::{
consensus::BlockHeight,
keys::OutgoingViewingKey,
legacy::TransparentAddress,
merkle_tree::IncrementalWitness,
sapling::{
note::ExtractedNoteCommitment, Diversifier, Node, Note, Nullifier, PaymentAddress, Rseed,
},
transaction::{
components::{
sapling,
transparent::{self, OutPoint, TxOut},
Amount,
},
TxId,
},
zip32::AccountId,
};
pub struct WalletTx<N> {
pub txid: TxId,
pub index: usize,
pub num_spends: usize,
pub num_outputs: usize,
pub shielded_spends: Vec<WalletShieldedSpend>,
pub shielded_outputs: Vec<WalletShieldedOutput<N>>,
}
#[derive(Debug, Clone)]
pub struct WalletTransparentOutput {
outpoint: OutPoint,
txout: TxOut,
height: BlockHeight,
recipient_address: TransparentAddress,
}
impl WalletTransparentOutput {
pub fn from_parts(
outpoint: OutPoint,
txout: TxOut,
height: BlockHeight,
) -> Option<WalletTransparentOutput> {
txout
.recipient_address()
.map(|recipient_address| WalletTransparentOutput {
outpoint,
txout,
height,
recipient_address,
})
}
pub fn outpoint(&self) -> &OutPoint {
&self.outpoint
}
pub fn txout(&self) -> &TxOut {
&self.txout
}
pub fn height(&self) -> BlockHeight {
self.height
}
pub fn recipient_address(&self) -> &TransparentAddress {
&self.recipient_address
}
pub fn value(&self) -> Amount {
self.txout.value
}
}
impl transparent::fees::InputView for WalletTransparentOutput {
fn outpoint(&self) -> &OutPoint {
&self.outpoint
}
fn coin(&self) -> &TxOut {
&self.txout
}
}
pub struct WalletShieldedSpend {
pub index: usize,
pub nf: Nullifier,
pub account: AccountId,
}
pub struct WalletShieldedOutput<N> {
pub index: usize,
pub cmu: ExtractedNoteCommitment,
pub ephemeral_key: EphemeralKeyBytes,
pub account: AccountId,
pub note: Note,
pub to: PaymentAddress,
pub is_change: bool,
pub witness: IncrementalWitness<Node>,
pub nf: N,
}
pub struct SpendableNote<NoteRef> {
pub note_id: NoteRef,
pub diversifier: Diversifier,
pub note_value: Amount,
pub rseed: Rseed,
pub witness: IncrementalWitness<Node>,
}
impl<NoteRef> sapling::fees::InputView<NoteRef> for SpendableNote<NoteRef> {
fn note_id(&self) -> &NoteRef {
&self.note_id
}
fn value(&self) -> Amount {
self.note_value
}
}
pub enum OvkPolicy {
Sender,
Custom(OutgoingViewingKey),
Discard,
}