Skip to content

Commit

Permalink
extend pool database with two new tables to store metadata
Browse files Browse the repository at this point in the history
one of them will be used to persist a queue of metadata to fetch, while the other
is a less volatile storage where metadata gets dumped once fetched.
There's in principle no need for caching or timestamps here since
metadata can't be updated (hash is stored on-chain as part of the
registration) which simplifies a bit the problem.
  • Loading branch information
KtorZ committed Jun 17, 2020
1 parent 9650f59 commit a57cf75
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/core/src/Cardano/Pool/DB/Sqlite/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import Prelude

import Cardano.Wallet.DB.Sqlite.Types
( sqlSettings' )
import Data.ByteString
( ByteString )
import Data.Text
( Text )
import Data.Word
( Word32, Word64, Word8 )
import Database.Persist.Class
Expand Down Expand Up @@ -89,4 +93,26 @@ PoolRegistration sql=pool_registration

Primary poolRegistrationPoolId
deriving Show Generic

-- Temporary queue where metadata to fetch are stored.
PoolMetadataQueue sql=pool_metadata_queue
poolMetadataQueuePoolId W.PoolId sql=pool_id
poolMetadataQueueUrl Text sql=metadata_url
poolMetadataQueueHash ByteString sql=metadata_hash

Primary poolMetadataQueuePoolId
deriving Show Generic

-- Cached metadata after they've been fetched from a remote server.
PoolMetadata sql=pool_metadata
poolMetadataPoolId W.PoolId sql=pool_id
poolMetadataName Text sql=name
poolMetadataTicker W.StakePoolTicker sql=ticker
poolMetadataDescription Text Maybe sql=description
poolMetadataHomepage Text sql=homepage
poolMetadataPledge Word64 sql=pledge
poolMetadataOwner ByteString sql=owner

Primary poolMetadataPoolId
deriving Show Generic
|]
11 changes: 11 additions & 0 deletions lib/core/src/Cardano/Wallet/DB/Sqlite/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Cardano.Wallet.Primitive.Types
, PoolOwner (..)
, SlotId (..)
, SlotNo (..)
, StakePoolTicker
, TxStatus (..)
, WalletId (..)
, flatSlot
Expand Down Expand Up @@ -454,3 +455,13 @@ instance PersistField PassphraseScheme where

instance PersistFieldSql PassphraseScheme where
sqlType _ = sqlType (Proxy @String)

----------------------------------------------------------------------------
-- StakePoolTicker

instance PersistField StakePoolTicker where
toPersistValue = toPersistValue . toText
fromPersistValue = fromPersistValueFromText

instance PersistFieldSql StakePoolTicker where
sqlType _ = sqlType (Proxy @Text)

0 comments on commit a57cf75

Please sign in to comment.