Enhance hex memo decoding
This commit is contained in:
parent
1bf99023b1
commit
dbc7568b55
5 changed files with 30 additions and 19 deletions
|
@ -48,6 +48,7 @@ library:
|
||||||
- vector
|
- vector
|
||||||
- wai-cors
|
- wai-cors
|
||||||
- warp-tls
|
- warp-tls
|
||||||
|
- hexstring
|
||||||
|
|
||||||
executables:
|
executables:
|
||||||
zgo-backend-exe:
|
zgo-backend-exe:
|
||||||
|
|
|
@ -17,6 +17,8 @@ import qualified Data.HashMap.Strict as HM
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.SecureMem
|
import Data.SecureMem
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Text.Encoding as E
|
||||||
|
import Data.Text.Encoding.Error (lenientDecode)
|
||||||
import qualified Data.Text.Lazy as L
|
import qualified Data.Text.Lazy as L
|
||||||
import Data.Time.Clock
|
import Data.Time.Clock
|
||||||
import Data.Time.Clock.POSIX
|
import Data.Time.Clock.POSIX
|
||||||
|
@ -122,15 +124,7 @@ instance FromJSON ZcashTx where
|
||||||
conf <- obj .: "confirmations"
|
conf <- obj .: "confirmations"
|
||||||
m <- obj .: "memo"
|
m <- obj .: "memo"
|
||||||
pure $
|
pure $
|
||||||
ZcashTx
|
ZcashTx t a aZ bh bt c conf (T.filter (/= '\NUL') $ decodeHexText m)
|
||||||
t
|
|
||||||
a
|
|
||||||
aZ
|
|
||||||
bh
|
|
||||||
bt
|
|
||||||
c
|
|
||||||
conf
|
|
||||||
(T.pack (filter (/= '\NUL') $ decodeHexText m))
|
|
||||||
|
|
||||||
instance ToJSON ZcashTx where
|
instance ToJSON ZcashTx where
|
||||||
toJSON (ZcashTx t a aZ bh bt c conf m) =
|
toJSON (ZcashTx t a aZ bh bt c conf m) =
|
||||||
|
@ -157,11 +151,13 @@ instance Arbitrary ZcashTx where
|
||||||
ZcashTx a aZ t bh bt c cm <$> arbitrary
|
ZcashTx a aZ t bh bt c cm <$> arbitrary
|
||||||
|
|
||||||
-- | Helper function to turn a hex-encoded memo strings to readable text
|
-- | Helper function to turn a hex-encoded memo strings to readable text
|
||||||
decodeHexText :: String -> String
|
decodeHexText :: String -> T.Text
|
||||||
decodeHexText hexText
|
decodeHexText h = E.decodeUtf8With lenientDecode $ BS.pack $ hexRead h
|
||||||
-- | chunk == "00" = decodeHexText (drop 2 hexText)
|
where
|
||||||
| null chunk = ""
|
hexRead hexText
|
||||||
| otherwise = chr (read ("0x" <> chunk)) : decodeHexText (drop 2 hexText)
|
| null chunk = []
|
||||||
|
| otherwise =
|
||||||
|
fromIntegral (read ("0x" <> chunk)) : hexRead (drop 2 hexText)
|
||||||
where
|
where
|
||||||
chunk = take 2 hexText
|
chunk = take 2 hexText
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,9 @@ packages:
|
||||||
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||||
#
|
#
|
||||||
# extra-deps: []
|
# extra-deps: []
|
||||||
|
extra-deps:
|
||||||
|
- git: https://github.com/reach-sh/haskell-hexstring.git
|
||||||
|
commit: 085c16fb21b9f856a435a3faab980e7e0b319341
|
||||||
# Override default flag values for local packages and extra-deps
|
# Override default flag values for local packages and extra-deps
|
||||||
# flags: {}
|
# flags: {}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,18 @@
|
||||||
# For more information, please see the documentation at:
|
# For more information, please see the documentation at:
|
||||||
# https://docs.haskellstack.org/en/stable/lock_files
|
# https://docs.haskellstack.org/en/stable/lock_files
|
||||||
|
|
||||||
packages: []
|
packages:
|
||||||
|
- completed:
|
||||||
|
name: hexstring
|
||||||
|
version: 0.11.1
|
||||||
|
git: https://github.com/reach-sh/haskell-hexstring.git
|
||||||
|
pantry-tree:
|
||||||
|
size: 687
|
||||||
|
sha256: 9ecf67856f59dfb382b283eceb42e4fc1865935d1a7e59111556ed381c6a2ffd
|
||||||
|
commit: 085c16fb21b9f856a435a3faab980e7e0b319341
|
||||||
|
original:
|
||||||
|
git: https://github.com/reach-sh/haskell-hexstring.git
|
||||||
|
commit: 085c16fb21b9f856a435a3faab980e7e0b319341
|
||||||
snapshots:
|
snapshots:
|
||||||
- completed:
|
- completed:
|
||||||
size: 618683
|
size: 618683
|
||||||
|
|
|
@ -5,7 +5,7 @@ cabal-version: 1.12
|
||||||
-- see: https://github.com/sol/hpack
|
-- see: https://github.com/sol/hpack
|
||||||
|
|
||||||
name: zgo-backend
|
name: zgo-backend
|
||||||
version: 0.1.0.1
|
version: 0.1.0.2
|
||||||
synopsis: Haskell Back-end for the ZGo point-of-sale application
|
synopsis: Haskell Back-end for the ZGo point-of-sale application
|
||||||
description: Please see the README on GitLab at <https://gitlab.com/pitmutt/zgo-backend#readme>
|
description: Please see the README on GitLab at <https://gitlab.com/pitmutt/zgo-backend#readme>
|
||||||
category: Web
|
category: Web
|
||||||
|
@ -17,7 +17,7 @@ license-file: LICENSE
|
||||||
build-type: Simple
|
build-type: Simple
|
||||||
extra-source-files:
|
extra-source-files:
|
||||||
README.md
|
README.md
|
||||||
ChangeLog.md
|
CHANGELOG.md
|
||||||
zgo.cfg
|
zgo.cfg
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
|
@ -44,6 +44,7 @@ library
|
||||||
, base >=4.7 && <5
|
, base >=4.7 && <5
|
||||||
, bson
|
, bson
|
||||||
, bytestring
|
, bytestring
|
||||||
|
, hexstring
|
||||||
, http-conduit
|
, http-conduit
|
||||||
, http-types
|
, http-types
|
||||||
, mongoDB
|
, mongoDB
|
||||||
|
|
Loading…
Reference in a new issue