diff --git a/.weeder.yaml b/.weeder.yaml index fcdc70d75ad..5180716a5bd 100644 --- a/.weeder.yaml +++ b/.weeder.yaml @@ -1,15 +1,5 @@ - package: - name: cardano-wallet - - section: - - name: bench:restore - - message: - - name: Weeds exported - - module: - - name: Cardano.Wallet.Primitive.AddressDiscovery.Any.TH - - identifier: - - AnyAddressStateId - - AnyAddressStateKey - - AnyAddressStateProportion - section: - name: test:integration bench:latency - message: diff --git a/lib/shelley/bench/Cardano/Wallet/Primitive/AddressDiscovery/Any.hs b/lib/shelley/bench/Cardano/Wallet/Primitive/AddressDiscovery/Any.hs deleted file mode 100644 index 05a537b0841..00000000000 --- a/lib/shelley/bench/Cardano/Wallet/Primitive/AddressDiscovery/Any.hs +++ /dev/null @@ -1,108 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE DerivingStrategies #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE TypeFamilies #-} - --- | --- Copyright: © 2018-2019 IOHK --- License: Apache-2.0 --- --- Custom address discovery schemes used for testing and benchmarking. --- - -module Cardano.Wallet.Primitive.AddressDiscovery.Any - ( AnyAddressState (..) - , initAnyState - ) where - -import Prelude - -import Cardano.Wallet.DB.Sqlite - ( PersistState (..) ) -import Cardano.Wallet.Primitive.AddressDiscovery - ( CompareDiscovery (..) - , GenChange (..) - , IsOurs (..) - , IsOwned (..) - , KnownAddresses (..) - ) -import Cardano.Wallet.Primitive.Types - ( Address (..), ChimericAccount (..), WalletId (..), WalletName (..) ) -import Control.DeepSeq - ( NFData ) -import Control.Monad.Trans.Maybe - ( MaybeT (..) ) -import Crypto.Hash - ( hash ) -import Data.Digest.CRC32 - ( crc32 ) -import Data.Text - ( Text ) -import Data.Word - ( Word32 ) -import Database.Persist.Sql - ( entityVal, insert_, selectFirst, (==.) ) -import GHC.Generics - ( Generic ) - -import qualified Cardano.Wallet.Primitive.AddressDiscovery.Any.TH as DB -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 Address where - isOurs (Address addr) s@(AnyAddressState p) = (crc32 addr < p', s) - where - p' = floor (fromIntegral (maxBound :: Word32) * p) - -instance IsOurs AnyAddressState ChimericAccount where - isOurs _ s = (False, s) - -instance IsOwned AnyAddressState key where - isOwned _ _ _ = Nothing - -instance GenChange AnyAddressState where - type ArgGenChange AnyAddressState = () - genChange _ = error - "GenChange.genChange: trying to generate change for \ - \an incompatible scheme 'AnyAddressState'. Please don't." - -instance CompareDiscovery AnyAddressState where - compareDiscovery _ _ _ = error - "CompareDiscovery.compareDiscovery: trying to generate change for \ - \an incompatible scheme 'AnyAddressState'. Please don't." - -instance KnownAddresses AnyAddressState where - knownAddresses _ = error - "KnownAddresses.knownAddresses: trying to generate change for \ - \an incompatible scheme 'AnyAddressState'. Please don't." - -instance PersistState AnyAddressState where - insertState (wid, sl) (AnyAddressState s) = - insert_ (DB.AnyAddressState wid sl s) - selectState (wid, sl) = runMaybeT $ do - DB.AnyAddressState _ _ s <- MaybeT $ fmap entityVal <$> selectFirst - [ DB.AnyAddressStateWalletId ==. wid - , DB.AnyAddressStateCheckpointSlot ==. sl - ] [] - return (AnyAddressState s) - -initAnyState :: Text -> Double -> (WalletId, WalletName, AnyAddressState) -initAnyState wname p = (walletId cfg, WalletName wname, cfg) - where cfg = AnyAddressState p - -walletId :: Show a => a -> WalletId -walletId = WalletId . hash . B8.pack . show diff --git a/lib/shelley/bench/Cardano/Wallet/Primitive/AddressDiscovery/Any/TH.hs b/lib/shelley/bench/Cardano/Wallet/Primitive/AddressDiscovery/Any/TH.hs deleted file mode 100644 index e1ff1a4292e..00000000000 --- a/lib/shelley/bench/Cardano/Wallet/Primitive/AddressDiscovery/Any/TH.hs +++ /dev/null @@ -1,42 +0,0 @@ -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE GADTs #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE QuasiQuotes #-} -{-# LANGUAGE TemplateHaskell #-} -{-# LANGUAGE TypeFamilies #-} -{-# LANGUAGE UndecidableInstances #-} - - --- | --- Copyright: © 2018-2019 IOHK --- License: Apache-2.0 --- --- Automatically generated code via Template-Haskell. Contains necessary --- database rows and columns declaration to work with 'AnyAddressState'. - -module Cardano.Wallet.Primitive.AddressDiscovery.Any.TH where - -import Prelude - -import Cardano.Wallet.DB.Sqlite.Types - ( sqlSettings' ) -import Database.Persist.Class - ( AtLeastOneUniqueKey (..), OnlyOneUniqueKey (..) ) -import Database.Persist.TH - ( mkDeleteCascade, mkMigrate, mkPersist, persistLowerCase, share ) - -import qualified Cardano.Wallet.Primitive.Types as W - -share - [ mkPersist sqlSettings' - , mkDeleteCascade sqlSettings' - , mkMigrate "migrateAll" - ] - [persistLowerCase| -AnyAddressState - anyAddressStateWalletId W.WalletId sql=wallet_id - anyAddressStateCheckpointSlot W.SlotNo sql=slot - anyAddressStateProportion Double sql=proportion -|] diff --git a/lib/shelley/cardano-wallet.cabal b/lib/shelley/cardano-wallet.cabal index be31e88fd2c..b856caae96b 100644 --- a/lib/shelley/cardano-wallet.cabal +++ b/lib/shelley/cardano-wallet.cabal @@ -236,15 +236,10 @@ benchmark restore , cardano-wallet-core-integration , cardano-wallet , contra-tracer - , containers - , cryptonite , deepseq - , digest , filepath , fmt , iohk-monitoring - , persistent - , persistent-template , say , temporary , text @@ -256,9 +251,6 @@ benchmark restore bench main-is: Restore.hs - other-modules: - Cardano.Wallet.Primitive.AddressDiscovery.Any - Cardano.Wallet.Primitive.AddressDiscovery.Any.TH benchmark latency default-language: