Update sending function for ZIP-317

This commit is contained in:
Rene Vergara 2023-10-06 14:31:22 -05:00
parent 3e4aaf647c
commit 9945dfc8c1
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2

View file

@ -45,14 +45,12 @@ import Text.Regex.Base
import Text.Regex.Posix import Text.Regex.Posix
-- | A type to model Zcash RPC calls -- | A type to model Zcash RPC calls
data RpcCall = data RpcCall = RpcCall
RpcCall
{ jsonrpc :: T.Text { jsonrpc :: T.Text
, id :: T.Text , id :: T.Text
, method :: T.Text , method :: T.Text
, params :: [Value] , params :: [Value]
} } deriving (Show, Generic, ToJSON, FromJSON)
deriving (Show, Generic, ToJSON, FromJSON)
-- | Type for modelling the different address sources for Zcash 5.0.0 -- | Type for modelling the different address sources for Zcash 5.0.0
data AddressSource data AddressSource
@ -91,14 +89,12 @@ instance FromJSON ZcashPool where
"orchard" -> return Orchard "orchard" -> return Orchard
_ -> fail "Not a known Zcash pool" _ -> fail "Not a known Zcash pool"
data ZcashAddress = data ZcashAddress = ZcashAddress
ZcashAddress
{ source :: AddressSource { source :: AddressSource
, pool :: [ZcashPool] , pool :: [ZcashPool]
, account :: Maybe Integer , account :: Maybe Integer
, addy :: T.Text , addy :: T.Text
} } deriving (Eq)
deriving (Eq)
instance Show ZcashAddress where instance Show ZcashAddress where
show (ZcashAddress s p i a) = show (ZcashAddress s p i a) =
@ -106,13 +102,11 @@ instance Show ZcashAddress where
"..." ++ T.unpack (T.takeEnd 8 a) ++ " Pools: " ++ show p "..." ++ T.unpack (T.takeEnd 8 a) ++ " Pools: " ++ show p
-- | A type to model the response of the Zcash RPC -- | A type to model the response of the Zcash RPC
data RpcResponse r = data RpcResponse r = RpcResponse
RpcResponse
{ err :: Maybe T.Text { err :: Maybe T.Text
, respId :: T.Text , respId :: T.Text
, result :: r , result :: r
} } deriving (Show, Generic, ToJSON)
deriving (Show, Generic, ToJSON)
instance (FromJSON r) => FromJSON (RpcResponse r) where instance (FromJSON r) => FromJSON (RpcResponse r) where
parseJSON (Object obj) = do parseJSON (Object obj) = do
@ -136,14 +130,12 @@ instance FromJSON NodeVersion where
pure $ NodeVersion v pure $ NodeVersion v
-- | A type to model an address group -- | A type to model an address group
data AddressGroup = data AddressGroup = AddressGroup
AddressGroup
{ agsource :: AddressSource { agsource :: AddressSource
, agtransparent :: [ZcashAddress] , agtransparent :: [ZcashAddress]
, agsapling :: [ZcashAddress] , agsapling :: [ZcashAddress]
, agunified :: [ZcashAddress] , agunified :: [ZcashAddress]
} } deriving (Show, Generic)
deriving (Show, Generic)
instance FromJSON AddressGroup where instance FromJSON AddressGroup where
parseJSON = parseJSON =
@ -195,8 +187,7 @@ displayZec s
| otherwise = show (fromIntegral s / 100000000) ++ " ZEC " | otherwise = show (fromIntegral s / 100000000) ++ " ZEC "
-- | A type to model a Zcash transaction -- | A type to model a Zcash transaction
data ZcashTx = data ZcashTx = ZcashTx
ZcashTx
{ ztxid :: T.Text { ztxid :: T.Text
, zamount :: Double , zamount :: Double
, zamountZat :: Integer , zamountZat :: Integer
@ -205,8 +196,7 @@ data ZcashTx =
, zchange :: Bool , zchange :: Bool
, zconfirmations :: Integer , zconfirmations :: Integer
, zmemo :: T.Text , zmemo :: T.Text
} } deriving (Show, Generic)
deriving (Show, Generic)
instance FromJSON ZcashTx where instance FromJSON ZcashTx where
parseJSON = parseJSON =
@ -246,13 +236,11 @@ instance ToJSON ZcashTx where
] ]
-- | Type for the UA balance -- | Type for the UA balance
data UABalance = data UABalance = UABalance
UABalance
{ uatransparent :: Integer { uatransparent :: Integer
, uasapling :: Integer , uasapling :: Integer
, uaorchard :: Integer , uaorchard :: Integer
} } deriving (Eq)
deriving (Eq)
instance Show UABalance where instance Show UABalance where
show (UABalance t s o) = show (UABalance t s o) =
@ -280,13 +268,11 @@ instance FromJSON UABalance where
pure $ UABalance vT vS vO pure $ UABalance vT vS vO
-- | Type for Operation Result -- | Type for Operation Result
data OpResult = data OpResult = OpResult
OpResult
{ opsuccess :: T.Text { opsuccess :: T.Text
, opmessage :: Maybe T.Text , opmessage :: Maybe T.Text
, optxid :: Maybe T.Text , optxid :: Maybe T.Text
} } deriving (Show, Eq)
deriving (Show, Eq)
instance FromJSON OpResult where instance FromJSON OpResult where
parseJSON = parseJSON =
@ -439,7 +425,7 @@ sendTx user pwd fromAddy toAddy amount memo = do
(V.fromList (V.fromList
[object ["address" .= toAddy, "amount" .= amount]]) [object ["address" .= toAddy, "amount" .= amount]])
, Data.Aeson.Number $ Scientific.scientific 1 1 , Data.Aeson.Number $ Scientific.scientific 1 1
, Data.Aeson.Number $ Scientific.scientific 1 (-5) , Data.Aeson.Null
, Data.Aeson.String privacyPolicy , Data.Aeson.String privacyPolicy
] ]
Just memo' -> Just memo' ->
@ -453,7 +439,7 @@ sendTx user pwd fromAddy toAddy amount memo = do
] ]
]) ])
, Data.Aeson.Number $ Scientific.scientific 1 1 , Data.Aeson.Number $ Scientific.scientific 1 1
, Data.Aeson.Number $ Scientific.scientific 1 (-5) , Data.Aeson.Null
, Data.Aeson.String privacyPolicy , Data.Aeson.String privacyPolicy
] ]
response <- makeZcashCall user pwd "z_sendmany" pd response <- makeZcashCall user pwd "z_sendmany" pd