Skip to content

Commit 390e775

Browse files
committed
unicode wip
1 parent c2c1f35 commit 390e775

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

pub/functora/src/bolt11/Functora/Bolt11.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,18 @@ data Route = Route
204204
instance A.ToJSON Route where
205205
toJSON x =
206206
A.object
207-
[ "pubkey" A..= inspectHex @String (routePubKey x),
208-
"short_channel_id" A..= inspectHex @String (routeShortChanId x),
207+
[ "pubkey" A..= inspectHex @Unicode (routePubKey x),
208+
"short_channel_id" A..= inspectHex @Unicode (routeShortChanId x),
209209
"fee_base_msat" A..= routeFeeBaseMsat x,
210210
"fee_proportional_millionths" A..= routeFeePropMillionth x,
211211
"cltv_expiry_delta" A..= routeCltvExpiryDelta x
212212
]
213213
toEncoding x =
214214
A.pairs
215215
$ "pubkey"
216-
A..= inspectHex @String (routePubKey x)
216+
A..= inspectHex @Unicode (routePubKey x)
217217
<> "short_channel_id"
218-
A..= inspectHex @String (routeShortChanId x)
218+
A..= inspectHex @Unicode (routeShortChanId x)
219219
<> "fee_base_msat"
220220
A..= routeFeeBaseMsat x
221221
<> "fee_proportional_millionths"

pub/functora/src/prelude/Functora/Prelude.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ display x
529529
#if defined(__GHCJS__) || defined(ghcjs_HOST_OS) || defined(wasi_HOST_OS)
530530
defDisplay
531531
| Just HRefl <- typeOf x `eqTypeRep` typeRep @JS.JSString =
532-
from @String @dst $ from @JS.JSString @String x
532+
from @JS.JSString @dst x
533533
| otherwise =
534534
Universum.show x
535535
#else
@@ -664,10 +664,10 @@ getCurrentPicos = do
664664
-- Exceptions
665665

666666
data ParseException = ParseException
667-
{ parseExceptionSource :: String,
667+
{ parseExceptionSource :: Unicode,
668668
parseExceptionSourceType :: SomeTypeRep,
669669
parseExceptionTargetType :: SomeTypeRep,
670-
parseExceptionFailure :: String
670+
parseExceptionFailure :: Unicode
671671
}
672672
deriving stock (Eq, Ord, Show, Data, Generic)
673673

@@ -736,7 +736,7 @@ parseRatio str =
736736
then pure rat
737737
else
738738
throwParseException str
739-
$ inspectType @int @String
739+
$ inspectType @int @Unicode
740740
<> " numerator or denominator seems to be out of bounds, expected "
741741
<> inspect rhsRat
742742
<> " but got "
@@ -1056,6 +1056,7 @@ type Textual mono =
10561056
From String mono,
10571057
From Text mono,
10581058
From TL.Text mono,
1059+
From Unicode mono,
10591060
ConvertUtf8 mono ByteString,
10601061
ConvertUtf8 mono BL.ByteString
10611062
)

pub/functora/src/prelude/Functora/PreludeOrphan.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,15 @@ instance ConvertUtf8 JSString BL.ByteString where
154154
decodeUtf8Strict = fmap JS.pack . decodeUtf8Strict
155155

156156
instance Binary JSString where
157-
put = Binary.put . from @JSString @Text
158-
get = fmap (from @Text @JSString) Binary.get
157+
put = Binary.put . encodeUtf8 @JSString @ByteString
158+
get = do
159+
bs <- Binary.get
160+
case decodeUtf8Strict @JSString @ByteString bs of
161+
Right x -> pure x
162+
Left e -> fail $ displayException e
159163

160164
instance A.ToJSONKey JSString where
161-
toJSONKey = contramap (from @JSString @Text) $ A.toJSONKey
165+
toJSONKey = contramap (from @JSString @Text) $ A.toJSONKey @Text
162166

163167
instance A.FromJSONKey JSString where
164168
fromJSONKey = fmap (from @Text @JSString) $ A.fromJSONKey @Text

pub/functora/src/web/Functora/Web.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ webFetch prevUri opts = do
9999
else
100100
throwString $
101101
"Bad HTTP status="
102-
<> inspect @Text webResCode
102+
<> inspect @Unicode webResCode
103103
<> " of req="
104104
<> inspect webReq
105105
<> " with res="
@@ -126,7 +126,7 @@ webFetch prevUri opts = do
126126
else
127127
throwString $
128128
"Bad HTTP status="
129-
<> inspect @Text webResCode
129+
<> inspect @Unicode webResCode
130130
<> " of req="
131131
<> inspect nextUri
132132
<> " with res="

0 commit comments

Comments
 (0)