Skip to content

Commit b62d19a

Browse files
committed
removes aeson and mtl
1 parent a798881 commit b62d19a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+595
-633
lines changed

bitcoin.cabal

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 1.12
22

3-
-- This file has been generated from package.yaml by hpack version 0.34.4.
3+
-- This file has been generated from package.yaml by hpack version 0.35.0.
44
--
55
-- see: https://github.com/sol/hpack
66

@@ -93,7 +93,6 @@ library
9393
src
9494
build-depends:
9595
QuickCheck >=2.13.2
96-
, aeson >=1.4.6.0
9796
, array >=0.5.4.0
9897
, base >=4.9 && <5
9998
, base16 >=0.3.0.1
@@ -108,7 +107,6 @@ library
108107
, hashable >=1.3.0.0
109108
, hspec >=2.7.1
110109
, memory >=0.15.0
111-
, mtl >=2.2.2
112110
, murmur3 >=1.0.3
113111
, network >=3.1.1.1
114112
, safe >=0.3.18
@@ -136,6 +134,7 @@ test-suite spec
136134
Bitcoin.Keys.MnemonicSpec
137135
Bitcoin.KeysSpec
138136
Bitcoin.NetworkSpec
137+
Bitcoin.Orphans
139138
Bitcoin.ScriptSpec
140139
Bitcoin.Transaction.PartialSpec
141140
Bitcoin.Transaction.TaprootSpec
@@ -166,7 +165,6 @@ test-suite spec
166165
, lens >=4.18.1
167166
, lens-aeson >=1.1
168167
, memory >=0.15.0
169-
, mtl >=2.2.2
170168
, murmur3 >=1.0.3
171169
, network >=3.1.1.1
172170
, safe >=0.3.18

hie.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
cradle:
2+
cabal:
3+
- path: "src"
4+
component: "lib:bitcoin"
5+
6+
- path: "test"
7+
component: "bitcoin:test:spec"

package.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extra-source-files:
1919
- README.md
2020
- CHANGELOG.md
2121
dependencies:
22-
- aeson >= 1.4.6.0
2322
- array >= 0.5.4.0
2423
- base >=4.9 && <5
2524
- base16 >= 0.3.0.1
@@ -34,7 +33,6 @@ dependencies:
3433
- hashable >= 1.3.0.0
3534
- hspec >= 2.7.1
3635
- memory >= 0.15.0
37-
- mtl >= 2.2.2
3836
- murmur3 >= 1.0.3
3937
- network >= 3.1.1.1
4038
- QuickCheck >= 2.13.2
@@ -61,6 +59,7 @@ tests:
6159
verbatim:
6260
build-tool-depends: hspec-discover:hspec-discover
6361
dependencies:
62+
- aeson >= 1.4.6.0
6463
- base64 ^>= 0.4
6564
- bitcoin
6665
- hspec >= 2.7.1

