@@ -10,7 +10,6 @@ import qualified Bitcoin.Address as Btc
10
10
import qualified Data.Aeson as A
11
11
import qualified Data.ByteString.Base16 as B16
12
12
import qualified Data.ByteString.Lazy as BL
13
- import qualified Data.Text.Lazy as TL
14
13
import qualified Functora.Bolt11 as B11
15
14
import Functora.Miso.Prelude
16
15
import qualified Functora.Miso.Widgets.FieldPairs as FieldPairs
@@ -65,7 +64,7 @@ pairs st header optic =
65
64
FieldPairs. argsAction = PushUpdate . Instant
66
65
}
67
66
68
- pair :: MisoString -> MisoString -> FieldPair DynamicField Identity
67
+ pair :: Unicode -> Unicode -> FieldPair DynamicField Identity
69
68
pair x =
70
69
newFieldPairId x
71
70
. DynamicFieldText
@@ -76,12 +75,12 @@ success = css "app-success"
76
75
failure :: [View Action ] -> [View Action ]
77
76
failure = css " app-failure"
78
77
79
- css :: MisoString -> [View action ] -> [View action ]
78
+ css :: Unicode -> [View action ] -> [View action ]
80
79
css x = fmap $ \ case
81
80
Node x0 x1 x2 x3 x4 -> Node x0 x1 x2 (class_ x : x3) x4
82
81
html -> html
83
82
84
- inspectTimestamp :: Int -> MisoString
83
+ inspectTimestamp :: Int -> Unicode
85
84
inspectTimestamp =
86
85
inspect
87
86
. posixSecondsToUTCTime
@@ -99,7 +98,7 @@ makeBolt11Viewer st =
99
98
then pure mempty
100
99
else bimap plain (preimageFields rawR) r
101
100
verifierFields =
102
- if any @ [MisoString ] (== mempty ) [rawLn, rawR]
101
+ if any @ [Unicode ] (== mempty ) [rawLn, rawR]
103
102
then pure mempty
104
103
else case verifyPreimage <$> rh <*> r of
105
104
Left {} -> pure mempty
@@ -117,18 +116,18 @@ makeBolt11Viewer st =
117
116
& # stDocLnPreimageViewer
118
117
.~ fromRight mempty preFields
119
118
where
120
- rawLn :: MisoString
119
+ rawLn :: Unicode
121
120
rawLn = st ^. # stDocLnInvoice . # fieldOutput
122
- rawR :: MisoString
121
+ rawR :: Unicode
123
122
rawR = st ^. # stDocLnPreimage . # fieldOutput
124
- ln :: Either MisoString B11. Bolt11
123
+ ln :: Either Unicode B11. Bolt11
125
124
ln =
126
- first (mappend " Bad invoice - " . toMisoString @ Prelude. String )
125
+ first (mappend " Bad invoice - " . from @ Prelude. String @ Unicode )
127
126
. B11. decodeBolt11
128
- $ fromMisoString @ Prelude. Text rawLn
129
- rh :: Either MisoString ByteString
127
+ $ from @ Unicode @ Prelude. Text rawLn
128
+ rh :: Either Unicode ByteString
130
129
rh = ln >>= parsePreimageHash
131
- r :: Either MisoString ByteString
130
+ r :: Either Unicode ByteString
132
131
r = parsePreimage rawR
133
132
134
133
mergeBolt11Viewers :: (Foldable1 f ) => StDoc f -> StDoc f -> StDoc f
@@ -143,21 +142,17 @@ mergeBolt11Viewers next prev =
143
142
& # stDocLnPreimageViewer
144
143
%~ mergeFieldPairs (stDocLnPreimageViewer next)
145
144
146
- plain :: MisoString -> [FieldPair DynamicField Identity ]
145
+ plain :: Unicode -> [FieldPair DynamicField Identity ]
147
146
plain =
148
147
(: mempty ) . newFieldPairId mempty . DynamicFieldText
149
148
150
- parsePreimage :: MisoString -> Either MisoString ByteString
149
+ parsePreimage :: Unicode -> Either Unicode ByteString
151
150
parsePreimage rawR =
152
- case B16. decode $ fromMisoString @ ByteString rawR of
151
+ case B16. decode $ encodeUtf8 rawR of
153
152
(r, " " ) -> Right r
154
- (_, e) ->
155
- Left
156
- . toMisoString @ Prelude. String
157
- $ " Bad preimage - non hex leftover "
158
- <> Prelude. show e
153
+ (_, e) -> Left $ " Bad preimage - non hex leftover " <> inspect @ Unicode e
159
154
160
- parsePreimageHash :: B11. Bolt11 -> Either MisoString ByteString
155
+ parsePreimageHash :: B11. Bolt11 -> Either Unicode ByteString
161
156
parsePreimageHash ln =
162
157
case find B11. isPaymentHash $ B11. bolt11Tags ln of
163
158
Just (B11. PaymentHash (B11. Hex rh)) -> Right rh
@@ -166,7 +161,7 @@ parsePreimageHash ln =
166
161
verifyPreimage ::
167
162
ByteString ->
168
163
ByteString ->
169
- Either MisoString MisoString
164
+ Either Unicode Unicode
170
165
verifyPreimage rh r =
171
166
if rh == sha256Hash r
172
167
then Right " The preimage matches the invoice"
@@ -181,11 +176,7 @@ invoiceFields ln =
181
176
B11. BitcoinRegtest -> " Bitcoin Regtest"
182
177
B11. BitcoinSignet -> " Bitcoin Signet" ,
183
178
pair " Amount"
184
- . maybe
185
- " 0"
186
- ( toMisoString @ Prelude. String
187
- . B11. inspectBolt11HrpAmt
188
- )
179
+ . maybe " 0" B11. inspectBolt11HrpAmt
189
180
. B11. bolt11HrpAmt
190
181
$ B11. bolt11Hrp ln,
191
182
pair " Created At"
@@ -196,7 +187,6 @@ invoiceFields ln =
196
187
>>= invoiceFieldsTag ln
197
188
)
198
189
<> [ pair " Signature"
199
- . toMisoString @ TL. Text
200
190
. B11. inspectHex
201
191
$ B11. bolt11SigVal sig,
202
192
pair " Pubkey Recovery Flag"
@@ -221,36 +211,39 @@ invoiceFieldsTag ln = \case
221
211
B11. OnchainFallback x ->
222
212
pure
223
213
. pair " Onchain Fallback"
224
- . toMisoString @ ByteString
214
+ . either impureThrow id
215
+ . decodeUtf8Strict @ Unicode @ ByteString
225
216
$ Btc. renderAddress x
226
217
B11. ExtraRouteInfo x ->
227
218
pure
228
219
. pair " Extra Routing Info"
229
- . toMisoString @ BL. ByteString
220
+ . either impureThrow id
221
+ . decodeUtf8Strict @ Unicode @ BL. ByteString
230
222
$ A. encode x
231
223
B11. Features x ->
232
224
pure
233
225
. pair " Feature Bits"
234
- . toMisoString @ Prelude. Text
235
226
$ B11. inspectFeatures x
236
227
B11. UnknownTag {} -> mempty
237
228
B11. UnparsedTag {} -> mempty
238
229
where
239
- w5s :: MisoString -> [B11. Word5 ] -> [FieldPair DynamicField Identity ]
230
+ w5s :: Unicode -> [B11. Word5 ] -> [FieldPair DynamicField Identity ]
240
231
w5s x =
241
232
pure
242
233
. pair x
243
234
. inspect
244
235
. fmap fromEnum
245
- hex :: MisoString -> B11. Hex -> [FieldPair DynamicField Identity ]
236
+ hex :: Unicode -> B11. Hex -> [FieldPair DynamicField Identity ]
246
237
hex x =
247
238
pure
248
239
. pair x
249
- . toMisoString @ TL. Text
250
240
. B11. inspectHex
251
241
252
- preimageFields :: MisoString -> ByteString -> [FieldPair DynamicField Identity ]
242
+ preimageFields :: Unicode -> ByteString -> [FieldPair DynamicField Identity ]
253
243
preimageFields rawR r =
254
244
[ pair " Preimage" rawR,
255
- pair " Preimage Hash" . inspect @ ByteString $ sha256Hash r
245
+ pair " Preimage Hash"
246
+ . either impureThrow id
247
+ . decodeUtf8Strict @ Unicode @ ByteString
248
+ $ sha256Hash r
256
249
]
0 commit comments