haskoin-core 0.8.3 → 0.8.4
raw patch · 4 files changed
+31/−2 lines, 4 files
Files
- CHANGELOG.md +4/−0
- haskoin-core.cabal +2/−2
- src/Network/Haskoin/Block/Headers.hs +10/−0
- test/Network/Haskoin/BlockSpec.hs +15/−0
CHANGELOG.md view
@@ -4,6 +4,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## 0.8.4+### Added+- Add reward computation to block functions.+ ## 0.8.3 ### Added - Add reward halving interval parameter to network constants.
haskoin-core.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 47347401d0d4e92d643d282dd4bf993ced972b2b0300de57d02efc74c705a647+-- hash: d2a9fa5a1034de67fddae041cd6e5f2473a5b97aa7951715ea23ef2c0154e909 name: haskoin-core-version: 0.8.3+version: 0.8.4 synopsis: Bitcoin & Bitcoin Cash library for Haskell description: Haskoin Core is a complete Bitcoin and Bitcoin Cash library of functions and data types for Haskell developers. category: Bitcoin, Finance, Network
src/Network/Haskoin/Block/Headers.hs view
@@ -58,6 +58,7 @@ , diffInterval , blockLocatorNodes , mineBlock+ , computeSubsidy , ) where import Control.Applicative ((<|>))@@ -728,3 +729,12 @@ -- | Generate the entire Genesis block for 'Network'. genesisBlock :: Network -> Block genesisBlock net = Block (getGenesisHeader net) [genesisTx]++-- | Compute block subsidy at particular height.+computeSubsidy :: Network -> BlockHeight -> Word64+computeSubsidy net height =+ let halvings = height `div` getHalvingInterval net+ ini = 50 * 100 * 1000 * 1000+ in if halvings >= 64+ then 0+ else ini `shiftR` fromIntegral halvings
test/Network/Haskoin/BlockSpec.hs view
@@ -95,6 +95,9 @@ property $ forAll arbitraryHeaders cerealID it "encodes and decodes merkle block" $ property $ forAll arbitraryMerkleBlock cerealID+ describe "helper functions" $ do+ it "computes bitcoin block subsidy correctly" (testSubsidy btc)+ it "computes regtest block subsidy correctly" (testSubsidy btcRegTest) -- 0 → → 2015 → → → → → → → 4031 -- ↓@@ -338,3 +341,15 @@ cerealID :: (Serialize a, Eq a) => a -> Bool cerealID x = S.decode (S.encode x) == Right x++testSubsidy :: Network -> Assertion+testSubsidy net = go (2 * 50 * 100 * 1000 * 1000) 0+ where+ go previous_subsidy halvings = do+ let height = halvings * getHalvingInterval net+ subsidy = computeSubsidy net height+ if halvings >= 64+ then subsidy `shouldBe` 0+ else do+ subsidy `shouldBe` (previous_subsidy `div` 2)+ go subsidy (halvings + 1)