@@ -22,12 +22,12 @@ bolt11 st =
22
22
<> either (const mempty ) invoiceWidget ln
23
23
<> either
24
24
(const mempty )
25
- (\ x -> if x == mempty then mempty else preimageWidget x )
25
+ (\ bsR -> if bsR == mempty then mempty else preimageWidget rawR bsR )
26
26
r
27
27
where
28
28
rawLn = st ^. # modelState . # stDoc . # stDocLnInvoice . # fieldOutput
29
29
rawR = st ^. # modelState . # stDoc . # stDocLnPreimage . # fieldOutput
30
- ln = first inspect $ B11. decodeBolt11 rawLn
30
+ ln = first ( mappend " Bad invoice - " . inspect) $ B11. decodeBolt11 rawLn
31
31
rh = ln >>= parsePreimageHash
32
32
r = parsePreimage rawR
33
33
@@ -42,8 +42,8 @@ verifierWidget src rh r =
42
42
then mempty
43
43
else
44
44
if rh == sha256Hash r
45
- then success " Invoice and preimage match! "
46
- else failure " Invoice and preimage mismatch! "
45
+ then success " The preimage matches the invoice "
46
+ else failure " The preimage does not match the invoice "
47
47
48
48
invoiceWidget :: B11. Bolt11 -> [View Action ]
49
49
invoiceWidget ln =
@@ -65,31 +65,33 @@ invoiceWidget ln =
65
65
. from @ Prelude. String @ MisoString
66
66
. Prelude. show
67
67
68
- preimageWidget :: ByteString -> [View Action ]
69
- preimageWidget r =
68
+ preimageWidget :: MisoString -> ByteString -> [View Action ]
69
+ preimageWidget rawR r =
70
70
Header. headerViewer " Preimage Details"
71
71
<> pairs
72
- [ simple " Preimage" r ,
73
- simple " Preimage Hash" $ sha256Hash r
72
+ [ simple " Preimage" rawR ,
73
+ simple " Preimage Hash" . inspect @ ByteString $ sha256Hash r
74
74
]
75
75
where
76
- simple :: MisoString -> ByteString -> FieldPair DynamicField Identity
76
+ simple :: MisoString -> MisoString -> FieldPair DynamicField Identity
77
77
simple x =
78
78
newFieldPairId x
79
79
. DynamicFieldText
80
- . inspect
81
80
82
81
parsePreimage :: MisoString -> Either MisoString ByteString
83
82
parsePreimage rawR =
84
83
case B16. decode . T. encodeUtf8 $ from @ MisoString @ Prelude. Text rawR of
85
84
(r, " " ) -> Right r
86
- res -> Left $ " Bad preimage " <> inspect res
85
+ (_, e) ->
86
+ Left
87
+ $ " Bad preimage - non hex leftover "
88
+ <> from @ Prelude. String @ MisoString (Prelude. show e)
87
89
88
90
parsePreimageHash :: B11. Bolt11 -> Either MisoString ByteString
89
91
parsePreimageHash ln =
90
92
case find B11. isPaymentHash $ B11. bolt11Tags ln of
91
93
Just (B11. PaymentHash (B11. Hex rh)) -> Right rh
92
- _ -> Left " Bad invoice without preimage hash! "
94
+ _ -> Left " Bad invoice - no preimage hash"
93
95
94
96
pairs :: [FieldPair DynamicField f ] -> [View Action ]
95
97
pairs xs =
0 commit comments