Skip to content

Commit

Permalink
ApiStakePool -> ApiJormungandrStakePool, move SPL to jorm package
Browse files Browse the repository at this point in the history
- Move StakePoolLayer to the jormungandr package

- add missing JSON golden file 'ApiJormungandrStakePool.json'

- Move jorm listPools handler to server module

- re-generate JSON golden file, in hope (commit from Matthias)

Hoping to see the windows unit test timeout disappear
  • Loading branch information
Anviking committed Jun 12, 2020
1 parent 5417c0a commit 9c249fb
Show file tree
Hide file tree
Showing 21 changed files with 465 additions and 167 deletions.
4 changes: 2 additions & 2 deletions lib/byron/src/Cardano/Wallet/Byron/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import Cardano.Wallet.Api.Server
, withLegacyLayer'
)
import Cardano.Wallet.Api.Types
( ApiT (..), SomeByronWalletPostData (..) )
( ApiJormungandrStakePool, ApiT (..), SomeByronWalletPostData (..) )
import Cardano.Wallet.Primitive.AddressDerivation
( PaymentAddress (..) )
import Cardano.Wallet.Primitive.AddressDerivation.Byron
Expand Down Expand Up @@ -161,7 +161,7 @@ server byron icarus ntp =
(\_ -> throwError err501)
:<|> (\_ _ -> throwError err501)

stakePools :: Server (StakePools n)
stakePools :: Server (StakePools n ApiJormungandrStakePool)
stakePools =
throwError err501
:<|> (\_ _ _ -> throwError err501)
Expand Down
6 changes: 4 additions & 2 deletions lib/cli/src/Cardano/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,8 @@ cmdVersion = command "version" $ info cmd $ mempty
-------------------------------------------------------------------------------}

cmdStakePool
:: StakePoolClient
:: ToJSON apiPool
=> StakePoolClient apiPool
-> Mod CommandFields (IO ())
cmdStakePool mkClient =
command "stake-pool" $ info (helper <*> cmds) $ mempty
Expand All @@ -1510,7 +1511,8 @@ newtype StakePoolListArgs = StakePoolListArgs
}

cmdStakePoolList
:: StakePoolClient
:: ToJSON apiPool
=> StakePoolClient apiPool
-> Mod CommandFields (IO ())
cmdStakePoolList mkClient =
command "list" $ info (helper <*> cmd) $ mempty
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/test/unit/Cardano/CLISpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ parser = cli $ mempty
<> cmdWallet cmdWalletCreate walletClient
<> cmdTransaction transactionClient walletClient
<> cmdAddress addressClient
<> cmdStakePool stakePoolClient
<> cmdStakePool (stakePoolClient @()) -- Type of pool not important here.
<> cmdNetwork networkClient
<> cmdKey

Expand Down
1 change: 0 additions & 1 deletion lib/core/cardano-wallet-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ library
Cardano.Byron.Codec.Cbor
Cardano.DB.Sqlite
Cardano.DB.Sqlite.Delete
Cardano.Pool
Cardano.Pool.Metadata
Cardano.Pool.DB
Cardano.Pool.DB.MVar
Expand Down
28 changes: 0 additions & 28 deletions lib/core/src/Cardano/Pool.hs

This file was deleted.

15 changes: 9 additions & 6 deletions lib/core/src/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ import Cardano.Wallet.Api.Types
, ApiByronWallet
, ApiCoinSelectionT
, ApiFee
, ApiJormungandrStakePool
, ApiNetworkClock
, ApiNetworkInformation
, ApiNetworkParameters
, ApiPoolId
, ApiPostRandomAddressData
, ApiSelectCoinsDataT
, ApiStakePool
, ApiT
, ApiTransactionT
, ApiTxId
Expand Down Expand Up @@ -183,13 +183,16 @@ import Servant.API.Verbs

type ApiV2 n = "v2" :> Api n

-- | The full cardano-wallet API.
--
-- The API used in cardano-wallet-jormungandr may differ from this one.
type Api n =
Wallets
:<|> Addresses n
:<|> CoinSelections n
:<|> Transactions n
:<|> ShelleyMigrations n
:<|> StakePools n
:<|> StakePools n ApiJormungandrStakePool -- TODO: Make haskell specific
:<|> ByronWallets
:<|> ByronAddresses n
:<|> ByronCoinSelections n
Expand Down Expand Up @@ -358,15 +361,15 @@ type GetShelleyWalletMigrationInfo = "wallets"
See also: https://input-output-hk.github.io/cardano-wallet/api/edge/#tag/Stake-Pools
-------------------------------------------------------------------------------}

type StakePools n =
ListStakePools
type StakePools n apiPool =
ListStakePools apiPool
:<|> JoinStakePool n
:<|> QuitStakePool n
:<|> DelegationFee

-- | https://input-output-hk.github.io/cardano-wallet/api/edge/#operation/listStakePools
type ListStakePools = "stake-pools"
:> Get '[JSON] [ApiStakePool]
type ListStakePools apiPool = "stake-pools"
:> Get '[JSON] [apiPool]

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/joinStakePool
type JoinStakePool n = "stake-pools"
Expand Down
9 changes: 4 additions & 5 deletions lib/core/src/Cardano/Wallet/Api/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import Cardano.Wallet.Api.Types
, ApiPoolId
, ApiPostRandomAddressData
, ApiSelectCoinsDataT
, ApiStakePool
, ApiT (..)
, ApiTransactionT
, ApiTxId (..)
Expand Down Expand Up @@ -174,9 +173,9 @@ data AddressClient = AddressClient
-> ClientM NoContent
}

