-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework createWallet to support different AD schemes
- Loading branch information
Showing
11 changed files
with
165 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/bench/Cardano/Wallet/Primitive/AddressDiscovery/Any.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
{-# LANGUAGE DerivingStrategies #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
-- | | ||
-- Copyright: © 2018-2019 IOHK | ||
-- License: MIT | ||
-- | ||
-- Custom address discovery schemes used for testing and benchmarking. | ||
-- | ||
|
||
module Cardano.Wallet.Primitive.AddressDiscovery.Any | ||
( AnyAddressState (..) | ||
, initAnyState | ||
) where | ||
|
||
import Prelude | ||
|
||
import Cardano.Wallet.Primitive.Types | ||
( Address (..), IsOurs (..), WalletId (..) ) | ||
import Control.DeepSeq | ||
( NFData ) | ||
import Crypto.Hash | ||
( hash ) | ||
import Data.Digest.CRC32 | ||
( crc32 ) | ||
import Data.Word | ||
( Word32 ) | ||
import GHC.Generics | ||
( Generic ) | ||
|
||
import qualified Data.ByteString.Char8 as B8 | ||
|
||
---------------------------------------------------------------------------- | ||
|
||
-- | Any Address Derivation | ||
-- | ||
-- An arbitrary fraction of addreses are recognized as "ours". This is done by | ||
-- looking at a checksum of the address. | ||
newtype AnyAddressState = AnyAddressState | ||
{ oursProportion :: Double | ||
} | ||
deriving stock (Generic, Show) | ||
|
||
instance NFData AnyAddressState | ||
|
||
instance IsOurs AnyAddressState where | ||
isOurs (Address addr) s@(AnyAddressState p) = (crc32 addr < p', s) | ||
where | ||
p' = floor (fromIntegral (maxBound :: Word32) * p) | ||
|
||
initAnyState :: Double -> (WalletId, AnyAddressState) | ||
initAnyState p = (walletId cfg, cfg) | ||
where cfg = AnyAddressState p | ||
|
||
walletId :: Show a => a -> WalletId | ||
walletId = WalletId . hash . B8.pack . show |
Oops, something went wrong.