-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zcash_client_sqlite: Support sending to t-addrs
- Loading branch information
Showing
4 changed files
with
93 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//! Structs for handling supported address types. | ||
|
||
use pairing::bls12_381::Bls12; | ||
use sapling_crypto::primitives::PaymentAddress; | ||
use zcash_client_backend::encoding::{ | ||
decode_payment_address, decode_transparent_address, encode_payment_address, | ||
encode_transparent_address, | ||
}; | ||
use zcash_primitives::legacy::TransparentAddress; | ||
|
||
use super::Error; | ||
|
||
#[cfg(feature = "mainnet")] | ||
use zcash_client_backend::constants::mainnet::{ | ||
B58_PUBKEY_ADDRESS_PREFIX, B58_SCRIPT_ADDRESS_PREFIX, HRP_SAPLING_PAYMENT_ADDRESS, | ||
}; | ||
|
||
#[cfg(not(feature = "mainnet"))] | ||
use zcash_client_backend::constants::testnet::{ | ||
B58_PUBKEY_ADDRESS_PREFIX, B58_SCRIPT_ADDRESS_PREFIX, HRP_SAPLING_PAYMENT_ADDRESS, | ||
}; | ||
|
||
/// An address that funds can be sent to. | ||
pub enum RecipientAddress { | ||
Shielded(PaymentAddress<Bls12>), | ||
Transparent(TransparentAddress), | ||
} | ||
|
||
impl From<PaymentAddress<Bls12>> for RecipientAddress { | ||
fn from(addr: PaymentAddress<Bls12>) -> Self { | ||
RecipientAddress::Shielded(addr) | ||
} | ||
} | ||
|
||
impl From<TransparentAddress> for RecipientAddress { | ||
fn from(addr: TransparentAddress) -> Self { | ||
RecipientAddress::Transparent(addr) | ||
} | ||
} | ||
|
||
impl RecipientAddress { | ||
pub fn from_str(s: &str) -> Result<Option<Self>, Error> { | ||
if let Some(pa) = decode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS, s)? { | ||
Ok(Some(RecipientAddress::Shielded(pa))) | ||
} else if let Some(addr) = | ||
decode_transparent_address(&B58_PUBKEY_ADDRESS_PREFIX, &B58_SCRIPT_ADDRESS_PREFIX, s)? | ||
{ | ||
Ok(Some(RecipientAddress::Transparent(addr))) | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
|
||
pub fn to_string(&self) -> String { | ||
match self { | ||
RecipientAddress::Shielded(pa) => { | ||
encode_payment_address(HRP_SAPLING_PAYMENT_ADDRESS, pa) | ||
} | ||
RecipientAddress::Transparent(addr) => encode_transparent_address( | ||
&B58_PUBKEY_ADDRESS_PREFIX, | ||
&B58_SCRIPT_ADDRESS_PREFIX, | ||
addr, | ||
), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters