Merge branch 'dev'

This commit is contained in:
Rene Vergara 2023-10-09 08:28:32 -05:00
commit 158b059596
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
9 changed files with 153 additions and 77 deletions

3
.gitmodules vendored
View file

@ -1,3 +1,6 @@
[submodule "haskoin-core"]
path = haskoin-core
url = https://github.com/khazaddum/haskoin-core.git
[submodule "zcash-haskell"]
path = zcash-haskell
url = git@git.vergara.tech:Vergara_Tech/zcash-haskell.git

View file

@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.4.0]
### Added
- `zcash-haskell` library
### Changed
- Sending of transactions to support ZIP-317.
- Functions to check if Unified Address is valid.
### Removed
- Dependency on patched `haskoin-core` library
## [0.3.4]
### Added

View file

@ -202,6 +202,6 @@ main = do
"Zenith"
def
{ getBanner =
" ______ _ _ _ \n |___ / (_) | | | \n / / ___ _ __ _| |_| |__ \n / / / _ \\ '_ \\| | __| '_ \\ \n / /_| __/ | | | | |_| | | |\n /_____\\___|_| |_|_|\\__|_| |_|\n Zcash Full Node CLI v0.3.3"
" ______ _ _ _ \n |___ / (_) | | | \n / / ___ _ __ _| |_| |__ \n / / / _ \\ '_ \\| | __| '_ \\ \n / /_| __/ | | | | |_| | | |\n /_____\\___|_| |_|_|\\__|_| |_|\n Zcash Full Node CLI v0.4.0"
}
(root nodeUser nodePwd)

@ -1 +0,0 @@
Subproject commit 23132427a25ebdedbcab4d4a931eaafa13de9011

View file

@ -1,5 +1,5 @@
name: zenith
version: 0.3.4
version: 0.4.0
git: "https://git.vergara.tech/Vergara_Tech/zenith"
license: BOSL
author: "Rene Vergara"
@ -31,7 +31,6 @@ library:
- bytestring
- http-conduit
- scientific
- haskoin-core
- vector
- regex-base
- regex-posix
@ -42,6 +41,8 @@ library:
- array
- base64-bytestring
- hexstring
- blake2
- zcash-haskell
executables:
zenith:

View file

@ -7,9 +7,11 @@ module Zenith where
import Control.Concurrent (threadDelay)
import Control.Monad
import Crypto.Hash.BLAKE2.BLAKE2b
import Data.Aeson
import Data.Aeson.Types
import qualified Data.Array as A
import Data.Bits
import qualified Data.ByteString as B
import qualified Data.ByteString.Base64 as B64
import qualified Data.ByteString.Char8 as C
@ -26,7 +28,10 @@ import qualified Data.Text.IO as TIO
import qualified Data.Vector as V
import Data.Word
import GHC.Generics
import Haskoin.Address.Bech32
import ZcashHaskell.Orchard (isValidUnifiedAddress)
import ZcashHaskell.Sapling (isValidShieldedAddress)
{-import Haskoin.Address.Bech32-}
import Network.HTTP.Simple
import Network.HTTP.Types
import Numeric
@ -40,14 +45,12 @@ import Text.Regex.Base
import Text.Regex.Posix
-- | A type to model Zcash RPC calls
data RpcCall =
RpcCall
data RpcCall = RpcCall
{ jsonrpc :: T.Text
, id :: T.Text
, method :: T.Text
, params :: [Value]
}
deriving (Show, Generic, ToJSON, FromJSON)
} deriving (Show, Generic, ToJSON, FromJSON)
-- | Type for modelling the different address sources for Zcash 5.0.0
data AddressSource
@ -86,14 +89,12 @@ instance FromJSON ZcashPool where
"orchard" -> return Orchard
_ -> fail "Not a known Zcash pool"
data ZcashAddress =
ZcashAddress
data ZcashAddress = ZcashAddress
{ source :: AddressSource
, pool :: [ZcashPool]
, account :: Maybe Integer
, addy :: T.Text
}
deriving (Eq)
} deriving (Eq)
instance Show ZcashAddress where
show (ZcashAddress s p i a) =
@ -101,13 +102,11 @@ instance Show ZcashAddress where
"..." ++ T.unpack (T.takeEnd 8 a) ++ " Pools: " ++ show p
-- | A type to model the response of the Zcash RPC
data RpcResponse r =
RpcResponse
data RpcResponse r = RpcResponse
{ err :: Maybe T.Text
, respId :: T.Text
, result :: r
}
deriving (Show, Generic, ToJSON)
} deriving (Show, Generic, ToJSON)
instance (FromJSON r) => FromJSON (RpcResponse r) where
parseJSON (Object obj) = do
@ -131,14 +130,12 @@ instance FromJSON NodeVersion where
pure $ NodeVersion v
-- | A type to model an address group
data AddressGroup =
AddressGroup
data AddressGroup = AddressGroup
{ agsource :: AddressSource
, agtransparent :: [ZcashAddress]
, agsapling :: [ZcashAddress]
, agunified :: [ZcashAddress]
}
deriving (Show, Generic)
} deriving (Show, Generic)
instance FromJSON AddressGroup where
parseJSON =
@ -190,8 +187,7 @@ displayZec s
| otherwise = show (fromIntegral s / 100000000) ++ " ZEC "
-- | A type to model a Zcash transaction
data ZcashTx =
ZcashTx
data ZcashTx = ZcashTx
{ ztxid :: T.Text
, zamount :: Double
, zamountZat :: Integer
@ -200,8 +196,7 @@ data ZcashTx =
, zchange :: Bool
, zconfirmations :: Integer
, zmemo :: T.Text
}
deriving (Show, Generic)
} deriving (Show, Generic)
instance FromJSON ZcashTx where
parseJSON =
@ -241,13 +236,11 @@ instance ToJSON ZcashTx where
]
-- | Type for the UA balance
data UABalance =
UABalance
data UABalance = UABalance
{ uatransparent :: Integer
, uasapling :: Integer
, uaorchard :: Integer
}
deriving (Eq)
} deriving (Eq)
instance Show UABalance where
show (UABalance t s o) =
@ -275,13 +268,11 @@ instance FromJSON UABalance where
pure $ UABalance vT vS vO
-- | Type for Operation Result
data OpResult =
OpResult
data OpResult = OpResult
{ opsuccess :: T.Text
, opmessage :: Maybe T.Text
, optxid :: Maybe T.Text
}
deriving (Show, Eq)
} deriving (Show, Eq)
instance FromJSON OpResult where
parseJSON =
@ -333,8 +324,8 @@ getAddresses ag = agtransparent ag <> agsapling ag <> agunified ag
validateAddress :: T.Text -> Maybe ZcashPool
validateAddress txt --(tReg || sReg && isJust chk) || (uReg && isJust chk)
| tReg = Just Transparent
| sReg && isJust chk = Just Sapling
| uReg && isJust chk = Just Orchard
| sReg && chkS = Just Sapling
| uReg && chk = Just Orchard
| otherwise = Nothing
where
transparentRegex = "^t1[a-zA-Z0-9]{33}$" :: String
@ -343,7 +334,8 @@ validateAddress txt --(tReg || sReg && isJust chk) || (uReg && isJust chk)
tReg = T.unpack txt =~ transparentRegex :: Bool
sReg = T.unpack txt =~ shieldedRegex :: Bool
uReg = T.unpack txt =~ unifiedRegex :: Bool
chk = bech32mDecode txt
chk = isValidUnifiedAddress $ E.encodeUtf8 txt
chkS = isValidShieldedAddress $ E.encodeUtf8 txt
-- | RPC methods
-- | List addresses
@ -433,7 +425,7 @@ sendTx user pwd fromAddy toAddy amount memo = do
(V.fromList
[object ["address" .= toAddy, "amount" .= amount]])
, Data.Aeson.Number $ Scientific.scientific 1 1
, Data.Aeson.Number $ Scientific.scientific 1 (-5)
, Data.Aeson.Null
, Data.Aeson.String privacyPolicy
]
Just memo' ->
@ -447,7 +439,7 @@ sendTx user pwd fromAddy toAddy amount memo = do
]
])
, Data.Aeson.Number $ Scientific.scientific 1 1
, Data.Aeson.Number $ Scientific.scientific 1 (-5)
, Data.Aeson.Null
, Data.Aeson.String privacyPolicy
]
response <- makeZcashCall user pwd "z_sendmany" pd

View file

@ -17,7 +17,7 @@
#
# resolver: ./custom-snapshot.yaml
# resolver: https://example.com/snapshots/2018-01-01.yaml
resolver: lts-20.16
resolver: lts-21.6
# User packages to be built.
# Various formats can be used as shown in the example below.
@ -30,7 +30,8 @@ resolver: lts-20.16
# - wai
packages:
- .
- haskoin-core
#- haskoin-core
#- zcash-haskell
# Dependency packages to be pulled from upstream that are not in the resolver.
# These entries can reference officially published versions as well as
# forks / in-progress versions pinned to a git hash. For example:
@ -42,8 +43,19 @@ packages:
#
# extra-deps: []
extra-deps:
- git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
commit: fef3d3af35a09db718cddb8fc9166b2d2691a744
- git: https://git.vergara.tech/Vergara_Tech/haskell-foreign-rust.git
commit: 787c2e813eb3a5d16c375d4b37dfefbd2adcdf05
- git: https://github.com/reach-sh/haskell-hexstring.git
commit: 085c16fb21b9f856a435a3faab980e7e0b319341
- git: https://github.com/well-typed/borsh.git
commit: d2fcfa159e0a844b1ec5e8ed3e232d4b380fa831
- vector-0.13.0.0@sha256:fa5cac81a17a5af388716792e8b99c24b3b66770086756d0d8b23f8272a0244c,9112
- generically-0.1.1
- vector-algorithms-0.9.0.1
#- vector-0.12.3.1@sha256:abbfe8830e13549596e1295219d340eb01bd00e1c7124d0dd16586911a291c59,8218
#extra-lib-dirs: [/home/rav/Documents/programs/haskoin]
#
# Override default flag values for local packages and extra-deps
# flags: {}
@ -64,7 +76,6 @@ extra-deps:
#
# Extra directories used by stack for building
# extra-include-dirs: [/path/to/dir]
#extra-lib-dirs: [/home/rav/Documents/programs/haskoin]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor

