zcash_client_backend/fees/
orchard.rs1use std::convert::Infallible;
5
6use orchard::{builder::BundleType, bundle::BundleVersion};
7use zcash_protocol::value::Zatoshis;
8
9pub(crate) fn transactional_action_count(
17 bundle_type: BundleType,
18 bundle_version: BundleVersion,
19 num_spends: usize,
20 num_outputs: usize,
21) -> Result<usize, &'static str> {
22 bundle_type.num_actions(bundle_version.default_flags(), num_spends, num_outputs)
23}
24
25pub trait BundleView<NoteRef> {
28 type In: InputView<NoteRef>;
30 type Out: OutputView;
32
33 fn bundle_version(&self) -> BundleVersion;
35 fn inputs(&self) -> &[Self::In];
37 fn outputs(&self) -> &[Self::Out];
39}
40
41impl<'a, NoteRef, In: InputView<NoteRef>, Out: OutputView> BundleView<NoteRef>
42 for (BundleVersion, &'a [In], &'a [Out])
43{
44 type In = In;
45 type Out = Out;
46
47 fn bundle_version(&self) -> BundleVersion {
48 self.0
49 }
50
51 fn inputs(&self) -> &[In] {
52 self.1
53 }
54
55 fn outputs(&self) -> &[Out] {
56 self.2
57 }
58}
59
60pub struct EmptyBundleView;
62
63impl<NoteRef> BundleView<NoteRef> for EmptyBundleView {
64 type In = Infallible;
65 type Out = Infallible;
66
67 fn bundle_version(&self) -> BundleVersion {
68 BundleVersion::orchard_v2()
72 }
73
74 fn inputs(&self) -> &[Self::In] {
75 &[]
76 }
77
78 fn outputs(&self) -> &[Self::Out] {
79 &[]
80 }
81}
82
83pub trait InputView<NoteRef> {
86 fn note_id(&self) -> &NoteRef;
88 fn value(&self) -> Zatoshis;
90}
91
92impl<N> InputView<N> for Infallible {
93 fn note_id(&self) -> &N {
94 unreachable!()
95 }
96 fn value(&self) -> Zatoshis {
97 unreachable!()
98 }
99}
100
101pub trait OutputView {
104 fn value(&self) -> Zatoshis;
106}
107
108impl OutputView for Infallible {
109 fn value(&self) -> Zatoshis {
110 unreachable!()
111 }
112}
113
114impl OutputView for Zatoshis {
115 fn value(&self) -> Zatoshis {
116 *self
117 }
118}