Skip to content

Commit

Permalink
AccountingStyle -> Role renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Nov 27, 2020
1 parent 5276dfd commit 848dd00
Show file tree
Hide file tree
Showing 24 changed files with 125 additions and 129 deletions.
4 changes: 2 additions & 2 deletions lib/core-integration/src/Test/Integration/Faucet.hs
Expand Up @@ -48,11 +48,11 @@ import Cardano.Mnemonic
, mnemonicToText
)
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle (..)
, DerivationType (..)
( DerivationType (..)
, HardDerivation (..)
, NetworkDiscriminant (..)
, PaymentAddress (..)
, Role (..)
, WalletKey (..)
, deriveRewardAccount
, liftIndex
Expand Down
4 changes: 2 additions & 2 deletions lib/core-integration/src/Test/Integration/Framework/DSL.hs
Expand Up @@ -218,12 +218,12 @@ import Cardano.Wallet.Api.Types
, insertedAt
)
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle (..)
, HardDerivation (..)
( HardDerivation (..)
, NetworkDiscriminant (..)
, Passphrase (..)
, PaymentAddress (..)
, PersistPublicKey (..)
, Role (..)
, WalletKey (..)
, hex
, preparePassphrase
Expand Down
Expand Up @@ -32,11 +32,11 @@ import Cardano.Wallet.Api.Types
, WalletStyle (..)
)
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle (..)
, DerivationIndex (..)
( DerivationIndex (..)
, PassphraseMaxLength (..)
, PassphraseMinLength (..)
, PaymentAddress
, Role (..)
)
import Cardano.Wallet.Primitive.AddressDerivation.Byron
( ByronKey )
Expand Down Expand Up @@ -995,7 +995,7 @@ spec = describe "SHELLEY_WALLETS" $ do
--- $ cat root.prv \
--- > | cardano-address key child 1852H/1815H/0H/ROLE/INDEX \
--- > | cardano-address key public \
let matrix :: [(AccountingStyle, DerivationIndex, String)]
let matrix :: [(Role, DerivationIndex, String)]
matrix =
[ ( UtxoExternal
, DerivationIndex 0
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/Cardano/Wallet.hs
Expand Up @@ -217,8 +217,7 @@ import Cardano.Wallet.Network
, follow
)
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle (..)
, DelegationAddress (..)
( DelegationAddress (..)
, Depth (..)
, DerivationIndex (..)
, DerivationPrefix (..)
Expand All @@ -230,6 +229,7 @@ import Cardano.Wallet.Primitive.AddressDerivation
, NetworkDiscriminant (..)
, Passphrase
, PaymentAddress (..)
, Role (..)
, SoftDerivation (..)
, ToRewardAccount (..)
, WalletKey (..)
Expand Down Expand Up @@ -2285,7 +2285,7 @@ signMetadataWith
=> ctx
-> WalletId
-> Passphrase "raw"
-> (AccountingStyle, DerivationIndex)
-> (Role, DerivationIndex)
-> TxMetadata
-> ExceptT ErrSignMetadataWith IO (Signature TxMetadata)
signMetadataWith ctx wid pwd (role_, ix) metadata = db & \DBLayer{..} -> do
Expand Down Expand Up @@ -2316,7 +2316,7 @@ derivePublicKey
)
=> ctx
-> WalletId
-> AccountingStyle
-> Role
-> DerivationIndex
-> ExceptT ErrDerivePublicKey IO (k 'AddressK XPub)
derivePublicKey ctx wid role_ ix = db & \DBLayer{..} -> do
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/Cardano/Wallet/Api.hs
Expand Up @@ -162,7 +162,7 @@ import Cardano.Wallet.DB
import Cardano.Wallet.Network
( NetworkLayer )
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle, Depth, DerivationIndex )
( Depth, DerivationIndex, Role )
import Cardano.Wallet.Primitive.SyncProgress
( SyncTolerance )
import Cardano.Wallet.Primitive.Types
Expand Down Expand Up @@ -301,15 +301,15 @@ type WalletKeys =
type GetWalletKey = "wallets"
:> Capture "walletId" (ApiT WalletId)
:> "keys"
:> Capture "role" (ApiT AccountingStyle)
:> Capture "role" (ApiT Role)
:> Capture "index" (ApiT DerivationIndex)
:> Get '[JSON] ApiVerificationKey

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/signMetadata
type SignMetadata = "wallets"
:> Capture "walletId" (ApiT WalletId)
:> "signatures"
:> Capture "role" (ApiT AccountingStyle)
:> Capture "role" (ApiT Role)
:> Capture "index" (ApiT DerivationIndex)
:> ReqBody '[JSON] ApiWalletSignData
:> Post '[OctetStream] ByteString
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/Cardano/Wallet/Api/Link.hs
Expand Up @@ -109,7 +109,7 @@ import Cardano.Wallet.Api.Types
, WalletStyle (..)
)
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle, DerivationIndex, NetworkDiscriminant (..) )
( DerivationIndex, NetworkDiscriminant (..), Role )
import Cardano.Wallet.Primitive.Types
( PoolId, SortOrder, WalletId (..) )
import Cardano.Wallet.Primitive.Types.Address
Expand Down Expand Up @@ -277,7 +277,7 @@ getWalletKey
( HasType (ApiT WalletId) w
)
=> w
-> AccountingStyle
-> Role
-> DerivationIndex
-> (Method, Text)
getWalletKey w role_ index =
Expand All @@ -290,7 +290,7 @@ signMetadata
( HasType (ApiT WalletId) w
)
=> w
-> AccountingStyle
-> Role
-> DerivationIndex
-> (Method, Text)
signMetadata w role_ index =
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Expand Up @@ -233,8 +233,7 @@ import Cardano.Wallet.Network
, timeInterpreter
)
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle
, DelegationAddress (..)
( DelegationAddress (..)
, Depth (..)
, DerivationIndex (..)
, DerivationType (..)
Expand All @@ -245,6 +244,7 @@ import Cardano.Wallet.Primitive.AddressDerivation
, Passphrase (..)
, PaymentAddress (..)
, RewardAccount (..)
, Role
, SoftDerivation (..)
, WalletKey (..)
, deriveRewardAccount
Expand Down Expand Up @@ -1872,7 +1872,7 @@ signMetadata
)
=> ctx
-> ApiT WalletId
-> ApiT AccountingStyle
-> ApiT Role
-> ApiT DerivationIndex
-> ApiWalletSignData
-> Handler ByteString
Expand All @@ -1893,7 +1893,7 @@ derivePublicKey
)
=> ctx
-> ApiT WalletId
-> ApiT AccountingStyle
-> ApiT Role
-> ApiT DerivationIndex
-> Handler ApiVerificationKey
derivePublicKey ctx (ApiT wid) (ApiT role_) (ApiT ix) = do
Expand Down
6 changes: 3 additions & 3 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Expand Up @@ -170,14 +170,14 @@ import Cardano.Mnemonic
, natVals
)
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle (..)
, Depth (..)
( Depth (..)
, DerivationIndex (..)
, Index (..)
, NetworkDiscriminant (..)
, Passphrase (..)
, PassphraseMaxLength (..)
, PassphraseMinLength (..)
, Role (..)
, hex
)
import Cardano.Wallet.Primitive.AddressDerivation.Jormungandr
Expand Down Expand Up @@ -871,7 +871,7 @@ data ApiWalletSignData = ApiWalletSignData
deriving anyclass NFData

