diff --git a/CHANGELOG.md b/CHANGELOG.md index f6da509..0bdf0f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index 0ec0a69..77fec2e 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -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) ] ]) ]