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
|
||||
- wai-cors
|
||||
- warp-tls
|
||||
- hexstring
|
||||
|
||||
executables:
|
||||
zgo-backend-exe:
|
||||
|
|
|
@ -17,6 +17,8 @@ import qualified Data.HashMap.Strict as HM
|
|||
import Data.Maybe
|
||||
import Data.SecureMem
|
||||
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 Data.Time.Clock
|
||||
import Data.Time.Clock.POSIX
|
||||
|
@ -122,15 +124,7 @@ instance FromJSON ZcashTx where
|
|||
conf <- obj .: "confirmations"
|
||||
m <- obj .: "memo"
|
||||
pure $
|
||||
ZcashTx
|
||||
t
|
||||
a
|
||||
aZ
|
||||
bh
|
||||
bt
|
||||
c
|
||||
conf
|
||||
(T.pack (filter (/= '\NUL') $ decodeHexText m))
|
||||
ZcashTx t a aZ bh bt c conf (T.filter (/= '\NUL') $ decodeHexText m)
|
||||
|
||||
instance ToJSON ZcashTx where
|
||||
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
|
||||
|
||||
-- | Helper function to turn a hex-encoded memo strings to readable text
|
||||
decodeHexText :: String -> String
|
||||
decodeHexText hexText
|
||||
-- | chunk == "00" = decodeHexText (drop 2 hexText)
|
||||
| null chunk = ""
|
||||
| otherwise = chr (read ("0x" <> chunk)) : decodeHexText (drop 2 hexText)
|
||||
decodeHexText :: String -> T.Text
|
||||
decodeHexText h = E.decodeUtf8With lenientDecode $ BS.pack $ hexRead h
|
||||
where
|
||||
hexRead hexText
|
||||
| null chunk = []
|
||||
| otherwise =
|
||||
fromIntegral (read ("0x" <> chunk)) : hexRead (drop 2 hexText)
|
||||
where
|
||||
chunk = take 2 hexText
|
||||
|
||||
|
|
|
@ -41,7 +41,9 @@ packages:
|
|||
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
|
||||
#
|
||||
# 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
|
||||
# flags: {}
|
||||
|
||||
|
|
|
@ -3,7 +3,18 @@
|
|||
# For more information, please see the documentation at:
|
||||
# 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:
|
||||
- completed:
|
||||
size: 618683
|
||||
|
|
|
@ -5,7 +5,7 @@ cabal-version: 1.12
|
|||
-- see: https://github.com/sol/hpack
|
||||
|
||||
name: zgo-backend
|
||||
version: 0.1.0.1
|
||||
version: 0.1.0.2
|
||||
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>
|
||||
category: Web
|
||||
|
@ -17,7 +17,7 @@ license-file: LICENSE
|
|||
build-type: Simple
|
||||
extra-source-files:
|
||||
README.md
|
||||
ChangeLog.md
|
||||
CHANGELOG.md
|
||||
zgo.cfg
|
||||
|
||||
source-repository head
|
||||
|
@ -44,6 +44,7 @@ library
|
|||
, base >=4.7 && <5
|
||||
, bson
|
||||
, bytestring
|
||||
, hexstring
|
||||
, http-conduit
|
||||
, http-types
|
||||
, mongoDB
|
||||
|
|
Loading…
Reference in a new issue