Skip to content

Commit

Permalink
unify gcPoolStatus and maintenance action for a cleaner API
Browse files Browse the repository at this point in the history
  It was a bit awkward to have two completely distinct endpoints for
  this with different paths, whereas they related to exactly the same
  thing. This commit makes the API a bit more consistent by wrapping the
  `gcPoolStatus` inside a `maintenance action` object. So that, the API
  now offers two dual endpoints:

  - post maintenance action
  - get maintenance action

  There's only one maintenance action available at this stage.
  • Loading branch information
KtorZ committed Nov 10, 2020
1 parent 105ec6a commit 6489807
Show file tree
Hide file tree
Showing 11 changed files with 574 additions and 221 deletions.
30 changes: 16 additions & 14 deletions lib/core/src/Cardano/Wallet/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,20 @@ module Cardano.Wallet.Api

, StakePools
, ListStakePools
, MetadataGCStatus
, JoinStakePool
, QuitStakePool
, DelegationFee
, PostPoolMaintenance
, GetPoolMaintenance

, ShelleyMigrations
, MigrateShelleyWallet
, GetShelleyWalletMigrationInfo

-- * Settings
, Settings
, PutSettings
, GetSettings
, PutSettings
, GetSettings

-- * Byron
, ByronWallets
Expand Down Expand Up @@ -126,6 +127,7 @@ import Cardano.Wallet.Api.Types
, ApiCoinSelectionT
, ApiFee
, ApiMaintenanceAction
, ApiMaintenanceActionPostData
, ApiNetworkClock
, ApiNetworkInformation
, ApiNetworkParameters
Expand Down Expand Up @@ -168,7 +170,6 @@ import Cardano.Wallet.Primitive.Types
, Block
, Coin (..)
, NetworkParameters
, PoolMetadataGCStatus (..)
, SortOrder (..)
, WalletId (..)
)
Expand Down Expand Up @@ -205,7 +206,6 @@ import Servant.API.Verbs
, Post
, PostAccepted
, PostCreated
, PostNoContent
, Put
, PutAccepted
, PutNoContent
Expand Down Expand Up @@ -447,18 +447,14 @@ type StakePools n apiPool =
:<|> JoinStakePool n
:<|> QuitStakePool n
:<|> DelegationFee
:<|> PoolMaintenance
:<|> MetadataGCStatus
:<|> PostPoolMaintenance
:<|> GetPoolMaintenance

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

type MetadataGCStatus = "stake-pools"
:> "metadata-gc-status"
:> Get '[JSON] (ApiT PoolMetadataGCStatus)

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/joinStakePool
type JoinStakePool n = "stake-pools"
:> Capture "stakePoolId" ApiPoolId
Expand All @@ -481,10 +477,16 @@ type DelegationFee = "wallets"
:> "delegation-fees"
:> Get '[JSON] ApiFee

type PoolMaintenance = "stake-pools"
-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/postPoolMaintenance
type PostPoolMaintenance = "stake-pools"
:> "maintenance-actions"
:> ReqBody '[JSON] ApiMaintenanceActionPostData
:> Post '[JSON] ApiMaintenanceAction

-- | https://input-output-hk.github.io/cardano-wallet/api/#operation/getPoolMaintenance
type GetPoolMaintenance = "stake-pools"
:> "maintenance-actions"
:> ReqBody '[JSON] ApiMaintenanceAction
:> PostNoContent
:> Get '[JSON] ApiMaintenanceAction

