Skip to content

Commit

Permalink
feat: zcash basic transaction view
Browse files Browse the repository at this point in the history
  • Loading branch information
soralit committed Nov 26, 2024
1 parent e1b7dca commit 24ab478
Show file tree
Hide file tree
Showing 14 changed files with 344 additions and 23 deletions.
4 changes: 2 additions & 2 deletions rust/apps/zcash/src/pczt/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn parse_pczt(
my_output_value = orchard
.get_to()
.iter()
.filter(|v| v.get_is_mine()&&!v.get_is_change())
.filter(|v| v.get_visible()&&!v.get_is_change())
.fold(0, |acc, to| acc + to.get_amount());
Some(())
});
Expand All @@ -100,7 +100,7 @@ pub fn parse_pczt(
my_output_value += transparent
.get_to()
.iter()
.filter(|v| v.get_is_mine()&&!v.get_is_change())
.filter(|v| v.get_visible()&&!v.get_is_change())
.fold(0, |acc, to| acc + to.get_amount());
Some(())
});
Expand Down
2 changes: 1 addition & 1 deletion rust/apps/zcash/src/pczt/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl_public_struct!(ParsedTo {
value: String,
amount: u64,
is_change: bool,
is_mine: bool,
visible: bool,
memo: Option<String>
});

