use zingo_netutils::lightwallet_protocol;
pub mod proposal;
pub enum PollReport<T, E> {
NoHandle,
NotReady,
Ready(Result<T, E>),
}
#[derive(Debug, Clone)]
pub struct ServerInfo {
pub version: String,
pub git_commit: String,
pub server_uri: http::Uri,
pub vendor: String,
pub taddr_support: bool,
pub chain_name: String,
pub sapling_activation_height: u64,
pub consensus_branch_id: String,
pub latest_block_height: u64,
}
impl ServerInfo {
pub fn from_lightd_info(info: lightwallet_protocol::LightdInfo, server_uri: http::Uri) -> Self {
Self {
version: info.version,
git_commit: info.git_commit,
server_uri,
vendor: info.vendor,
taddr_support: info.taddr_support,
chain_name: info.chain_name,
sapling_activation_height: info.sapling_activation_height,
consensus_branch_id: info.consensus_branch_id,
latest_block_height: info.block_height,
}
}
}
impl From<ServerInfo> for json::JsonValue {
fn from(info: ServerInfo) -> Self {
json::object! {
"version" => info.version,
"git_commit" => info.git_commit,
"server_uri" => info.server_uri.to_string(),
"vendor" => info.vendor,
"taddr_support" => info.taddr_support,
"chain_name" => info.chain_name,
"sapling_activation_height" => info.sapling_activation_height,
"consensus_branch_id" => info.consensus_branch_id,
"latest_block_height" => info.latest_block_height
}
}
}
pub mod receivers {
use zcash_address::ZcashAddress;
use zcash_client_backend::zip321::Payment;
use zcash_client_backend::zip321::PaymentError;
use zcash_client_backend::zip321::TransactionRequest;
use zcash_client_backend::zip321::Zip321Error;
use zcash_protocol::memo::MemoBytes;
use zcash_protocol::value::Zatoshis;
pub type Receivers = Vec<Receiver>;
#[derive(Clone, Debug, PartialEq)]
pub struct Receiver {
pub recipient_address: ZcashAddress,
pub amount: Zatoshis,
pub memo: Option<MemoBytes>,
}
impl Receiver {
pub(crate) fn new(
recipient_address: ZcashAddress,
amount: Zatoshis,
memo: Option<MemoBytes>,
) -> Self {
Self {
recipient_address,
amount,
memo,
}
}
}
impl TryFrom<Receiver> for Payment {
type Error = PaymentError;
fn try_from(receiver: Receiver) -> Result<Self, Self::Error> {
Payment::new(
receiver.recipient_address,
Some(receiver.amount),
receiver.memo,
None,
None,
vec![],
)
}
}
pub fn transaction_request_from_receivers(
receivers: Receivers,
) -> Result<TransactionRequest, Zip321Error> {
let payments = receivers
.into_iter()
.enumerate()
.map(|(i, receiver)| {
Payment::try_from(receiver).map_err(|e| match e {
PaymentError::TransparentMemo => Zip321Error::TransparentMemo(i),
PaymentError::ZeroValuedTransparentOutput => {
Zip321Error::ZeroValuedTransparentOutput(i)
}
})
})
.collect::<Result<Vec<_>, Zip321Error>>()?;
TransactionRequest::new(payments)
}
}