diff --git a/app/Main.hs b/app/Main.hs deleted file mode 100644 index 56a7df4..0000000 --- a/app/Main.hs +++ /dev/null @@ -1,6 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} - -module Main where - -main :: IO () -main = putStrLn "Zcash Utilities for Haskell" diff --git a/librustzcash-wrapper/src/lib.rs b/librustzcash-wrapper/src/lib.rs index 696573b..71bac6d 100644 --- a/librustzcash-wrapper/src/lib.rs +++ b/librustzcash-wrapper/src/lib.rs @@ -17,13 +17,13 @@ use haskell_ffi::{ use zcash_address::{ Network, - unified::{Address, Encoding} + unified::{Address, Encoding}, + ZcashAddress }; pub enum RW {} pub const RW: PhantomData = PhantomData; - #[no_mangle] pub extern "C" fn rust_wrapper_f4jumble( input: *const u8, @@ -43,3 +43,11 @@ pub extern "C" fn rust_wrapper_ua_decode( Address::decode(&input).is_ok() //marshall_to_haskell_var(&result, out, out_len, RW); } + +#[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() +} diff --git a/src/C/Zcash.chs b/src/C/Zcash.chs index 17cdeb5..e6e4acd 100644 --- a/src/C/Zcash.chs +++ b/src/C/Zcash.chs @@ -37,3 +37,9 @@ newtype CodedString = CodedString BS.ByteString } -> `Bool' #} + +{# fun pure unsafe rust_wrapper_shielded_decode as rustWrapperIsShielded + { toBorshVar* `BS.ByteString'& + } + -> `Bool' +#} diff --git a/src/Zcash.hs b/src/Zcash.hs index 9b289f3..ede2cd2 100644 --- a/src/Zcash.hs +++ b/src/Zcash.hs @@ -1,9 +1,15 @@ module Zcash ( f4Jumble , isValidUnifiedAddress + , isValidShieldedAddress ) where -import C.Zcash (CodedString, rustWrapperF4Jumble, rustWrapperIsUA) +import C.Zcash + ( CodedString + , rustWrapperF4Jumble + , rustWrapperIsShielded + , rustWrapperIsUA + ) import qualified Data.ByteString as BS import Foreign.Rust.Marshall.Fixed import Foreign.Rust.Marshall.Variable @@ -13,3 +19,6 @@ f4Jumble = withPureBorshVarBuffer . rustWrapperF4Jumble isValidUnifiedAddress :: BS.ByteString -> Bool isValidUnifiedAddress = rustWrapperIsUA + +isValidShieldedAddress :: BS.ByteString -> Bool +isValidShieldedAddress = rustWrapperIsShielded diff --git a/zcash-haskell.cabal b/zcash-haskell.cabal index cda14d2..62b50de 100644 --- a/zcash-haskell.cabal +++ b/zcash-haskell.cabal @@ -36,7 +36,7 @@ library rustzcash_wrapper-uninstalled build-depends: base >=4.7 && <5 - , borsh + , borsh >=0.2 , bytestring , foreign-rust , text