Payment URI fixes
This commit is contained in:
parent
337fe20b4f
commit
3565a6297f
14
Cargo.toml
14
Cargo.toml
|
@ -121,32 +121,32 @@ apple_metal = ["metal", "objc", "block"]
|
|||
|
||||
[dependencies.zcash_params]
|
||||
git = "https://github.com/hhanh00/zcash-params.git"
|
||||
rev = "9fabe6aa8b3ca7099dc39db16fe126129c7755b8"
|
||||
rev = "bdb7aa490b32c204307c717f5dcea18358f7be3b"
|
||||
|
||||
[dependencies.zcash_client_backend]
|
||||
git = "https://github.com/hhanh00/librustzcash.git"
|
||||
rev = "2cb26889d9384c7f43f1bd8417a5c088ae380323"
|
||||
rev = "ad4a1c61fdaf04ac4fb884976ad175196e695264"
|
||||
|
||||
[dependencies.zcash_primitives]
|
||||
git = "https://github.com/hhanh00/librustzcash.git"
|
||||
rev = "2cb26889d9384c7f43f1bd8417a5c088ae380323"
|
||||
rev = "ad4a1c61fdaf04ac4fb884976ad175196e695264"
|
||||
features = [ "transparent-inputs" ]
|
||||
|
||||
[dependencies.zcash_proofs]
|
||||
git = "https://github.com/hhanh00/librustzcash.git"
|
||||
rev = "2cb26889d9384c7f43f1bd8417a5c088ae380323"
|
||||
rev = "ad4a1c61fdaf04ac4fb884976ad175196e695264"
|
||||
|
||||
[dependencies.zcash_address]
|
||||
git = "https://github.com/hhanh00/librustzcash.git"
|
||||
rev = "2cb26889d9384c7f43f1bd8417a5c088ae380323"
|
||||
rev = "ad4a1c61fdaf04ac4fb884976ad175196e695264"
|
||||
|
||||
[dependencies.zcash_encoding]
|
||||
git = "https://github.com/hhanh00/librustzcash.git"
|
||||
rev = "2cb26889d9384c7f43f1bd8417a5c088ae380323"
|
||||
rev = "ad4a1c61fdaf04ac4fb884976ad175196e695264"
|
||||
|
||||
[dependencies.zcash_note_encryption]
|
||||
git = "https://github.com/hhanh00/librustzcash.git"
|
||||
rev = "2cb26889d9384c7f43f1bd8417a5c088ae380323"
|
||||
rev = "ad4a1c61fdaf04ac4fb884976ad175196e695264"
|
||||
|
||||
[build-dependencies]
|
||||
tonic-build = "0.7.2"
|
||||
|
|
|
@ -250,7 +250,10 @@ void truncate_sync_data(void);
|
|||
|
||||
void delete_account(uint8_t coin, uint32_t account);
|
||||
|
||||
struct CResult_____c_char make_payment_uri(char *address, uint64_t amount, char *memo);
|
||||
struct CResult_____c_char make_payment_uri(uint8_t coin,
|
||||
char *address,
|
||||
uint64_t amount,
|
||||
char *memo);
|
||||
|
||||
struct CResult_____c_char parse_payment_uri(char *uri);
|
||||
|
||||
|
|
|
@ -344,7 +344,7 @@ pub unsafe extern "C" fn is_valid_key(coin: u8, key: *mut c_char) -> i8 {
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn valid_address(coin: u8, address: *mut c_char) -> bool {
|
||||
from_c_str!(address);
|
||||
crate::key2::is_valid_address(coin, &address)
|
||||
crate::key2::decode_address(coin, &address).is_some()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -663,13 +663,14 @@ pub unsafe extern "C" fn delete_account(coin: u8, account: u32) {
|
|||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn make_payment_uri(
|
||||
coin: u8,
|
||||
address: *mut c_char,
|
||||
amount: u64,
|
||||
memo: *mut c_char,
|
||||
) -> CResult<*mut c_char> {
|
||||
from_c_str!(memo);
|
||||
from_c_str!(address);
|
||||
let res = crate::api::payment_uri::make_payment_uri(&address, amount, &memo);
|
||||
let res = crate::api::payment_uri::make_payment_uri(coin, &address, amount, &memo);
|
||||
to_cresult_str(res)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
//! encode and decode Payment URI
|
||||
|
||||
use crate::coinconfig::CoinConfig;
|
||||
use crate::key2::decode_address;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::convert::TryFrom;
|
||||
use std::str::FromStr;
|
||||
use zcash_client_backend::address::RecipientAddress;
|
||||
use zcash_client_backend::zip321::{Payment, TransactionRequest};
|
||||
use zcash_primitives::memo::Memo;
|
||||
use zcash_primitives::transaction::components::Amount;
|
||||
|
@ -14,10 +14,14 @@ use zcash_primitives::transaction::components::Amount;
|
|||
/// * `address`: recipient address
|
||||
/// * `amount`: amount in zats
|
||||
/// * `memo`: memo text
|
||||
pub fn make_payment_uri(address: &str, amount: u64, memo: &str) -> anyhow::Result<String> {
|
||||
let c = CoinConfig::get_active();
|
||||
let addr = RecipientAddress::decode(c.chain.network(), address)
|
||||
.ok_or_else(|| anyhow::anyhow!("Invalid address"))?;
|
||||
pub fn make_payment_uri(
|
||||
coin: u8,
|
||||
address: &str,
|
||||
amount: u64,
|
||||
memo: &str,
|
||||
) -> anyhow::Result<String> {
|
||||
let c = CoinConfig::get(coin);
|
||||
let addr = decode_address(coin, address).ok_or_else(|| anyhow::anyhow!("Invalid address"))?;
|
||||
let payment = Payment {
|
||||
recipient_address: addr,
|
||||
amount: Amount::from_u64(amount).map_err(|_| anyhow::anyhow!("Invalid amount"))?,
|
||||
|
|
|
@ -410,9 +410,9 @@ pub mod compact_tx_streamer_client {
|
|||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::BlockRange>,
|
||||
) -> Result<
|
||||
tonic::Response<tonic::codec::Streaming<super::CompactBlock>>,
|
||||
tonic::Status,
|
||||
> {
|
||||
tonic::Response<tonic::codec::Streaming<super::CompactBlock>>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
|
@ -473,9 +473,9 @@ pub mod compact_tx_streamer_client {
|
|||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::TransparentAddressBlockFilter>,
|
||||
) -> Result<
|
||||
tonic::Response<tonic::codec::Streaming<super::RawTransaction>>,
|
||||
tonic::Status,
|
||||
> {
|
||||
tonic::Response<tonic::codec::Streaming<super::RawTransaction>>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
|
@ -544,9 +544,9 @@ pub mod compact_tx_streamer_client {
|
|||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::Exclude>,
|
||||
) -> Result<
|
||||
tonic::Response<tonic::codec::Streaming<super::CompactTx>>,
|
||||
tonic::Status,
|
||||
> {
|
||||
tonic::Response<tonic::codec::Streaming<super::CompactTx>>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
|
@ -568,9 +568,9 @@ pub mod compact_tx_streamer_client {
|
|||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::Empty>,
|
||||
) -> Result<
|
||||
tonic::Response<tonic::codec::Streaming<super::RawTransaction>>,
|
||||
tonic::Status,
|
||||
> {
|
||||
tonic::Response<tonic::codec::Streaming<super::RawTransaction>>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
|
@ -632,9 +632,9 @@ pub mod compact_tx_streamer_client {
|
|||
&mut self,
|
||||
request: impl tonic::IntoRequest<super::GetAddressUtxosArg>,
|
||||
) -> Result<
|
||||
tonic::Response<tonic::codec::Streaming<super::GetAddressUtxosReply>>,
|
||||
tonic::Status,
|
||||
> {
|
||||
tonic::Response<tonic::codec::Streaming<super::GetAddressUtxosReply>>,
|
||||
tonic::Status,
|
||||
> {
|
||||
self.inner
|
||||
.ready()
|
||||
.await
|
||||
|
|
23
src/key2.rs
23
src/key2.rs
|
@ -1,10 +1,10 @@
|
|||
use crate::coinconfig::CoinConfig;
|
||||
use anyhow::anyhow;
|
||||
use bip39::{Language, Mnemonic, Seed};
|
||||
use zcash_client_backend::address::RecipientAddress;
|
||||
use zcash_client_backend::encoding::{
|
||||
decode_extended_full_viewing_key, decode_extended_spending_key, decode_payment_address,
|
||||
decode_transparent_address, encode_extended_full_viewing_key, encode_extended_spending_key,
|
||||
encode_payment_address,
|
||||
decode_extended_full_viewing_key, decode_extended_spending_key,
|
||||
encode_extended_full_viewing_key, encode_extended_spending_key, encode_payment_address,
|
||||
};
|
||||
use zcash_client_backend::keys::UnifiedFullViewingKey;
|
||||
use zcash_primitives::consensus::{Network, Parameters};
|
||||
|
@ -77,23 +77,10 @@ pub fn is_valid_key(coin: u8, key: &str) -> i8 {
|
|||
-1
|
||||
}
|
||||
|
||||
#[allow(dead_code)] // Used by C FFI
|
||||
pub fn is_valid_address(coin: u8, address: &str) -> bool {
|
||||
pub fn decode_address(coin: u8, address: &str) -> Option<RecipientAddress> {
|
||||
let c = CoinConfig::get(coin);
|
||||
let network = c.chain.network();
|
||||
if decode_payment_address(network.hrp_sapling_payment_address(), address).is_ok() {
|
||||
true
|
||||
} else if let Ok(Some(_)) = decode_transparent_address(
|
||||
&network.b58_pubkey_address_prefix(),
|
||||
&network.b58_script_address_prefix(),
|
||||
address,
|
||||
) {
|
||||
true
|
||||
} else if zcash_client_backend::address::RecipientAddress::decode(network, address).is_some() {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
zcash_client_backend::address::RecipientAddress::decode(network, address)
|
||||
}
|
||||
|
||||
fn derive_secret_key(
|
||||
|
|
Loading…
Reference in New Issue