Skip to content

Commit 4d1145f

Browse files
committed
wip
1 parent a4dc2f2 commit 4d1145f

File tree

2 files changed

+35
-8
lines changed
  • ghcjs/lightning-verifier/src/App/Widgets
  • pub/functora/src/bolt11/Functora

2 files changed

+35
-8
lines changed

ghcjs/lightning-verifier/src/App/Widgets/Bolt11.hs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ invoiceWidget ln =
6868
. maybe "0" B11.inspectBolt11HrpAmt
6969
. B11.bolt11HrpAmt
7070
$ B11.bolt11Hrp ln,
71-
pair "Timestamp"
72-
. inspect
71+
pair "Created At"
72+
. inspectTimestamp
7373
$ B11.bolt11Timestamp ln
7474
]
7575
<> ( B11.bolt11Tags ln
76-
>>= invoiceTagWidget
76+
>>= invoiceTagWidget ln
7777
)
7878
<> [ pair "Signature"
7979
. B11.inspectHex
@@ -86,24 +86,26 @@ invoiceWidget ln =
8686
where
8787
sig = B11.bolt11Signature ln
8888

89-
invoiceTagWidget :: B11.Tag -> [FieldPair DynamicField Identity]
90-
invoiceTagWidget = \case
89+
invoiceTagWidget :: B11.Bolt11 -> B11.Tag -> [FieldPair DynamicField Identity]
90+
invoiceTagWidget ln = \case
9191
B11.PaymentHash x -> hex "Preimage Hash" x
9292
B11.PaymentSecret x -> hex "Payment Secret" x
9393
B11.Description x -> pure . pair "Description" $ inspect x
9494
B11.AdditionalMetadata x -> w5s "Additional Metadata" x
9595
B11.PayeePubkey x -> hex "Payee Pubkey" x
9696
B11.DescriptionHash x -> hex "Description Hash" x
97-
B11.Expiry x -> pure . pair "Expiry" $ inspect x
98-
B11.MinFinalCltvExpiry x -> pure . pair "Min Final CLTV Expiry" $ inspect x
97+
B11.Expiry x ->
98+
pure . pair "Expires At" . inspectTimestamp $ x + B11.bolt11Timestamp ln
99+
B11.MinFinalCltvExpiry x ->
100+
pure . pair "Min Final CLTV Expiry" $ inspect x <> " Blocks"
99101
B11.OnchainFallback x -> do
100102
--
101103
-- TODO : do not ignore failure?
102104
--
103105
txt <- either (const mempty) pure . decodeUtf8' $ Btc.renderAddress x
104106
pure $ pair "Onchain Fallback" $ from @Prelude.Text @MisoString txt
105107
B11.ExtraRouteInfo -> mempty
106-
B11.Features x -> pure . pair "Feature Bits" $ inspect x
108+
B11.Features x -> pure . pair "Feature Bits" $ B11.inspectFeatures x
107109
B11.UnknownTag {} -> mempty
108110
B11.UnparsedTag {} -> mempty
109111
where
@@ -181,3 +183,10 @@ css :: MisoString -> [View action] -> [View action]
181183
css x = fmap $ \case
182184
Node x0 x1 x2 x3 x4 -> Node x0 x1 x2 (class_ x : x3) x4
183185
html -> html
186+
187+
inspectTimestamp :: Int -> MisoString
188+
inspectTimestamp =
189+
inspect
190+
. posixSecondsToUTCTime
191+
. Prelude.fromInteger
192+
. from @Int @Integer

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ module Functora.Bolt11
88
Tag (..),
99
Feature (..),
1010
FeatureName (..),
11+
inspectFeature,
12+
inspectFeatures,
1113
RequiredOrSupported (..),
1214
isPaymentHash,
1315
Network (..),
@@ -120,6 +122,22 @@ data FeatureName
120122
| Unknown_feature
121123
deriving stock (Eq, Ord, Show, Data, Generic)
122124

125+
inspectFeature :: forall a. (From Text a) => Feature -> a
126+
inspectFeature x =
127+
from @Text @a
128+
$ "("
129+
<> inspect (featureBits x)
130+
<> ") "
131+
<> T.toLower (inspect $ featureName x)
132+
<> " "
133+
<> T.toLower (inspect $ featureRequiredOrSuported x)
134+
135+
inspectFeatures :: forall a. (From Text a) => [Feature] -> a
136+
inspectFeatures =
137+
from @Text @a
138+
. T.intercalate ", "
139+
. fmap inspectFeature
140+
123141
parseFeatures :: [Word5] -> [Feature]
124142
parseFeatures [] = mempty
125143
parseFeatures ws = sort . nubOrd $ do

0 commit comments

Comments
 (0)