src/Bitcoin/Address.hs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ module Bitcoin.Address (
2222
textToAddr,
2323
bech32ToAddr,
2424
base58ToAddr,
25-
addrToJSON,
26-
addrToEncoding,
27-
addrFromJSON,
2825
pubKeyAddr,
2926
pubKeyWitnessAddr,
3027
pubKeyCompatWitnessAddr,
@@ -57,9 +54,6 @@ import Control.Applicative
5754
import Control.Arrow (second)
5855
import Control.DeepSeq
5956
import Control.Monad
60-
import Data.Aeson as A
61-
import Data.Aeson.Encoding as A
62-
import Data.Aeson.Types
6357
import Data.Binary (Binary (..))
6458
import Data.ByteString (ByteString)
6559
import qualified Data.ByteString as B
@@ -181,24 +175,6 @@ isWitnessAddress WitnessAddress{} = True
181175
isWitnessAddress _ = False
182176

183177

184-
addrToJSON :: Network -> Address -> Value
185-
addrToJSON net a = toJSON (addrToText net a)
186-
187-
188-
addrToEncoding :: Network -> Address -> Encoding
189-
addrToEncoding net = maybe null_ text . addrToText net
190-
191-
192-
-- | JSON parsing for Bitcoin addresses. Works with 'Base58', and
193-
-- 'Bech32'.
194-
addrFromJSON :: Network -> Value -> Parser Address
195-
addrFromJSON net =
196-
withText "address" $ \t ->
197-
case textToAddr net t of
198-
Nothing -> fail "could not decode address"
199-
Just x -> return x
200-
201-
202178
-- | Convert address to human-readable string. Uses 'Base58', or 'Bech32'
203179
-- depending on network.
204180
addrToText :: Network -> Address -> Maybe Text

src/Bitcoin/Block/Common.hs

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@ import Bitcoin.Transaction.Common
3232
import Bitcoin.Util
3333
import Control.DeepSeq
3434
import Control.Monad (forM_, liftM2, mzero, replicateM, (<=<))
35-
import Data.Aeson (
36-
FromJSON (..),
37-
ToJSON (..),
38-
Value (..),
39-
object,
40-
toJSON,
41-
withObject,
42-
withText,
43-
(.:),
44-
(.=),
45-
)
46-
import Data.Aeson.Encoding (pairs, unsafeToEncoding)
4735
import Data.Binary (Binary (..))
4836
import Data.Bits (shiftL, shiftR, (.&.), (.|.))
4937
import qualified Data.ByteString as B
@@ -111,17 +99,6 @@ instance Binary Block where
11199
put = serialize
112100

113101

114-
instance ToJSON Block where
115-
toJSON (Block h t) = object ["header" .= h, "transactions" .= t]
116-
toEncoding (Block h t) = pairs $ "header" .= h <> "transactions" .= t
117-
118-
119-
instance FromJSON Block where
120-
parseJSON =
121-
withObject "Block" $ \o ->
122-
Block <$> o .: "header" <*> o .: "transactions"
123-
124-
125102
-- | Block header hash. To be serialized reversed for display purposes.
126103
newtype BlockHash = BlockHash
127104
{ getBlockHash :: Hash256
@@ -155,21 +132,6 @@ instance IsString BlockHash where
155132
in fromMaybe e $ hexToBlockHash $ cs s
156133

157134

158-
instance FromJSON BlockHash where
159-
parseJSON =
160-
withText "BlockHash" $
161-
maybe mzero return . hexToBlockHash
162-
163-
164-
instance ToJSON BlockHash where
165-
toJSON = String . blockHashToHex
166-
toEncoding h =
167-
unsafeToEncoding $
168-
char7 '"'
169-
<> hexBuilder (BL.reverse (runPutL (serialize h)))
170-
<> char7 '"'
171-
172-
173135
-- | Block hashes are reversed with respect to the in-memory byte order in a
174136
-- block hash when displayed.
175137
blockHashToHex :: BlockHash -> Text
@@ -212,43 +174,6 @@ data BlockHeader = BlockHeader
212174
deriving (Eq, Ord, Show, Read, Generic, Hashable, NFData)
213175

214176

215-
-- 80 bytes
216-
217-
instance ToJSON BlockHeader where
218-
toJSON (BlockHeader v p m t b n) =
219-
object
220-
[ "version" .= v
221-
, "prevblock" .= p
222-
, "merkleroot" .= encodeHex (runPutS (serialize m))
223-
, "timestamp" .= t
224-
, "bits" .= b
225-
, "nonce" .= n
226-
]
227-
toEncoding (BlockHeader v p m t b n) =
228-
pairs
229-
( "version" .= v
230-
<> "prevblock" .= p
231-
<> "merkleroot" .= encodeHex (runPutS (serialize m))
232-
<> "timestamp" .= t
233-
<> "bits" .= b
234-
<> "nonce" .= n
235-
)
236-
237-
238-
instance FromJSON BlockHeader where
239-
parseJSON =
240-
withObject "BlockHeader" $ \o ->
241-
BlockHeader
242-
<$> o .: "version"
243-
<*> o .: "prevblock"
244-
<*> (f =<< o .: "merkleroot")
245-
<*> o .: "timestamp"
246-
<*> o .: "bits"
247-
<*> o .: "nonce"
248-
where
249-
f = maybe mzero return . (eitherToMaybe . runGetS deserialize <=< decodeHex)
250-
251-
252177
instance Serial BlockHeader where
253178
deserialize = do
254179
v <- getWord32le

src/Bitcoin/Block/Headers.hs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module Bitcoin.Block.Headers (
4545
bip34,
4646
validVersion,
4747
lastNoMinDiff,
48-
computeAsertBits,
48+
computeAssertBits,
4949
nextPowWorkRequired,
5050
calcNextWork,
5151
isValidPOW,
@@ -68,19 +68,10 @@ import Bitcoin.Util
6868
import Control.Applicative ((<|>))
6969
import Control.DeepSeq
7070
import Control.Monad (guard, mzero, unless, when)
71-
import Control.Monad.Except (
72-
ExceptT (..),
73-
runExceptT,
74-
throwError,
75-
)
76-
import Control.Monad.State.Strict as State (
77-
StateT,
78-
get,
79-
gets,
80-
lift,
81-
modify,
82-
)
71+
import Control.Monad.Trans.Class (lift)
72+
import Control.Monad.Trans.Except (ExceptT (..), runExceptT, throwE)
8373
import Control.Monad.Trans.Maybe
74+
import Control.Monad.Trans.State.Strict as State (StateT, get, gets, modify)
8475
import Data.Binary (Binary (..))
8576
import Data.Bits (shiftL, shiftR, (.&.))
8677
import qualified Data.ByteString as B
@@ -323,7 +314,7 @@ connectBlocks _ _ [] = return $ Right []
323314
connectBlocks net t bhs@(bh : _) =
324315
runExceptT $ do
325316
unless (chained bhs) $
326-
throwError "Blocks to connect do not form a chain"
317+
throwE "Blocks to connect do not form a chain"
327318
par <-
328319
maybeToExceptT
329320
"Could not get parent block"
@@ -347,13 +338,13 @@ connectBlocks net t bhs@(bh : _) =
347338
case skM of
348339
Just sk -> return sk
349340
Nothing ->
350-
throwError $
341+
throwE $
351342
"BUG: Could not get skip for block "
352343
++ show (headerHash $ nodeHeader par)
353344
| otherwise = do
354345
let sn = ls !! fromIntegral (nodeHeight par - sh)
355346
when (nodeHeight sn /= sh) $
356-
throwError "BUG: Node height not right in skip"
347+
throwE "BUG: Node height not right in skip"
357348
return sn
358349
where
359350
sh = skipHeight (nodeHeight par + 1)
@@ -394,7 +385,7 @@ connectBlock net t bh =
394385
case skM of
395386
Just sk -> return sk
396387
Nothing ->
397-
throwError $
388+
throwE $
398389
"BUG: Could not get skip for block "
399390
++ show (headerHash $ nodeHeader par)
400391
bb <- lift getBestBlockHeader
@@ -686,13 +677,13 @@ maxTarget :: Integer
686677
maxTarget = fst $ decodeCompact maxBits
687678

688679

689-
computeAsertBits ::
680+
computeAssertBits ::
690681
Integer ->
691682
Word32 ->
692683
Integer ->
693684
Integer ->
694685
Word32
695-
computeAsertBits halflife anchor_bits time_diff height_diff =
686+
computeAssertBits halflife anchor_bits time_diff height_diff =
696687
if e2 >= 0 && e2 < 65536
697688
then
698689
if g4 == 0

src/Bitcoin/Keys/Common.hs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ import Bitcoin.Util
3838
import Control.DeepSeq
3939
import Control.Monad (guard, mzero, (<=<))
4040
import Crypto.Secp256k1
41-
import Data.Aeson (
42-
FromJSON,
43-
ToJSON (..),
44-
Value (String),
45-
parseJSON,
46-
withText,
47-
)
48-
import Data.Aeson.Encoding (unsafeToEncoding)
4941
import Data.Binary (Binary (..))
5042
import Data.ByteString (ByteString)
5143
import qualified Data.ByteString as BS
@@ -76,21 +68,6 @@ instance IsString PubKeyI where
7668
e = error "Could not decode public key"
7769

7870

79-
instance ToJSON PubKeyI where
80-
toJSON = String . encodeHex . runPutS . serialize
81-
toEncoding s =
82-
unsafeToEncoding $
83-
char7 '"'
84-
<> hexBuilder (runPutL (serialize s))
85-
<> char7 '"'
86-
87-
88-
instance FromJSON PubKeyI where
89-
parseJSON =
90-
withText "PubKeyI" $
91-
maybe mzero return . ((eitherToMaybe . runGetS deserialize) <=< decodeHex)
92-
93-
9471
instance Serial PubKeyI where
9572
deserialize =
9673
s >>= \case

0 commit comments

Comments
 (0)