@@ -23,6 +23,7 @@ import qualified Data.ByteString as BS
23
23
import qualified Data.ByteString.Base16 as B16
24
24
import qualified Data.ByteString.Builder as BS
25
25
import qualified Data.ByteString.Lazy.Char8 as BL
26
+ import Data.Data (Data )
26
27
import Data.Foldable (foldl' )
27
28
import Data.Maybe (fromMaybe )
28
29
import Data.String (IsString (.. ))
@@ -32,10 +33,12 @@ import Data.Text.Encoding (decodeUtf8)
32
33
import qualified Data.Text.Encoding as T
33
34
import Functora.Bech32 (Word5 (.. ), bech32Decode , toBase256 )
34
35
import Functora.Denomination (Denomination (toMsats ), MSats , btc )
36
+ import GHC.Generics (Generic )
35
37
import Prelude
36
38
37
39
newtype Hex = Hex { getHex :: ByteString }
38
40
deriving newtype (Eq , Ord )
41
+ deriving stock (Data , Generic )
39
42
40
43
instance Show Hex where
41
44
show (Hex bs) = BL. unpack (BS. toLazyByteString (BS. byteStringHex bs))
@@ -70,7 +73,7 @@ data Tag
70
73
| OnchainFallback Hex -- TODO: address type
71
74
| ExtraRouteInfo
72
75
| FeatureBits [Word5 ]
73
- deriving stock (Eq , Ord , Show )
76
+ deriving stock (Eq , Ord , Show , Data , Generic )
74
77
75
78
isPaymentHash :: Tag -> Bool
76
79
isPaymentHash PaymentHash {} = True
@@ -81,16 +84,17 @@ isDescription Description {} = True
81
84
isDescription _ = False
82
85
83
86
data Multiplier = Milli | Micro | Nano | Pico
84
- deriving stock (Eq , Ord , Show )
87
+ deriving stock (Eq , Ord , Show , Data , Generic )
85
88
86
89
data Currency
87
90
= Bitcoin
88
91
| BitcoinTestnet
89
92
| BitcoinRegtest
90
- deriving stock (Eq , Ord , Show )
93
+ deriving stock (Eq , Ord , Show , Data , Generic )
91
94
92
95
newtype Bolt11Amount = Bolt11Amount { _getBolt11Amount :: (Int , Multiplier )}
93
96
deriving newtype (Eq , Ord )
97
+ deriving stock (Data , Generic )
94
98
95
99
instance Show Bolt11Amount where
96
100
show amt = show (bolt11Msats amt)
@@ -99,15 +103,15 @@ data Bolt11HRP = Bolt11HRP
99
103
{ bolt11Currency :: Currency ,
100
104
bolt11Amount :: Maybe Bolt11Amount
101
105
}
102
- deriving stock (Eq , Ord , Show )
106
+ deriving stock (Eq , Ord , Show , Data , Generic )
103
107
104
108
data Bolt11 = Bolt11
105
109
{ bolt11HRP :: Bolt11HRP ,
106
110
bolt11Timestamp :: Int , -- posix
107
111
bolt11Tags :: [Tag ], -- posix
108
112
bolt11Signature :: Hex
109
113
}
110
- deriving stock (Eq , Ord , Show )
114
+ deriving stock (Eq , Ord , Show , Data , Generic )
111
115
112
116
parseCurrency :: Parser Currency
113
117
parseCurrency =
@@ -185,7 +189,7 @@ tagParser ws@(UnsafeWord5 typ : d1 : d2 : rest)
185
189
data MSig
186
190
= Sig [Word5 ]
187
191
| Unk [Word5 ]
188
- deriving stock (Eq , Ord , Show )
192
+ deriving stock (Eq , Ord , Show , Data , Generic )
189
193
190
194
tagsParser :: [Word5 ] -> ([Tag ], MSig )
191
195
tagsParser ws
0 commit comments