zcash-haskell/src/ZcashHaskell/Utils.hs

75 lines
2.4 KiB
Haskell
Raw Normal View History

2023-12-20 20:03:42 +00:00
{- Copyright 2022-2024 Vergara Technologies LLC
This file is part of Zcash-Haskell.
Zcash-Haskell is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version.
Zcash-Haskell is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along with
Zcash-Haskell. If not, see <https://www.gnu.org/licenses/>.
-}
2023-08-17 15:02:32 +00:00
-- |
-- 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.
--
2023-09-26 20:24:18 +00:00
{-# LANGUAGE OverloadedStrings #-}
2023-06-14 15:53:29 +00:00
module ZcashHaskell.Utils where
import C.Zcash
( rustWrapperBech32Decode
, rustWrapperF4Jumble
, rustWrapperF4UnJumble
)
2023-09-26 20:24:18 +00:00
import Control.Monad.IO.Class
import Data.Aeson
import qualified Data.ByteString as BS
2023-09-26 20:24:18 +00:00
import qualified Data.Text as T
import Foreign.Rust.Marshall.Variable
2023-09-26 20:24:18 +00:00
import Network.HTTP.Simple
2023-06-14 15:53:29 +00:00
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
2023-09-26 20:24:18 +00:00
-- | 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