Enhance encoding of hex memos

This commit is contained in:
Rene Vergara 2022-07-07 10:33:53 -05:00
parent dbc7568b55
commit bd60df43d7
Signed by: pitmutt
GPG Key ID: 65122AD495A7F5B2
2 changed files with 12 additions and 9 deletions

View File

@ -6,13 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- Enhance `decodeHexText` to support Unicode
- Enhance `encodeHexText` to support Unicode
## [0.1.0.2] - 2022-05-25
### Added
- Changelog
- `paid` field in ZGoOrder type
- Test for `api/order/:id` endpoint with an invalid ID
## Fixed
### Fixed
- Bug #1: crash when invalid ID was provided to `api/order/:id`

View File

@ -14,6 +14,7 @@ import qualified Data.Bson as B
import qualified Data.ByteString as BS
import Data.Char
import qualified Data.HashMap.Strict as HM
import Data.HexString
import Data.Maybe
import Data.SecureMem
import qualified Data.Text as T
@ -162,13 +163,8 @@ decodeHexText h = E.decodeUtf8With lenientDecode $ BS.pack $ hexRead h
chunk = take 2 hexText
-- | Helper function to turn a string into a hex-encoded string
encodeHexText :: String -> String
encodeHexText t = mconcat (map padHex t)
where
padHex x =
if ord x < 16
then "0" ++ (showHex . ord) x ""
else showHex (ord x) ""
encodeHexText :: T.Text -> String
encodeHexText t = T.unpack . toText . fromBytes $ E.encodeUtf8 t
-- Types for the ZGo database documents
-- | Type to model a country for the database's country list
@ -258,7 +254,7 @@ sendPin nodeUser nodePwd nodeAddress addr pin = do
[ object
[ "address" .= addr
, "amount" .= (0.00000001 :: Double)
, "memo" .= encodeHexText ("ZGo PIN: " ++ T.unpack pin)
, "memo" .= encodeHexText ("ZGo PIN: " <> pin)
]
])
]