-
Notifications
You must be signed in to change notification settings - Fork 217
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
Parameterise StakePools
API over apiPool type
#1738
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,6 @@ module Cardano.Wallet.Api.Server | |
, getWallet | ||
, joinStakePool | ||
, listAddresses | ||
, listPools | ||
, listTransactions | ||
, listWallets | ||
, migrateWallet | ||
|
@@ -90,8 +89,6 @@ import Cardano.Address.Derivation | |
( XPrv, XPub ) | ||
import Cardano.Mnemonic | ||
( SomeMnemonic ) | ||
import Cardano.Pool | ||
( StakePoolLayer (..) ) | ||
import Cardano.Wallet | ||
( ErrAdjustForFee (..) | ||
, ErrCannotJoin (..) | ||
|
@@ -160,8 +157,6 @@ import Cardano.Wallet.Api.Types | |
, ApiPoolId (..) | ||
, ApiPostRandomAddressData (..) | ||
, ApiSelectCoinsData (..) | ||
, ApiStakePool (..) | ||
, ApiStakePoolMetrics (..) | ||
, ApiT (..) | ||
, ApiTimeReference (..) | ||
, ApiTransaction (..) | ||
|
@@ -247,8 +242,6 @@ import Cardano.Wallet.Primitive.Types | |
, PassphraseScheme (..) | ||
, PoolId | ||
, SortOrder (..) | ||
, StakePool (..) | ||
, StakePoolMetadata | ||
, SyncProgress | ||
, SyncTolerance | ||
, TransactionInfo (TransactionInfo) | ||
|
@@ -1196,37 +1189,8 @@ postTransactionFee ctx (ApiT wid) body = do | |
|
||
e -> throwE e | ||
|
||
|
||
{------------------------------------------------------------------------------- | ||
Stake Pools | ||
-------------------------------------------------------------------------------} | ||
|
||
listPools | ||
:: LiftHandler e | ||
=> StakePoolLayer e IO | ||
-> Handler [ApiStakePool] | ||
listPools spl = | ||
liftHandler $ map (uncurry mkApiStakePool) <$> listStakePools spl | ||
where | ||
mkApiStakePool | ||
:: StakePool | ||
-> Maybe StakePoolMetadata | ||
-> ApiStakePool | ||
mkApiStakePool sp meta = | ||
ApiStakePool | ||
(ApiT $ poolId sp) | ||
(ApiStakePoolMetrics | ||
(Quantity $ fromIntegral $ getQuantity $ stake sp) | ||
(Quantity $ fromIntegral $ getQuantity $ production sp)) | ||
(sp ^. #performance) | ||
(ApiT <$> meta) | ||
(fromIntegral <$> sp ^. #cost) | ||
(Quantity $ sp ^. #margin) | ||
(sp ^. #desirability) | ||
(sp ^. #saturation) | ||
|
||
joinStakePool | ||
:: forall ctx s t n k e. | ||
:: forall ctx s t n k. | ||
( DelegationAddress n k | ||
, s ~ SeqState n k | ||
, IsOwned s k | ||
|
@@ -1236,19 +1200,21 @@ joinStakePool | |
, ctx ~ ApiLayer s t k | ||
) | ||
=> ctx | ||
-> StakePoolLayer e IO | ||
-> IO [PoolId] | ||
-- ^ Known pools | ||
-- We could maybe replace this with a @IO (PoolId -> Bool)@ | ||
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. No need to have a common We just need to make sure the target packages can provide a |
||
-> ApiPoolId | ||
-> ApiT WalletId | ||
-> ApiWalletPassphrase | ||
-> Handler (ApiTransaction n) | ||
joinStakePool ctx spl apiPoolId (ApiT wid) body = do | ||
joinStakePool ctx knownPools apiPoolId (ApiT wid) body = do | ||
let pwd = coerce $ getApiT $ body ^. #passphrase | ||
|
||
pid <- case apiPoolId of | ||
ApiPoolIdPlaceholder -> liftE ErrUnexpectedPoolIdPlaceholder | ||
ApiPoolId pid -> pure pid | ||
|
||
pools <- liftIO $ knownStakePools spl | ||
pools <- liftIO knownPools | ||
|
||
(tx, txMeta, txTime) <- withWorkerCtx ctx wid liftE liftE $ \wrk -> liftHandler $ | ||
W.joinStakePool @_ @s @t @k wrk wid (pid, pools) (delegationAddress @n) pwd | ||
|
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.
I assume this one can be fully moved to each target package, alongside the server instantiation.
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.
No! Sadly not easily, because we have a swagger spec in core!
My plan is to keep this type, but let jormungandr use a custom
Api
type.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.
Hmmm. Well no, we can also declare an "Api" type in the relevant test.
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.
That might make our test meaningless since if it is no longer testing the
Api
type that is actually used.I say we keep the haskell API in
core
as the most important api, and test it, but not the jormungandr one.…or, we define and test both APIs in core 🤔
…or, maybe one could do something with a
ApiStakePool | ApiJormungandrStakePool
sum type 🤔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.
Can sort out later.
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.
Yeah, I thought of it. Since the stake pools are only something the server produces, it might just be okay to go down that path and fairly transparent for clients.