-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move delegation certificate declaration in a separate table #980
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ import Cardano.Wallet.DB | |
) | ||
import Cardano.Wallet.DB.Sqlite.TH | ||
( Checkpoint (..) | ||
, DelegationCertificate (..) | ||
, EntityField (..) | ||
, Key (..) | ||
, PrivateKey (..) | ||
|
@@ -359,6 +360,9 @@ newDBLayer logConfig trace mDatabaseFile = do | |
deleteCheckpoints wid | ||
[ CheckpointSlot >. point | ||
] | ||
deleteDelegationCertificates wid | ||
[ CertSlot >. point | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
] | ||
updateTxMetas wid | ||
[ TxMetaDirection ==. W.Outgoing | ||
, TxMetaSlot >. point | ||
|
@@ -391,10 +395,18 @@ newDBLayer logConfig trace mDatabaseFile = do | |
pure $ Right () | ||
Nothing -> pure $ Left $ ErrNoSuchWallet wid | ||
|
||
, readWalletMeta = \(PrimaryKey wid) -> | ||
runQuery $ | ||
fmap (metadataFromEntity . entityVal) <$> | ||
selectFirst [WalId ==. wid] [] | ||
, readWalletMeta = \(PrimaryKey wid) -> runQuery $ do | ||
walDelegation <- delegationFromEntity . fmap entityVal | ||
<$> selectFirst [CertWalletId ==. wid] [Desc CertSlot] | ||
|
||
fmap (metadataFromEntity walDelegation . entityVal) | ||
<$> selectFirst [WalId ==. wid] [] | ||
|
||
, putDelegationCertificate = \pk pool sl -> ExceptT $ runQuery $ do | ||
let (PrimaryKey wid) = pk | ||
selectWallet wid >>= \case | ||
Nothing -> pure $ Left $ ErrNoSuchWallet wid | ||
Just _ -> pure <$> insert_ (DelegationCertificate wid sl pool) | ||
|
||
{----------------------------------------------------------------------- | ||
Tx History | ||
|
@@ -466,13 +478,14 @@ newDBLayer logConfig trace mDatabaseFile = do | |
ExceptT $ withMVar lock $ \() -> runExceptT action | ||
}) | ||
|
||
delegationToPoolId :: W.WalletDelegation W.PoolId -> Maybe W.PoolId | ||
delegationToPoolId W.NotDelegating = Nothing | ||
delegationToPoolId (W.Delegating pool) = Just pool | ||
|
||
delegationFromPoolId :: Maybe W.PoolId -> W.WalletDelegation W.PoolId | ||
delegationFromPoolId Nothing = W.NotDelegating | ||
delegationFromPoolId (Just pool) = W.Delegating pool | ||
delegationFromEntity | ||
:: Maybe DelegationCertificate | ||
-> W.WalletDelegation W.PoolId | ||
delegationFromEntity = \case | ||
Nothing -> | ||
W.NotDelegating | ||
Just (DelegationCertificate _ _ pool) -> | ||
W.Delegating pool | ||
|
||
mkWalletEntity :: W.WalletId -> W.WalletMetadata -> Wallet | ||
mkWalletEntity wid meta = Wallet | ||
|
@@ -481,7 +494,6 @@ mkWalletEntity wid meta = Wallet | |
, walCreationTime = meta ^. #creationTime | ||
, walPassphraseLastUpdatedAt = | ||
W.lastUpdatedAt <$> meta ^. #passphraseInfo | ||
, walDelegation = delegationToPoolId $ meta ^. #delegation | ||
} | ||
|
||
mkWalletMetadataUpdate :: W.WalletMetadata -> [Update Wallet] | ||
|
@@ -490,7 +502,6 @@ mkWalletMetadataUpdate meta = | |
, WalCreationTime =. meta ^. #creationTime | ||
, WalPassphraseLastUpdatedAt =. | ||
W.lastUpdatedAt <$> meta ^. #passphraseInfo | ||
, WalDelegation =. delegationToPoolId (meta ^. #delegation) | ||
] | ||
|
||
blockHeaderFromEntity :: Checkpoint -> W.BlockHeader | ||
|
@@ -501,13 +512,13 @@ blockHeaderFromEntity cp = W.BlockHeader | |
, parentHeaderHash = getBlockId (checkpointParentHash cp) | ||
} | ||
|
||
metadataFromEntity :: Wallet -> W.WalletMetadata | ||
metadataFromEntity wal = W.WalletMetadata | ||
metadataFromEntity :: W.WalletDelegation W.PoolId -> Wallet -> W.WalletMetadata | ||
metadataFromEntity walDelegation wal = W.WalletMetadata | ||
{ name = W.WalletName (walName wal) | ||
, creationTime = walCreationTime wal | ||
, passphraseInfo = W.WalletPassphraseInfo <$> | ||
walPassphraseLastUpdatedAt wal | ||
, delegation = delegationFromPoolId (walDelegation wal) | ||
, delegation = walDelegation | ||
} | ||
|
||
mkPrivateKeyEntity | ||
|
@@ -781,6 +792,14 @@ deleteLooseTransactions = do | |
"LEFT OUTER JOIN tx_meta ON tx_meta.tx_id = "<> t <>".tx_id " <> | ||
"WHERE (tx_meta.tx_id IS NULL))" | ||
|
||
-- | Delete all delegation certificates matching the given filter | ||
deleteDelegationCertificates | ||
:: W.WalletId | ||
-> [Filter DelegationCertificate] | ||
-> SqlPersistT IO () | ||
deleteDelegationCertificates wid filters = do | ||
deleteCascadeWhere ((CertWalletId ==. wid) : filters) | ||
|
||
selectLatestCheckpoint | ||
:: W.WalletId | ||
-> SqlPersistT IO (Maybe Checkpoint) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -394,6 +394,12 @@ instance PathPiece PoolId where | |
fromPathPiece = fromTextMaybe | ||
toPathPiece = toText | ||
|
||
instance ToJSON PoolId where | ||
toJSON = String . toText | ||
|
||
instance FromJSON PoolId where | ||
parseJSON = aesonFromText "PoolId" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤷♂️ I still don't understand why persistent requires this for field involved in a PrimaryKey. This is non-sense. |
||
|
||
---------------------------------------------------------------------------- | ||
-- HDPassphrase | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ import Cardano.Wallet.Primitive.Types | |
, EpochLength (..) | ||
, EpochNo (..) | ||
, Hash (..) | ||
, PoolId (..) | ||
, ShowFmt (..) | ||
, SlotId (..) | ||
, SlotNo (..) | ||
|
@@ -506,7 +507,11 @@ instance Eq XPrv where | |
|
||
instance Arbitrary (Hash purpose) where | ||
arbitrary = do | ||
Hash . convertToBase Base16 . BS.pack <$> vectorOf 32 arbitrary | ||
Hash . convertToBase Base16 . BS.pack <$> vectorOf 16 arbitrary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generate only |
||
|
||
instance Arbitrary PoolId where | ||
arbitrary = do | ||
PoolId . convertToBase Base16 . BS.pack <$> vectorOf 16 arbitrary | ||
|
||
{------------------------------------------------------------------------------- | ||
Buildable | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just moved up next to other calls related to txs.