@@ -125,6 +125,7 @@ module Cardano.Wallet
125
125
-- ** Delegation
126
126
, PoolRetirementEpochInfo (.. )
127
127
, joinStakePool
128
+ , getStakePoolCoinSelection
128
129
, quitStakePool
129
130
, selectCoinsForDelegation
130
131
, estimateFeeForDelegation
@@ -418,6 +419,7 @@ import Statistics.Quantile
418
419
import Type.Reflection
419
420
( Typeable , typeRep )
420
421
422
+ import qualified Cardano.Api.Typed as Cardano
421
423
import qualified Cardano.Wallet.Primitive.AddressDiscovery.Random as Rnd
422
424
import qualified Cardano.Wallet.Primitive.AddressDiscovery.Sequential as Seq
423
425
import qualified Cardano.Wallet.Primitive.CoinSelection.Random as CoinSelection
@@ -1714,8 +1716,9 @@ signDelegation
1714
1716
-> Passphrase " raw"
1715
1717
-> CoinSelection
1716
1718
-> DelegationAction
1719
+ -> [Cardano. Certificate ]
1717
1720
-> ExceptT ErrSignDelegation IO (Tx , TxMeta , UTCTime , SealedTx )
1718
- signDelegation ctx wid argGenChange pwd coinSel action = db & \ DBLayer {.. } -> do
1721
+ signDelegation ctx wid argGenChange pwd coinSel action certs = db & \ DBLayer {.. } -> do
1719
1722
nodeTip <- withExceptT ErrSignDelegationNetwork $ currentNodeTip nl
1720
1723
withRootKey @ _ @ s ctx wid pwd ErrSignDelegationWithRootKey $ \ xprv scheme -> do
1721
1724
let pwdP = preparePassphrase scheme pwd
@@ -1733,20 +1736,23 @@ signDelegation ctx wid argGenChange pwd coinSel action = db & \DBLayer{..} -> do
1733
1736
case action of
1734
1737
RegisterKeyAndJoin poolId ->
1735
1738
mkDelegationJoinTx tl poolId
1739
+ certs
1736
1740
(rewardAcnt, pwdP)
1737
1741
keyFrom
1738
1742
(nodeTip ^. # slotNo)
1739
1743
coinSel'
1740
1744
1741
1745
Join poolId ->
1742
1746
mkDelegationJoinTx tl poolId
1747
+ certs
1743
1748
(rewardAcnt, pwdP)
1744
1749
keyFrom
1745
1750
(nodeTip ^. # slotNo)
1746
1751
coinSel'
1747
1752
1748
1753
Quit ->
1749
1754
mkDelegationQuitTx tl
1755
+ certs
1750
1756
(rewardAcnt, pwdP)
1751
1757
keyFrom
1752
1758
(nodeTip ^. # slotNo)
@@ -1934,16 +1940,12 @@ getTransaction ctx wid tid = db & \DBLayer{..} -> do
1934
1940
Delegation
1935
1941
-------------------------------------------------------------------------------}
1936
1942
1937
- -- | Helper function to factor necessary logic for joining a stake pool.
1938
- joinStakePool
1943
+ -- | Get the coin selection for joining a stake pool.
1944
+ getStakePoolCoinSelection
1939
1945
:: forall ctx s t k .
1940
1946
( HasDBLayer s k ctx
1941
1947
, HasLogger WalletLog ctx
1942
- , HasNetworkLayer t ctx
1943
1948
, HasTransactionLayer t k ctx
1944
- , IsOwned s k
1945
- , IsOurs s ChimericAccount
1946
- , GenChange s
1947
1949
, HardDerivation k
1948
1950
, AddressIndexDerivationType k ~ 'Soft
1949
1951
, WalletKey k
@@ -1954,10 +1956,9 @@ joinStakePool
1954
1956
-> PoolId
1955
1957
-> PoolLifeCycleStatus
1956
1958
-> WalletId
1957
- -> ArgGenChange s
1958
1959
-> Passphrase " raw"
1959
- -> ExceptT ErrJoinStakePool IO (Tx , TxMeta , UTCTime )
1960
- joinStakePool ctx currentEpoch knownPools pid poolStatus wid argGenChange pwd =
1960
+ -> ExceptT ErrJoinStakePool IO (CoinSelection , [ Cardano. Certificate ], DelegationAction )
1961
+ getStakePoolCoinSelection ctx currentEpoch knownPools pid poolStatus wid pwd =
1961
1962
db & \ DBLayer {.. } -> do
1962
1963
1963
1964
(isKeyReg, walMeta) <- mapExceptT atomically
@@ -1976,21 +1977,62 @@ joinStakePool ctx currentEpoch knownPools pid poolStatus wid argGenChange pwd =
1976
1977
let action = if isKeyReg then Join pid else RegisterKeyAndJoin pid
1977
1978
liftIO $ traceWith tr $ MsgIsStakeKeyRegistered isKeyReg
1978
1979
1979
- selection <- withExceptT ErrJoinStakePoolSelectCoin $
1980
+ cs <- withExceptT ErrJoinStakePoolSelectCoin $
1980
1981
selectCoinsForDelegation @ ctx @ s @ t @ k ctx wid action
1981
1982
1983
+ withRootKey @ _ @ s ctx wid pwd ErrJoinStakePoolRootKey $ \ xprv scheme -> do
1984
+ let pwdP = preparePassphrase scheme pwd
1985
+ let rewardAcnt = getRawKey $ deriveRewardAccount @ k pwdP xprv
1986
+ let certs = (mkDelegationCertificates tl) (W. Join pid)
1987
+ (rewardAcnt, pwdP) cs
1988
+
1989
+ pure (cs, certs, action)
1990
+
1991
+ where
1992
+ tl = ctx ^. transactionLayer @ t @ k
1993
+ db = ctx ^. dbLayer @ s @ k
1994
+ tr = ctx ^. logger
1995
+
1996
+ -- | Helper function to factor necessary logic for joining a stake pool.
1997
+ joinStakePool
1998
+ :: forall ctx s t k .
1999
+ ( HasDBLayer s k ctx
2000
+ , HasLogger WalletLog ctx
2001
+ , HasNetworkLayer t ctx
2002
+ , HasTransactionLayer t k ctx
2003
+ , IsOwned s k
2004
+ , IsOurs s ChimericAccount
2005
+ , GenChange s
2006
+ , HardDerivation k
2007
+ , AddressIndexDerivationType k ~ 'Soft
2008
+ , WalletKey k
2009
+ )
2010
+ => ctx
2011
+ -> W. EpochNo
2012
+ -> Set PoolId
2013
+ -> PoolId
2014
+ -> PoolLifeCycleStatus
2015
+ -> WalletId
2016
+ -> ArgGenChange s
2017
+ -> Passphrase " raw"
2018
+ -> ExceptT ErrJoinStakePool IO (Tx , TxMeta , UTCTime )
2019
+ joinStakePool ctx currentEpoch knownPools pid poolStatus wid argGenChange pwd =
2020
+ db & \ DBLayer {.. } -> do
2021
+ (selection, certs, action) <- getStakePoolCoinSelection @ ctx @ s @ t @ k
2022
+ ctx currentEpoch knownPools pid poolStatus wid pwd
2023
+
1982
2024
(tx, txMeta, txTime, sealedTx) <-
1983
2025
withExceptT ErrJoinStakePoolSignDelegation $
1984
2026
signDelegation
1985
2027
@ ctx @ s @ t @ k ctx wid argGenChange pwd selection action
2028
+ certs
1986
2029
1987
2030
withExceptT ErrJoinStakePoolSubmitTx $
1988
2031
submitTx @ ctx @ s @ t @ k ctx wid (tx, txMeta, sealedTx)
1989
2032
1990
2033
pure (tx, txMeta, txTime)
1991
2034
where
1992
2035
db = ctx ^. dbLayer @ s @ k
1993
- tr = ctx ^. logger
1994
2036
1995
2037
-- | Helper function to factor necessary logic for quitting a stake pool.
1996
2038
quitStakePool
@@ -2024,14 +2066,22 @@ quitStakePool ctx wid argGenChange pwd = db & \DBLayer{..} -> do
2024
2066
selection <- withExceptT ErrQuitStakePoolSelectCoin $
2025
2067
selectCoinsForDelegation @ ctx @ s @ t @ k ctx wid action
2026
2068
2069
+ certs <- withRootKey @ _ @ s ctx wid pwd ErrQuitStakePoolRootKey $ \ xprv scheme -> do
2070
+ let pwdP = preparePassphrase scheme pwd
2071
+ let rewardAcnt = getRawKey $ deriveRewardAccount @ k pwdP xprv
2072
+ pure $ (mkDelegationCertificates tl) W. Quit
2073
+ (rewardAcnt, pwdP) selection
2074
+
2027
2075
(tx, txMeta, txTime, sealedTx) <- withExceptT ErrQuitStakePoolSignDelegation $
2028
2076
signDelegation @ ctx @ s @ t @ k ctx wid argGenChange pwd selection action
2077
+ certs
2029
2078
2030
2079
withExceptT ErrQuitStakePoolSubmitTx $
2031
2080
submitTx @ ctx @ s @ t @ k ctx wid (tx, txMeta, sealedTx)
2032
2081
2033
2082
pure (tx, txMeta, txTime)
2034
2083
where
2084
+ tl = ctx ^. transactionLayer @ t @ k
2035
2085
db = ctx ^. dbLayer @ s @ k
2036
2086
2037
2087
@@ -2309,6 +2359,7 @@ data ErrJoinStakePool
2309
2359
| ErrJoinStakePoolSignDelegation ErrSignDelegation
2310
2360
| ErrJoinStakePoolSubmitTx ErrSubmitTx
2311
2361
| ErrJoinStakePoolCannotJoin ErrCannotJoin
2362
+ | ErrJoinStakePoolRootKey ErrWithRootKey
2312
2363
deriving (Generic , Eq , Show )
2313
2364
2314
2365
data ErrQuitStakePool
@@ -2317,6 +2368,7 @@ data ErrQuitStakePool
2317
2368
| ErrQuitStakePoolSignDelegation ErrSignDelegation
2318
2369
| ErrQuitStakePoolSubmitTx ErrSubmitTx
2319
2370
| ErrQuitStakePoolCannotQuit ErrCannotQuit
2371
+ | ErrQuitStakePoolRootKey ErrWithRootKey
2320
2372
deriving (Generic , Eq , Show )
2321
2373
2322
2374
-- | Errors that can occur when fetching the reward balance of a wallet
0 commit comments