newtype ApiVerificationKey = ApiVerificationKey
{ getApiVerificationKey :: (ByteString, AccountingStyle)
{ getApiVerificationKey :: (ByteString, Role)
} deriving (Eq, Generic, Show)
deriving anyclass NFData

Expand Down
16 changes: 8 additions & 8 deletions lib/core/src/Cardano/Wallet/DB/Sqlite.hs
Expand Up @@ -377,7 +377,7 @@ migrateManually tr proxy defaultFieldValues =

addSeqStateDerivationPrefixIfMissing conn

renameAccountingStyle conn
renameRole conn
where
-- NOTE
-- Wallets created before the 'PassphraseScheme' was introduced have no
Expand Down Expand Up @@ -554,7 +554,7 @@ migrateManually tr proxy defaultFieldValues =
jormungandrPrefix =
shelleyPrefix

-- The 'AccountingStyle' constructors used to be respectively:
-- The 'Role' constructors used to be respectively:
--
-- - UTxOInternal
-- - UTxOExternal
Expand All @@ -567,11 +567,11 @@ migrateManually tr proxy defaultFieldValues =
-- which is pretty lame. This was changed later on, but already
-- serialized data may subsist on for quite a while. Hence this little
-- pirouette here.
renameAccountingStyle :: Sqlite.Connection -> IO ()
renameAccountingStyle conn = do
renameColumn conn (DBField SeqStateAddressAccountingStyle)
renameRole :: Sqlite.Connection -> IO ()
renameRole conn = do
renameColumn conn (DBField SeqStateAddressRole)
"u_tx_o_internal" "utxo_internal"
renameColumn conn (DBField SeqStateAddressAccountingStyle)
renameColumn conn (DBField SeqStateAddressRole)
"u_tx_o_external" "utxo_external"

-- | Determines whether a field is present in its parent table.
Expand Down Expand Up @@ -1719,7 +1719,7 @@ insertAddressPool
-> SqlPersistT IO ()
insertAddressPool wid sl pool =
void $ dbChunked insertMany_
[ SeqStateAddress wid sl addr ix (Seq.accountingStyle @c) state
[ SeqStateAddress wid sl addr ix (Seq.role @c) state
| (ix, (addr, state))
<- zip [0..] (Seq.addresses (liftPaymentAddress @n) pool)
]
Expand All @@ -1740,7 +1740,7 @@ selectAddressPool wid sl gap xpub = do
addrs <- fmap entityVal <$> selectList
[ SeqStateAddressWalletId ==. wid
, SeqStateAddressSlot ==. sl
, SeqStateAddressAccountingStyle ==. Seq.accountingStyle @c
, SeqStateAddressRole ==. Seq.role @c
] [Asc SeqStateAddressIndex]
pure $ addressPoolFromEntity addrs
where
Expand Down
4 changes: 2 additions & 2 deletions lib/core/src/Cardano/Wallet/DB/Sqlite/TH.hs
Expand Up @@ -253,15 +253,15 @@ SeqStateAddress
seqStateAddressSlot SlotNo sql=slot
seqStateAddressAddress W.Address sql=address
seqStateAddressIndex Word32 sql=address_ix
seqStateAddressAccountingStyle W.AccountingStyle sql=accounting_style
seqStateAddressRole W.Role sql=role
seqStateAddressStatus W.AddressState sql=status

Primary
seqStateAddressWalletId
seqStateAddressSlot
seqStateAddressAddress
seqStateAddressIndex
seqStateAddressAccountingStyle
seqStateAddressRole
Foreign Checkpoint seq_state_address seqStateAddressWalletId seqStateAddressSlot ! ON DELETE CASCADE
deriving Show Generic

Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/Cardano/Wallet/DB/Sqlite/Types.hs
Expand Up @@ -28,7 +28,7 @@ import Cardano.Api.Typed
import Cardano.Slotting.Slot
( SlotNo (..) )
import Cardano.Wallet.Primitive.AddressDerivation
( AccountingStyle (..), Passphrase (..), PassphraseScheme (..) )
( Passphrase (..), PassphraseScheme (..), Role (..) )
import Cardano.Wallet.Primitive.AddressDiscovery.Sequential
( AddressPoolGap (..)
, DerivationPrefix
Expand Down Expand Up @@ -435,13 +435,13 @@ instance PersistFieldSql AddressPoolGap where
sqlType _ = sqlType (Proxy @Word32)

----------------------------------------------------------------------------
-- AccountingStyle
-- Role

instance PersistField AccountingStyle where
instance PersistField Role where
toPersistValue = toPersistValue . toText
fromPersistValue = fromPersistValueFromText

instance PersistFieldSql AccountingStyle where
instance PersistFieldSql Role where
sqlType _ = sqlType (Proxy @Text)

----------------------------------------------------------------------------
Expand Down
28 changes: 14 additions & 14 deletions lib/core/src/Cardano/Wallet/Primitive/AddressDerivation.hs
Expand Up @@ -34,7 +34,7 @@ module Cardano.Wallet.Primitive.AddressDerivation
-- * HD Derivation
Depth (..)
, Index (..)
, AccountingStyle (..)
, Role (..)
, utxoExternal
, utxoInternal
, mutableAccount
Expand Down Expand Up @@ -165,45 +165,45 @@ import qualified Data.Text.Encoding as T
data Depth
= RootK | PurposeK | CoinTypeK | AccountK | RoleK | AddressK

-- | Marker for addresses type engaged. We want to handle three cases here.
-- The first two are pertinent to UTxO accounting
-- and the last one handles rewards from participation in staking.
-- | Marker for addresses type engaged. We want to handle four cases here.
-- The first two are pertinent to UTxO accounting,
-- next handles rewards from participation in staking
-- the last one is used for getting verification keys used in scripts.
-- (a) external chain is used for addresses that are part of the 'advertised'
-- targets of a given transaction
-- (b) internal change is for addresses used to handle the change of a
-- the transaction within a given wallet
-- (c) the addresses for a reward account
--
-- FIXME: rename this to 'Role' or 'HDRole'
data AccountingStyle
-- (d) used for keys used inside scripts
data Role
= UtxoExternal
| UtxoInternal
| MutableAccount
| MultisigScript
deriving (Generic, Typeable, Show, Eq, Ord, Bounded)

instance NFData AccountingStyle
instance NFData Role

-- Not deriving 'Enum' because this could have a dramatic impact if we were
-- to assign the wrong index to the corresponding constructor (by swapping
-- around the constructor above for instance).
instance Enum AccountingStyle where
instance Enum Role where
toEnum = \case
0 -> UtxoExternal
1 -> UtxoInternal
2 -> MutableAccount
3 -> MultisigScript
_ -> error "AccountingStyle.toEnum: bad argument"
_ -> error "Role.toEnum: bad argument"
fromEnum = \case
UtxoExternal -> 0
UtxoInternal -> 1
MutableAccount -> 2
MultisigScript -> 3

instance ToText AccountingStyle where
instance ToText Role where
toText = toTextFromBoundedEnum SnakeLowerCase

instance FromText AccountingStyle where
instance FromText Role where
fromText = fromTextToBoundedEnum SnakeLowerCase

-- | smart-constructor for getting a derivation index that refers to external
Expand Down Expand Up @@ -453,7 +453,7 @@ class HardDerivation (key :: Depth -> * -> *) where
deriveAddressPrivateKey
:: Passphrase "encryption"
-> key 'AccountK XPrv
-> AccountingStyle
-> Role
-> Index (AddressIndexDerivationType key) 'AddressK
-> key 'AddressK XPrv

Expand All @@ -466,7 +466,7 @@ class HardDerivation key => SoftDerivation (key :: Depth -> * -> *) where
-- This is the preferred way of deriving new sequential address public keys.
deriveAddressPublicKey
:: key 'AccountK XPub
-> AccountingStyle
-> Role
-> Index 'Soft 'AddressK
-> key 'AddressK XPub

Expand Down

0 comments on commit 848dd00

Please sign in to comment.