data StakePoolClient = StakePoolClient
data StakePoolClient apiPool = StakePoolClient
{ listPools
:: ClientM [ApiStakePool]
:: ClientM [apiPool]
, joinStakePool
:: ApiPoolId
-> ApiT WalletId
Expand Down Expand Up @@ -326,14 +325,14 @@ byronAddressClient =

-- | Produces an 'StakePoolsClient n' working against the /stake-pools API
stakePoolClient
:: StakePoolClient
:: forall apiPool. (Aeson.FromJSON apiPool) => StakePoolClient apiPool
stakePoolClient =
let
_listPools
:<|> _joinStakePool
:<|> _quitStakePool
:<|> _delegationFee
= client (Proxy @("v2" :> StakePools Aeson.Value))
= client (Proxy @("v2" :> StakePools Aeson.Value apiPool))
in
StakePoolClient
{ listPools = _listPools
Expand Down
10 changes: 4 additions & 6 deletions lib/core/src/Cardano/Wallet/Api/Link.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ module Cardano.Wallet.Api.Link

import Prelude

import Cardano.Wallet.Api
( Api )
import Cardano.Wallet.Api.Types
( ApiPoolId (..)
, ApiT (..)
Expand Down Expand Up @@ -383,7 +381,7 @@ deleteTransaction w t = discriminate @style
listStakePools
:: (Method, Text)
listStakePools =
endpoint @Api.ListStakePools id
endpoint @(Api.ListStakePools ()) id

joinStakePool
:: forall s w.
Expand Down Expand Up @@ -491,15 +489,15 @@ postExternalTransaction =
-- ( "GET", "v2/wallets/2512a00e9653fe49a44a5886202e24d77eeb998f" )
endpoint
:: forall endpoint.
( IsElem endpoint (Api Net)
, HasLink endpoint
( HasLink endpoint
, IsElem endpoint endpoint
, HasVerb endpoint
)
=> (MkLink endpoint Text -> Text)
-> (Method, Text)
endpoint mk =
( method (Proxy @endpoint)
, "v2/" <> mk (safeLink' toUrlPiece (Proxy @(Api Net)) (Proxy @endpoint))
, "v2/" <> mk (safeLink' toUrlPiece (Proxy @endpoint) (Proxy @endpoint))
)

-- Returns first argument for Shelley style wallet, second argument otherwise.
Expand Down
46 changes: 6 additions & 40 deletions lib/core/src/Cardano/Wallet/Api/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ module Cardano.Wallet.Api.Server
, getWallet
, joinStakePool
, listAddresses
, listPools
, listTransactions
, listWallets
, migrateWallet
Expand Down Expand Up @@ -90,8 +89,6 @@ import Cardano.Address.Derivation
( XPrv, XPub )
import Cardano.Mnemonic
( SomeMnemonic )
import Cardano.Pool
( StakePoolLayer (..) )
import Cardano.Wallet
( ErrAdjustForFee (..)
, ErrCannotJoin (..)
Expand Down Expand Up @@ -160,8 +157,6 @@ import Cardano.Wallet.Api.Types
, ApiPoolId (..)
, ApiPostRandomAddressData (..)
, ApiSelectCoinsData (..)
, ApiStakePool (..)
, ApiStakePoolMetrics (..)
, ApiT (..)
, ApiTimeReference (..)
, ApiTransaction (..)
Expand Down Expand Up @@ -247,8 +242,6 @@ import Cardano.Wallet.Primitive.Types
, PassphraseScheme (..)
, PoolId
, SortOrder (..)
, StakePool (..)
, StakePoolMetadata
, SyncProgress
, SyncTolerance
, TransactionInfo (TransactionInfo)
Expand Down Expand Up @@ -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
Expand All @@ -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)@
-> 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
Expand Down
8 changes: 4 additions & 4 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module Cardano.Wallet.Api.Types
, ApiSelectCoinsData (..)
, ApiCoinSelection (..)
, ApiCoinSelectionInput (..)
, ApiStakePool (..)
, ApiJormungandrStakePool (..)
, ApiStakePoolMetrics (..)
, ApiWallet (..)
, ApiWalletPassphrase (..)
Expand Down Expand Up @@ -391,7 +391,7 @@ newtype ApiWalletPassphrase = ApiWalletPassphrase
{ passphrase :: ApiT (Passphrase "lenient")
} deriving (Eq, Generic, Show)

data ApiStakePool = ApiStakePool
data ApiJormungandrStakePool = ApiJormungandrStakePool
{ id :: !(ApiT PoolId)
, metrics :: !ApiStakePoolMetrics
, apparentPerformance :: !Double
Expand Down Expand Up @@ -1056,9 +1056,9 @@ instance FromJSON ApiWalletDelegationNext where
instance ToJSON ApiWalletDelegationNext where
toJSON = genericToJSON defaultRecordTypeOptions

instance FromJSON ApiStakePool where
instance FromJSON ApiJormungandrStakePool where
parseJSON = genericParseJSON defaultRecordTypeOptions
instance ToJSON ApiStakePool where
instance ToJSON ApiJormungandrStakePool where
toJSON = genericToJSON defaultRecordTypeOptions

instance FromJSON ApiStakePoolMetrics where
Expand Down
Loading

0 comments on commit 9c249fb

Please sign in to comment.