Skip to content

Commit

Permalink
add persistance to verKeysIndexedKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Nov 28, 2020
1 parent e3e413b commit 0aa437a
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import Prelude

import Cardano.Address.Derivation
( XPrv, XPub )
import Cardano.Address.Script
( KeyHash (..) )
import Cardano.DB.Sqlite
( DBField (..)
, DBLog (..)
Expand Down Expand Up @@ -1738,6 +1740,7 @@ instance
}
insertAddressPool @n wid sl intPool
insertAddressPool @n wid sl extPool
insertScriptPool wid sl sPool
deleteWhere [SeqStatePendingWalletId ==. wid]
dbChunked
insertMany_
Expand All @@ -1750,10 +1753,9 @@ instance
let rewardXPub = unsafeDeserializeXPub rewardBytes
intPool <- lift $ selectAddressPool @n wid sl iGap accountXPub
extPool <- lift $ selectAddressPool @n wid sl eGap accountXPub
--TO-DO
let multiPool = Seq.mkVerificationKeyPool accountXPub sGap Map.empty Map.empty
sPool <- lift $ selectScriptPool wid sl sGap accountXPub
pendingChangeIxs <- lift $ selectSeqStatePendingIxs wid
pure $ Seq.SeqState intPool extPool pendingChangeIxs rewardXPub prefix multiPool
pure $ Seq.SeqState intPool extPool pendingChangeIxs rewardXPub prefix sPool

insertAddressPool
:: forall n k c. (PaymentAddress n k, Typeable c)
Expand Down Expand Up @@ -1807,6 +1809,45 @@ selectSeqStatePendingIxs wid =
where
fromRes = fmap (W.Index . seqStatePendingIxIndex . entityVal)

insertScriptPool
:: W.WalletId
-> W.SlotNo
-> Seq.VerificationKeyPool k
-> SqlPersistT IO ()
insertScriptPool wid sl pool =
void $ dbChunked insertMany_
[ SeqStateAddress wid sl (W.Address payload) (getIndex ix) W.MultisigScript state
| (KeyHash payload, (ix, state) )
<- Map.toList (Seq.verPoolIndexedKeys pool)
]

selectScriptPool
:: forall k .
( SoftDerivation k
, WalletKey k
)
=> W.WalletId
-> W.SlotNo
-> Seq.AddressPoolGap
-> k 'AccountK XPub
-> SqlPersistT IO (Seq.VerificationKeyPool k)
selectScriptPool wid sl gap xpub = do
verKeys <- fmap entityVal <$> selectList
[ SeqStateAddressWalletId ==. wid
, SeqStateAddressSlot ==. sl
, SeqStateAddressRole ==. W.MultisigScript
] [Asc SeqStateAddressIndex]
pure $ scriptPoolFromEntity verKeys
where
verKeyMap =
Map.fromList .
map (\x -> (coerce $ seqStateAddressAddress x, (Index $ seqStateAddressIndex x, seqStateAddressStatus x)) )
scriptPoolFromEntity
:: [SeqStateAddress]
-> Seq.VerificationKeyPool k
scriptPoolFromEntity verKeys
= Seq.mkVerificationKeyPool xpub gap (verKeyMap verKeys) Map.empty

{-------------------------------------------------------------------------------
HD Random address discovery
-------------------------------------------------------------------------------}
Expand Down

0 comments on commit 0aa437a

Please sign in to comment.