{-------------------------------------------------------------------------------
Settings
Expand Down
2 changes: 2 additions & 0 deletions lib/core/src/Cardano/Wallet/Api/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ stakePoolClient =
:<|> _joinStakePool
:<|> _quitStakePool
:<|> _delegationFee
:<|> _postPoolMaintenance
:<|> _getPoolMaintenance
= client (Proxy @("v2" :> StakePools Aeson.Value apiPool))
in
StakePoolClient
Expand Down
25 changes: 23 additions & 2 deletions lib/core/src/Cardano/Wallet/Api/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module Cardano.Wallet.Api.Types
, ApiCoinSelectionOutput (..)
, ApiStakePool (..)
, ApiStakePoolMetrics (..)
, ApiStakePoolFlag (..)
, ApiWallet (..)
, ApiWalletPassphrase (..)
, ApiWalletPassphraseInfo (..)
Expand All @@ -77,6 +78,7 @@ module Cardano.Wallet.Api.Types
, ApiTransaction (..)
, ApiWithdrawalPostData (..)
, ApiMaintenanceAction (..)
, ApiMaintenanceActionPostData (..)
, MaintenanceAction (..)
, ApiFee (..)
, ApiTxId (..)
Expand Down Expand Up @@ -410,10 +412,14 @@ fmtAllowedWords =
data MaintenanceAction = GcStakePools
deriving (Eq, Generic, Show)

newtype ApiMaintenanceAction = ApiMaintenanceAction
newtype ApiMaintenanceActionPostData = ApiMaintenanceActionPostData
{ maintenanceAction :: MaintenanceAction
} deriving (Eq, Generic, Show)

newtype ApiMaintenanceAction = ApiMaintenanceAction
{ gcStakePools :: ApiT PoolMetadataGCStatus
} deriving (Eq, Generic, Show)

data ApiAddress (n :: NetworkDiscriminant) = ApiAddress
{ id :: !(ApiT Address, Proxy n)
, state :: !(ApiT AddressState)
Expand Down Expand Up @@ -555,9 +561,14 @@ data ApiStakePool = ApiStakePool
, margin :: !(Quantity "percent" Percentage)
, pledge :: !(Quantity "lovelace" Natural)
, retirement :: !(Maybe ApiEpochInfo)
, delisted :: !Bool
, flags :: ![ApiStakePoolFlag]
} deriving (Eq, Generic, Show)

data ApiStakePoolFlag
= Delisted
deriving stock (Eq, Generic, Show)
deriving anyclass NFData

data ApiStakePoolMetrics = ApiStakePoolMetrics
{ nonMyopicMemberRewards :: !(Quantity "lovelace" Natural)
, relativeStake :: !(Quantity "percent" Percentage)
Expand Down Expand Up @@ -1430,6 +1441,11 @@ instance FromJSON ByronWalletPutPassphraseData where
instance ToJSON ByronWalletPutPassphraseData where
toJSON = genericToJSON defaultRecordTypeOptions

instance FromJSON ApiMaintenanceActionPostData where
parseJSON = genericParseJSON defaultRecordTypeOptions
instance ToJSON ApiMaintenanceActionPostData where
toJSON = genericToJSON defaultRecordTypeOptions

instance FromJSON ApiMaintenanceAction where
parseJSON = genericParseJSON defaultRecordTypeOptions
instance ToJSON ApiMaintenanceAction where
Expand Down Expand Up @@ -1600,6 +1616,11 @@ instance FromJSON ApiStakePoolMetrics where
instance ToJSON ApiStakePoolMetrics where
toJSON = genericToJSON defaultRecordTypeOptions

instance FromJSON ApiStakePoolFlag where
parseJSON = genericParseJSON defaultSumTypeOptions
instance ToJSON ApiStakePoolFlag where
toJSON = genericToJSON defaultSumTypeOptions

instance FromJSON (ApiT WalletName) where
parseJSON = parseJSON >=> eitherToParser . bimap ShowFmt ApiT . fromText
instance ToJSON (ApiT WalletName) where
Expand Down
61 changes: 61 additions & 0 deletions lib/core/test/data/Cardano/Wallet/Api/ApiMaintenanceAction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"seed": -9096659285789418454,
"samples": [
{
"gc_stake_pools": {
"status": "has_run",
"last_run": "1887-02-07T15:59:58Z"
}
},
{
"gc_stake_pools": {
"status": "restarting",
"last_run": "1895-01-25T13:15:15Z"
}
},
{
"gc_stake_pools": {
"status": "restarting",
"last_run": "1873-08-31T03:33:04Z"
}
},
{
"gc_stake_pools": {
"status": "not_started"
}
},
{
"gc_stake_pools": {
"status": "not_started"
}
},
{
"gc_stake_pools": {
"status": "restarting",
"last_run": "1864-06-09T06:48:03.138827934098Z"
}
},
{
"gc_stake_pools": {
"status": "not_started"
}
},
{
"gc_stake_pools": {
"status": "has_run",
"last_run": "1901-11-24T13:54:25Z"
}
},
{
"gc_stake_pools": {
"status": "has_run",
"last_run": "1896-02-25T15:16:00Z"
}
},
{
"gc_stake_pools": {
"status": "not_applicable"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"seed": -940073206050741807,
"samples": [
{
"maintenance_action": "gc_stake_pools"
},
{
"maintenance_action": "gc_stake_pools"
},
{
"maintenance_action": "gc_stake_pools"
},
{
"maintenance_action": "gc_stake_pools"
},
{
"maintenance_action": "gc_stake_pools"
},
{
"maintenance_action": "gc_stake_pools"
},
{
"maintenance_action": "gc_stake_pools"
},
{
"maintenance_action": "gc_stake_pools"
},
{
"maintenance_action": "gc_stake_pools"
},
{
"maintenance_action": "gc_stake_pools"
}
]
}
Loading

0 comments on commit 6489807

Please sign in to comment.