Expand Down
2 changes: 2 additions & 0 deletions rust/rust_c/src/common/src/ur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ pub enum ViewType {
#[cfg(feature = "multi-coins")]
TonSignProof,
#[cfg(feature = "multi-coins")]
ZcashTx,
#[cfg(feature = "multi-coins")]
AptosTx,
WebAuthResult,
#[cfg(feature = "multi-coins")]
Expand Down
76 changes: 68 additions & 8 deletions rust/rust_c/src/zcash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ extern crate alloc;

pub mod structs;

use core::slice;
use core::{ptr::null_mut, slice};

use alloc::boxed::Box;
use app_zcash::get_address;
use alloc::{boxed::Box, string::ToString, vec};
use app_zcash::{
get_address,
pczt::structs::{ParsedFrom, ParsedOrchard, ParsedPczt, ParsedTo, ParsedTransparent},
};
use common_rust_c::{
structs::{Response, SimpleResponse},
types::{PtrBytes, PtrString},
structs::{Response, SimpleResponse, TransactionParseResult},
types::{Ptr, PtrBytes, PtrString, PtrUR},
utils::{convert_c_char, recover_c_char},
};
use keystore::algorithms::zcash::{self, calculate_seed_fingerprint, derive_ufvk};
use cty::c_char;
use keystore::algorithms::zcash::{self, calculate_seed_fingerprint, derive_ufvk};
use structs::DisplayPczt;

#[no_mangle]
pub extern "C" fn derive_zcash_ufvk(seed: PtrBytes, seed_len: u32) -> *mut SimpleResponse<c_char> {
Expand All @@ -26,11 +30,16 @@ pub extern "C" fn derive_zcash_ufvk(seed: PtrBytes, seed_len: u32) -> *mut Simpl
}

#[no_mangle]
pub extern "C" fn calculate_zcash_seed_fingerprint(seed: PtrBytes, seed_len: u32) -> *mut SimpleResponse<u8> {
pub extern "C" fn calculate_zcash_seed_fingerprint(
seed: PtrBytes,
seed_len: u32,
) -> *mut SimpleResponse<u8> {
let seed = unsafe { slice::from_raw_parts(seed, seed_len as usize) };
let sfp = calculate_seed_fingerprint(seed);
match sfp {
Ok(bytes) => SimpleResponse::success(Box::into_raw(Box::new(bytes)) as *mut u8).simple_c_ptr(),
Ok(bytes) => {
SimpleResponse::success(Box::into_raw(Box::new(bytes)) as *mut u8).simple_c_ptr()
}
Err(e) => SimpleResponse::from(e).simple_c_ptr(),
}
}
Expand All @@ -46,3 +55,54 @@ pub extern "C" fn generate_zcash_default_address(
Err(e) => SimpleResponse::from(e).simple_c_ptr(),
}
}

#[no_mangle]
pub extern "C" fn parse_zcash_tx(
tx: PtrUR,
ufvk: PtrString,
) -> Ptr<TransactionParseResult<DisplayPczt>> {
TransactionParseResult::success(mock_parsed_pczt().c_ptr()).c_ptr()
}

fn mock_parsed_pczt() -> DisplayPczt {
let parsed = ParsedPczt::new(
Some(ParsedTransparent::new(
vec![ParsedFrom::new(
"t1QN3Kxh5wPFDi9ZPrTCgMVY5X4Rz96LkVC".to_string(),
"1 ZEC".to_string(),
1,
true,
)],
vec![ParsedTo::new(
"t1QN3Kxh5wPFDi9ZPrTCgMVY5X4Rz96LkVC".to_string(),
"1 ZEC".to_string(),
1,
false,
true,
None,
)],
)),
Some(ParsedOrchard::new(
vec![ParsedFrom::new(
"u13axqdhqadqf3aua82uvnp8wle5vf8fgvnxhzr8nd2kpc23d3d06r25cgzsx4gz8gastt8lcqz4v2kyfdj0zvlkhv4vjudlxsrvprx48y".to_string(),
"1 ZEC".to_string(),
1,
true,
)],
vec![
ParsedTo::new(
"u13axqdhqadqf3aua82uvnp8wle5vf8fgvnxhzr8nd2kpc23d3d06r25cgzsx4gz8gastt8lcqz4v2kyfdj0zvlkhv4vjudlxsrvprx48y".to_string(),
"1 ZEC".to_string(),
1,
false,
true,
Some("this is a memo".to_string()),
),
ParsedTo::new("u13axqdhqadqf3aua82uvnp8wle5vf8fgvnxhzr8nd2kpc23d3d06r25cgzsx4gz8gastt8lcqz4v2kyfdj0zvlkhv4vjudlxsrvprx48y".to_string(), "1 ZEC".to_string(), 1, true, true, None),
ParsedTo::new("u13axqdhqadqf3aua82uvnp8wle5vf8fgvnxhzr8nd2kpc23d3d06r25cgzsx4gz8gastt8lcqz4v2kyfdj0zvlkhv4vjudlxsrvprx48y".to_string(), "1 ZEC".to_string(), 1, false, false, None),
],
)),
"2 ZEC".to_string(),
);
DisplayPczt::from(&parsed)
}
4 changes: 2 additions & 2 deletions rust/rust_c/src/zcash/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct DisplayTo {
pub address: PtrString,
pub value: PtrString,
pub is_change: bool,
pub is_mine: bool,
pub visible: bool,
pub memo: PtrString,
}

Expand All @@ -95,7 +95,7 @@ impl From<&ParsedTo> for DisplayTo {
address: convert_c_char(to.get_address()),
value: convert_c_char(to.get_value()),
is_change: to.get_is_change(),
is_mine: to.get_is_mine(),
visible: to.get_visible(),
memo: to.get_memo().map(convert_c_char).unwrap_or(null_mut()),
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/ui/gui_analyze/gui_analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ const static GuiAnalyze_t g_analyzeArray[] = {
},
{
REMAPVIEW_ZCASH,
#ifndef COMPILE_SIMULATOR
"{\"name\":\"ton_page\",\"type\":\"tabview\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"children\":[{\"type\":\"tabview_child\",\"index\":1,\"tab_name\":\"Overview\",\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiTonTxOverview\"}]},{\"type\":\"tabview_child\",\"index\":2,\"tab_name\":\"Raw Data\",\"text_color\":16777215,\"font\":\"openSansEnIllustrate\",\"children\":[{\"type\":\"custom_container\",\"bg_color\":0,\"bg_opa\":0,\"pos\":[0,12],\"custom_show_func\":\"GuiTonTxRawData\"}]}]}",
#ifndef COMPILE_SIMULATOR
"{\"name\":\"zcash_page\",\"type\":\"custom_container\",\"pos\":[36,0],\"size\":[408,900],\"bg_color\":0,\"custom_show_func\":\"GuiZcashOverview\"}",
#else
PC_SIMULATOR_PATH "/page_zcash.json",
#endif
GuiGetTonProofGUIData,
GuiGetZcashGUIData,
NULL,
FreeArMemory,
}
Expand Down Expand Up @@ -1339,6 +1339,8 @@ GetCustomContainerFunc GuiTemplateCustomFunc(char *funcName)
return GuiStellarHashNotice;
} else if (!strcmp(funcName, "GuiTonTxOverview")) {
return GuiTonTxOverview;
} else if (!strcmp(funcName, "GuiZcashOverview")) {
return GuiZcashOverview;
} else if (!strcmp(funcName, "GuiTonTxRawData")) {
return GuiTonTxRawData;
} else if (!strcmp(funcName, "GuiTonProofOverview")) {
Expand Down Expand Up @@ -1760,6 +1762,8 @@ GuiRemapViewType ViewTypeReMap(uint8_t viewType)
return REMAPVIEW_TON;
case TonSignProof:
return REMAPVIEW_TON_SIGNPROOF;
case ZcashTx:
return REMAPVIEW_ZCASH;
#endif
default:
return REMAPVIEW_BUTT;
Expand Down
2 changes: 2 additions & 0 deletions src/ui/gui_chain/gui_chain.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ GuiChainCoinType ViewTypeToChainTypeSwitch(uint8_t ViewType)
case TonTx:
case TonSignProof:
return CHAIN_TON;
case ZcashTx:
return CHAIN_ZCASH;
#endif
default:
return CHAIN_BUTT;
Expand Down
3 changes: 2 additions & 1 deletion src/ui/gui_chain/gui_chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "gui_ar.h"
#include "gui_stellar.h"
#include "gui_ton.h"
#include "gui_zcash.h"
#endif

typedef void (*SetChainDataFunc)(void *resultData, void *multiResultData, bool multi);
Expand All @@ -24,7 +25,6 @@ typedef enum {
CHAIN_BTC,
#ifndef BTC_ONLY
CHAIN_ETH,
CHAIN_ZEC,
CHAIN_SOL,
CHAIN_BNB,
CHAIN_HNT,
Expand Down Expand Up @@ -74,6 +74,7 @@ typedef enum {
CHAIN_UMEE,
CHAIN_QCK,
CHAIN_TGD,
CHAIN_ZCASH,

#endif
CHAIN_BUTT,
Expand Down
Loading

0 comments on commit 24ab478

Please sign in to comment.