zcash-haskell/librustzcash-wrapper/src/lib.rs

54 lines
1.3 KiB
Rust
Raw Normal View History

2023-04-16 00:07:08 +00:00
use std::{
marker::PhantomData,
io::Write,
fmt::{Debug, Display, Formatter}
};
use f4jumble;
use borsh::{BorshDeserialize, BorshSerialize};
use haskell_ffi::{
error::Result,
from_haskell::{marshall_from_haskell_var},
to_haskell::{marshall_to_haskell_var, marshall_to_haskell_fixed},
FromHaskell, HaskellSize, ToHaskell
};
use zcash_address::{
Network,
2023-04-18 18:58:21 +00:00
unified::{Address, Encoding},
ZcashAddress
2023-04-16 00:07:08 +00:00
};
pub enum RW {}
pub const RW: PhantomData<RW> = PhantomData;
#[no_mangle]
pub extern "C" fn rust_wrapper_f4jumble(
input: *const u8,
input_len: usize,
out: *mut u8,
out_len: &mut usize) {
let input: Vec<u8> = marshall_from_haskell_var(input, input_len, RW);
let result = f4jumble::f4jumble(&input).unwrap();
marshall_to_haskell_var(&result, out, out_len, RW);
}
#[no_mangle]
pub extern "C" fn rust_wrapper_ua_decode(
input: *const u8,
input_len: usize,) -> bool {
let input: String = marshall_from_haskell_var(input, input_len, RW);
Address::decode(&input).is_ok()
//marshall_to_haskell_var(&result, out, out_len, RW);
}
2023-04-18 18:58:21 +00:00
#[no_mangle]
pub extern "C" fn rust_wrapper_shielded_decode(
input: *const u8,
input_len: usize) -> bool {
let input: String = marshall_from_haskell_var(input, input_len, RW);
ZcashAddress::try_from_encoded(&input).is_ok()
}