View file

@ -4,6 +4,28 @@
# https://docs.haskellstack.org/en/stable/lock_files
packages:
- completed:
commit: fef3d3af35a09db718cddb8fc9166b2d2691a744
git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
name: zcash-haskell
pantry-tree:
sha256: ec7782cf2646da17548d59af0ea98dcbaac1b6c2176258c696a7f508db6dbc21
size: 1126
version: 0.1.0
original:
commit: fef3d3af35a09db718cddb8fc9166b2d2691a744
git: https://git.vergara.tech/Vergara_Tech/zcash-haskell.git
- completed:
commit: 787c2e813eb3a5d16c375d4b37dfefbd2adcdf05
git: https://git.vergara.tech/Vergara_Tech/haskell-foreign-rust.git
name: foreign-rust
pantry-tree:
sha256: be2f6fc0fab58a90fec657bdb6bd0ccf0810c7dccfe95c78b85e174fae227e42
size: 2315
version: 0.1.0
original:
commit: 787c2e813eb3a5d16c375d4b37dfefbd2adcdf05
git: https://git.vergara.tech/Vergara_Tech/haskell-foreign-rust.git
- completed:
commit: 085c16fb21b9f856a435a3faab980e7e0b319341
git: https://github.com/reach-sh/haskell-hexstring.git
@ -15,9 +37,41 @@ packages:
original:
commit: 085c16fb21b9f856a435a3faab980e7e0b319341
git: https://github.com/reach-sh/haskell-hexstring.git
- completed:
commit: d2fcfa159e0a844b1ec5e8ed3e232d4b380fa831
git: https://github.com/well-typed/borsh.git
name: borsh
pantry-tree:
sha256: 8335925f495a5a653fcb74b6b8bb18cd0b6b7fe7099a1686108704e6ab82f47b
size: 2268
version: 0.3.0
original:
commit: d2fcfa159e0a844b1ec5e8ed3e232d4b380fa831
git: https://github.com/well-typed/borsh.git
- completed:
hackage: vector-0.13.0.0@sha256:fa5cac81a17a5af388716792e8b99c24b3b66770086756d0d8b23f8272a0244c,9112
pantry-tree:
sha256: d2461d28022c8c0a91da08b579b1bff478f617102d2f5ef596cc5b28d14b8b6a
size: 4092
original:
hackage: vector-0.13.0.0@sha256:fa5cac81a17a5af388716792e8b99c24b3b66770086756d0d8b23f8272a0244c,9112
- completed:
hackage: generically-0.1.1@sha256:aa00d9a77b7fb90c08f935699758ed9de55975021b1e979c6a4a4b5b49a940a9,1133
pantry-tree:
sha256: ec19e6d2aecfbe7a59e789526b9d7ab5c8ba853f017248d0203ee69a9769adb7
size: 233
original:
hackage: generically-0.1.1
- completed:
hackage: vector-algorithms-0.9.0.1@sha256:f3e5c6695529a94edf762117cafd91c989cb642ad3f8ca4014dbb13c8f6c2a20,3826
pantry-tree:
sha256: aef389e57ae6020e5da719bee40aaf6cccf1c4d1e7743a85d30c9d8c25d170a0
size: 1510
original:
hackage: vector-algorithms-0.9.0.1
snapshots:
- completed:
sha256: dad15e2ec0c09280a5c2e07190fb18710fc54472f029f34f861f686540824d81
size: 649592
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/16.yaml
original: lts-20.16
sha256: 2e7d4a730d8eb5373b2d383fac84efcf7c81e3b7a5fce71b4c2e19a1768f25a6
size: 640239
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/6.yaml
original: lts-21.6

View file

@ -1,11 +1,11 @@
cabal-version: 1.12
-- This file has been generated from package.yaml by hpack version 0.35.0.
-- This file has been generated from package.yaml by hpack version 0.35.1.
--
-- see: https://github.com/sol/hpack
name: zenith
version: 0.3.4
version: 0.4.0
synopsis: Haskell CLI for Zcash Full Node
description: Please see the README on repo at <https://git.vergara.tech/Vergara_Tech/zenith#readme>
author: Rene Vergara
@ -36,8 +36,8 @@ library
, array
, base >=4.7 && <5
, base64-bytestring
, blake2
, bytestring
, haskoin-core
, hexstring
, http-conduit
, http-types
@ -48,6 +48,7 @@ library
, scientific
, text
, vector
, zcash-haskell
default-language: Haskell2010
executable zenith