1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! This is a mod for data structs that will be used across all sections of zingolib.
pub mod proposal;
/// Return type for fns that poll the status of task handles.
pub enum PollReport<T, E> {
/// Task has not been launched.
NoHandle,
/// Task is not complete.
NotReady,
/// Task has completed successfully or failed.
Ready(Result<T, E>),
}
/// transforming data related to the destination of a send.
pub mod receivers {
use zcash_address::ZcashAddress;
use zcash_client_backend::zip321::Payment;
use zcash_client_backend::zip321::TransactionRequest;
use zcash_client_backend::zip321::Zip321Error;
use zcash_primitives::memo::MemoBytes;
use zcash_protocol::value::Zatoshis;
/// A list of Receivers
pub(crate) type Receivers = Vec<Receiver>;
/// The superficial representation of the the consumer's intended receiver
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct Receiver {
pub(crate) recipient_address: ZcashAddress,
pub(crate) amount: Zatoshis,
pub(crate) memo: Option<MemoBytes>,
}
impl Receiver {
/// Create a new Receiver
pub(crate) fn new(
recipient_address: ZcashAddress,
amount: Zatoshis,
memo: Option<MemoBytes>,
) -> Self {
Self {
recipient_address,
amount,
memo,
}
}
}
impl From<Receiver> for Payment {
fn from(receiver: Receiver) -> Self {
Payment::new(
receiver.recipient_address,
receiver.amount,
receiver.memo,
None,
None,
vec![],
)
.expect("memo compatibility checked in 'parse_send_args'")
}
}
/// Creates a [`zcash_client_backend::zip321::TransactionRequest`] from receivers.
/// Note this fn is called to calculate the spendable_shielded balance
/// shielding and TEX should be handled mutually exclusively
pub(crate) fn transaction_request_from_receivers(
receivers: Receivers,
) -> Result<TransactionRequest, Zip321Error> {
// If this succeeds:
// * zingolib learns whether there is a TEX address
// * if there's a TEX address it's readable.
let payments = receivers
.into_iter()
.map(|receiver| receiver.into())
.collect();
TransactionRequest::new(payments)
}
}