Skip to content

Commit 92fdd10

Browse files
committed
feat: decrypt addresses
1 parent f432187 commit 92fdd10

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/lib.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub struct DecryptedOutput {
2121
pub memo: String,
2222
pub amount: f64, // Amount in ZEC
2323
pub transfer_type: String,
24+
pub from: String,
25+
pub to: String,
2426
}
2527

2628
#[derive(Serialize, Deserialize)]
@@ -62,6 +64,25 @@ impl DecryptedOutput {
6264
fn decode_note_value(zatoshis: Zatoshis) -> f64 {
6365
zatoshis.into_u64() as f64 / 100_000_000.0
6466
}
67+
68+
fn decode_address(address: &str) -> String {
69+
let address_bytes = address.as_bytes();
70+
let address_len = address_bytes.iter().position(|&b| b == 0).unwrap_or(address_bytes.len());
71+
72+
if address_len == 0 {
73+
return String::from("");
74+
}
75+
76+
String::from_utf8(address_bytes[..address_len].to_vec()).unwrap_or_default()
77+
}
78+
79+
fn decode_from(from: &str) -> String {
80+
DecryptedOutput::decode_address(from)
81+
}
82+
83+
fn decode_to(to: &str) -> String {
84+
DecryptedOutput::decode_address(to)
85+
}
6586
}
6687

6788
#[wasm_bindgen]

0 commit comments

Comments
 (0)