Skip to content

Commit

Permalink
add CosignerKey schema
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Apr 8, 2021
1 parent 6dec62f commit 1cb127c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
20 changes: 19 additions & 1 deletion lib/core/src/Cardano/Wallet/DB/Sqlite/TH.hs
Expand Up @@ -33,14 +33,18 @@ import Cardano.Slotting.Slot
( SlotNo )
import Cardano.Wallet.DB.Sqlite.Types
( BlockId, HDPassphrase, TxId, sqlSettings' )
import Cardano.Wallet.Primitive.AddressDiscovery.Script
( CredentialType )
import Data.Quantity
( Percentage (..) )
import Data.Text
( Text )
import Data.Time.Clock
( UTCTime )
import Data.Word
( Word16, Word32, Word64 )
( Word16, Word32, Word64, Word8 )
import Database.Persist.Class
( AtLeastOneUniqueKey (..), OnlyOneUniqueKey (..) )
import Database.Persist.TH
( mkDeleteCascade, mkMigrate, mkPersist, persistLowerCase, share )
import GHC.Generics
Expand Down Expand Up @@ -392,4 +396,18 @@ SharedWallet

Primary sharedWalletWalletId
deriving Show Generic

CosignerKey
cosignerKeyWalletId W.WalletId sql=wallet_id
cosignerKeyCreationTime UTCTime sql=creation_time
cosignerKeyCredential CredentialType sql=credential
cosignerKeyAccountXPub B8.ByteString sql=account_xpub
cosignerKeyIndex Word8 sql=cosigner_ix

Primary
cosignerKeyWalletId
cosignerKeyCredential
cosignerKeyIndex
Foreign SharedWallet fk_shared_wallet_cosigner_key cosignerKeyWalletId ! ON DELETE CASCADE
deriving Show Generic
|]
15 changes: 15 additions & 0 deletions lib/core/src/Cardano/Wallet/DB/Sqlite/Types.hs
Expand Up @@ -34,6 +34,8 @@ import Cardano.Slotting.Slot
( SlotNo (..) )
import Cardano.Wallet.Primitive.AddressDerivation
( Passphrase (..), PassphraseScheme (..), Role (..) )
import Cardano.Wallet.Primitive.AddressDiscovery.Script
( CredentialType )
import Cardano.Wallet.Primitive.AddressDiscovery.Sequential
( AddressPoolGap (..)
, DerivationPrefix
Expand Down Expand Up @@ -518,6 +520,19 @@ instance PersistField (Script Cosigner) where
instance PersistFieldSql (Script Cosigner) where
sqlType _ = sqlType (Proxy @Text)


----------------------------------------------------------------------------
-- CredentialType

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

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

----------------------------------------------------------------------------

----------------------------------------------------------------------------
-- AddressPoolGap

Expand Down
24 changes: 22 additions & 2 deletions lib/core/src/Cardano/Wallet/Primitive/AddressDiscovery/Script.hs
Expand Up @@ -17,11 +17,12 @@
-- License: Apache-2.0
--
-- An implementation of shared script state using
-- scheme specified in CIP-XXX Multi-signature Wallets.
-- scheme specified in CIP-1854 Multi-signature Wallets..

module Cardano.Wallet.Primitive.AddressDiscovery.Script
(
keyHashFromAccXPubIx
CredentialType (..)
, keyHashFromAccXPubIx
, constructAddressFromIx
, toNetworkTag
, replaceCosignersWithVerKeys
Expand Down Expand Up @@ -72,6 +73,9 @@ import Data.Kind
( Type )
import Data.Maybe
( fromJust, fromMaybe, isJust )
( fromMaybe, isJust )
import Data.Text.Class
( FromText (..), TextDecodingError (..), ToText (..) )
import Data.Type.Equality
( (:~:) (..), testEquality )
import Type.Reflection
Expand All @@ -82,6 +86,22 @@ import qualified Cardano.Address.Derivation as CA
import qualified Cardano.Address.Style.Shelley as CA
import qualified Data.Map.Strict as Map

data CredentialType = Payment | Delegation
deriving (Eq, Show)

instance ToText CredentialType where
toText Payment = "payment"
toText Delegation = "delegation"

instance FromText CredentialType where
fromText = \case
"payment" -> Right Payment
"delegation" -> Right Delegation
_ -> Left $ TextDecodingError $ unwords
[ "Invalid credential type: expecting only following values:"
, "'payment', 'delegation'."
]

keyHashFromAccXPubIx
:: (SoftDerivation k, WalletKey k)
=> k 'AccountK XPub
Expand Down

0 comments on commit 1cb127c

Please sign in to comment.