-- | -- Module : ZcashHaskell.Utils -- Copyright : Vergara Technologies (c)2023 -- License : BOSL -- -- Maintainer : rene@vergara.network -- Stability : experimental -- Portability : unknown -- -- A set of functions to assist in the handling of elements of the Zcash protocol, allowing for decoding of memos, addresses and viewing keys. -- {-# LANGUAGE OverloadedStrings #-} module ZcashHaskell.Utils where import C.Zcash ( rustWrapperBech32Decode , rustWrapperF4Jumble , rustWrapperF4UnJumble ) import Control.Monad.IO.Class import Data.Aeson import qualified Data.ByteString as BS import qualified Data.Text as T import Foreign.Rust.Marshall.Variable import Network.HTTP.Simple import ZcashHaskell.Types -- | Decode the given bytestring using Bech32 decodeBech32 :: BS.ByteString -> RawData decodeBech32 = withPureBorshVarBuffer . rustWrapperBech32Decode -- | Apply the F4Jumble transformation to the given bytestring f4Jumble :: BS.ByteString -> BS.ByteString f4Jumble = withPureBorshVarBuffer . rustWrapperF4Jumble -- | Apply the inverse F4Jumble transformation to the given bytestring f4UnJumble :: BS.ByteString -> BS.ByteString f4UnJumble = withPureBorshVarBuffer . rustWrapperF4UnJumble -- | Make a Zcash RPC call makeZcashCall :: (MonadIO m, FromJSON a) => BS.ByteString -> BS.ByteString -> T.Text -> [Data.Aeson.Value] -> m (Response a) makeZcashCall username password m p = do let payload = RpcCall "1.0" "test" m p let myRequest = setRequestBodyJSON payload $ setRequestPort 8232 $ setRequestBasicAuth username password $ setRequestMethod "POST" defaultRequest httpJSON myRequest