Enhance encoding of hex memos
This commit is contained in:
parent
dbc7568b55
commit
bd60df43d7
2 changed files with 12 additions and 9 deletions
|
@ -6,13 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Enhance `decodeHexText` to support Unicode
|
||||||
|
- Enhance `encodeHexText` to support Unicode
|
||||||
|
|
||||||
|
## [0.1.0.2] - 2022-05-25
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- Changelog
|
- Changelog
|
||||||
- `paid` field in ZGoOrder type
|
- `paid` field in ZGoOrder type
|
||||||
- Test for `api/order/:id` endpoint with an invalid ID
|
- Test for `api/order/:id` endpoint with an invalid ID
|
||||||
|
|
||||||
## Fixed
|
### Fixed
|
||||||
|
|
||||||
- Bug #1: crash when invalid ID was provided to `api/order/:id`
|
- Bug #1: crash when invalid ID was provided to `api/order/:id`
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import qualified Data.Bson as B
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
import Data.Char
|
import Data.Char
|
||||||
import qualified Data.HashMap.Strict as HM
|
import qualified Data.HashMap.Strict as HM
|
||||||
|
import Data.HexString
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.SecureMem
|
import Data.SecureMem
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
@ -162,13 +163,8 @@ decodeHexText h = E.decodeUtf8With lenientDecode $ BS.pack $ hexRead h
|
||||||
chunk = take 2 hexText
|
chunk = take 2 hexText
|
||||||
|
|
||||||
-- | Helper function to turn a string into a hex-encoded string
|
-- | Helper function to turn a string into a hex-encoded string
|
||||||
encodeHexText :: String -> String
|
encodeHexText :: T.Text -> String
|
||||||
encodeHexText t = mconcat (map padHex t)
|
encodeHexText t = T.unpack . toText . fromBytes $ E.encodeUtf8 t
|
||||||
where
|
|
||||||
padHex x =
|
|
||||||
if ord x < 16
|
|
||||||
then "0" ++ (showHex . ord) x ""
|
|
||||||
else showHex (ord x) ""
|
|
||||||
|
|
||||||
-- Types for the ZGo database documents
|
-- Types for the ZGo database documents
|
||||||
-- | Type to model a country for the database's country list
|
-- | Type to model a country for the database's country list
|
||||||
|
@ -258,7 +254,7 @@ sendPin nodeUser nodePwd nodeAddress addr pin = do
|
||||||
[ object
|
[ object
|
||||||
[ "address" .= addr
|
[ "address" .= addr
|
||||||
, "amount" .= (0.00000001 :: Double)
|
, "amount" .= (0.00000001 :: Double)
|
||||||
, "memo" .= encodeHexText ("ZGo PIN: " ++ T.unpack pin)
|
, "memo" .= encodeHexText ("ZGo PIN: " <> pin)
|
||||||
]
|
]
|
||||||
])
|
])
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue