@@ -20,7 +20,6 @@ module Functora.Bolt11
20
20
Bolt11Hrp (.. ),
21
21
Bolt11Sig (.. ),
22
22
Bolt11 (.. ),
23
- inspectW5 ,
24
23
decodeBolt11 ,
25
24
)
26
25
where
@@ -40,7 +39,6 @@ import qualified Data.ByteString as BS
40
39
import qualified Data.ByteString.Base16 as B16
41
40
import qualified Data.ByteString.Builder as BS
42
41
import qualified Data.ByteString.Lazy.Char8 as BL
43
- import qualified Data.Text.Lazy as TL
44
42
import Functora.Prelude hiding (error )
45
43
import Prelude (Show (.. ), error )
46
44
@@ -50,11 +48,9 @@ newtype Hex = Hex
50
48
deriving stock (Eq , Ord , Data , Generic )
51
49
52
50
instance Show Hex where
53
- show =
54
- from @ TL. Text @ String
55
- . inspectHex
51
+ show = inspectHex @ String
56
52
57
- inspectHex :: Hex -> TL. Text
53
+ inspectHex :: ( Textual a ) => Hex -> a
58
54
inspectHex =
59
55
decodeUtf8
60
56
. BS. toLazyByteString
@@ -82,7 +78,7 @@ instance IsString Hex where
82
78
data Tag
83
79
= PaymentHash Hex
84
80
| PaymentSecret Hex
85
- | Description Text
81
+ | Description Unicode
86
82
| AdditionalMetadata [Word5 ]
87
83
| PayeePubkey Hex
88
84
| DescriptionHash Hex
@@ -208,18 +204,18 @@ data Route = Route
208
204
instance A. ToJSON Route where
209
205
toJSON x =
210
206
A. object
211
- [ " pubkey" A. .= inspectHex (routePubKey x),
212
- " short_channel_id" A. .= inspectHex (routeShortChanId x),
207
+ [ " pubkey" A. .= inspectHex @ String (routePubKey x),
208
+ " short_channel_id" A. .= inspectHex @ String (routeShortChanId x),
213
209
" fee_base_msat" A. .= routeFeeBaseMsat x,
214
210
" fee_proportional_millionths" A. .= routeFeePropMillionth x,
215
211
" cltv_expiry_delta" A. .= routeCltvExpiryDelta x
216
212
]
217
213
toEncoding x =
218
214
A. pairs
219
215
$ " pubkey"
220
- A. .= inspectHex (routePubKey x)
216
+ A. .= inspectHex @ String (routePubKey x)
221
217
<> " short_channel_id"
222
- A. .= inspectHex (routeShortChanId x)
218
+ A. .= inspectHex @ String (routeShortChanId x)
223
219
<> " fee_base_msat"
224
220
A. .= routeFeeBaseMsat x
225
221
<> " fee_proportional_millionths"
@@ -284,7 +280,7 @@ data Bolt11HrpAmt = Bolt11HrpAmt
284
280
}
285
281
deriving stock (Eq , Ord , Show , Data , Generic )
286
282
287
- inspectBolt11HrpAmt :: ( IsString a , Semigroup a ) => Bolt11HrpAmt -> a
283
+ inspectBolt11HrpAmt :: forall a . ( Textual a ) => Bolt11HrpAmt -> a
288
284
inspectBolt11HrpAmt (Bolt11HrpAmt amt mul) =
289
285
if sat > 1_000_000
290
286
then inspectBolt11HrpAmt' btc <> " BTC"
@@ -302,9 +298,9 @@ inspectBolt11HrpAmt (Bolt11HrpAmt amt mul) =
302
298
303
299
inspectBolt11HrpAmt' ::
304
300
forall a b .
305
- ( IsString a ,
306
- From b Integer ,
307
- Integral b
301
+ ( Textual a ,
302
+ Integral b ,
303
+ From b Integer
308
304
) =>
309
305
Ratio b ->
310
306
a
@@ -390,9 +386,9 @@ w5hex :: [Word5] -> Either String Hex
390
386
w5hex =
391
387
second Hex . w5bs
392
388
393
- w5txt :: [Word5 ] -> Either String Text
389
+ w5txt :: [Word5 ] -> Either String Unicode
394
390
w5txt =
395
- first displayException . decodeUtf8' <=< w5bs
391
+ first displayException . decodeUtf8Strict <=< w5bs
396
392
397
393
w5int :: [Word5 ] -> Int
398
394
w5int bytes = foldl' decodeInt 0 (zip [0 .. ] (take 7 (reverse bytes)))
@@ -430,13 +426,6 @@ w5addr net (v0 : rest) =
430
426
where
431
427
cfg = networkSettings net
432
428
433
- inspectW5 :: forall a . (From Text a ) => [Word5 ] -> a
434
- inspectW5 ws =
435
- from @ Text @ a
436
- . either (const . inspect $ fmap fromEnum ws) id
437
- $ w5txt ws
438
- <|> fmap inspect (w5bs ws)
439
-
440
429
parseTag :: Network -> [Word5 ] -> (Maybe Tag , [Word5 ])
441
430
parseTag _ [] = (Nothing , [] )
442
431
parseTag _ ws@ [_] = (Nothing , ws)
0 commit comments