Skip to content

Commit

Permalink
Merge pull request #332 from Concordium/grpc-extensions
Browse files Browse the repository at this point in the history
Support new GRPC endpoints
  • Loading branch information
td202 authored Dec 3, 2024
2 parents d33ccdf + b91aa0f commit 231ae66
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 37 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

## Unreleased

Note: due to API changes, this release may not work correctly with node versions prior to 8.

- Support node version 8 and protocol version 8.
- Support for suspend/resume in validator update transactions.
- Add command `consensus detailed-status` for getting detailed consensus status (from protocol
version 6).
- Add `raw GetConsensusDetailedStatus` that presents the detailed consensus status as JSON.
- Update GHC version to 9.6.6 (lts-22.39).
- Add raw commands `GetScheduledReleaseAccounts`, `GetCooldownAccounts`,
`GetPreCooldownAccounts` and `GetPrePreCooldownAccounts` for querying
accounts with scheduled releases, cooldowns, pre-cooldowns and pre-pre-cooldowns.
- Raw commands `GetBlockTransactionEvents` and `GetTransactionStatus` include the `parameter`
for `ContractInitialized` events.

## 7.0.1

Expand Down
4 changes: 2 additions & 2 deletions concordium-client.cabal
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cabal-version: 1.24

-- This file has been generated from package.yaml by hpack version 0.36.0.
-- This file has been generated from package.yaml by hpack version 0.37.0.
--
-- see: https://github.com/sol/hpack

name: concordium-client
version: 7.0.1
version: 7.0.2
description: Please see the README on GitHub at <https://github.com/Concordium/concordium-client#readme>
homepage: https://github.com/Concordium/concordium-client#readme
bug-reports: https://github.com/Concordium/concordium-client/issues
Expand Down
54 changes: 45 additions & 9 deletions src/Concordium/Client/GRPC2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ instance FromProto Proto.ContractVersion where
fromProtoFail "Unable to convert 'ContractVersion'."

instance FromProto Proto.ContractTraceElement where
type Output Proto.ContractTraceElement = Event
type Output Proto.ContractTraceElement = SupplementedEvent
fromProto ctElement = do
cte <- case ctElement ^. Proto.maybe'element of
Nothing ->
Expand Down Expand Up @@ -1506,7 +1506,7 @@ instance FromProto Proto.TransactionType where
<> "'."

instance FromProto Proto.AccountCreationDetails where
type Output Proto.AccountCreationDetails = ValidResult
type Output Proto.AccountCreationDetails = SupplementedValidResult
fromProto acDetails = do
ecdAccount <- fromProto $ acDetails ^. ProtoFields.address
ecdRegId <- fmap fst . fromProto $ acDetails ^. ProtoFields.regId
Expand Down Expand Up @@ -1980,7 +1980,7 @@ instance FromProto Proto.UpdatePayload where
return $ Updates.FinalizationCommitteeParametersUpdatePayload fcp

instance FromProto Proto.BlockItemSummary where
type Output Proto.BlockItemSummary = TransactionSummary
type Output Proto.BlockItemSummary = SupplementedTransactionSummary
fromProto biSummary = do
-- Common block item summary fields
let tsIndex = deMkWord64 $ biSummary ^. ProtoFields.index
Expand Down Expand Up @@ -2021,7 +2021,7 @@ instance FromProto Proto.BlockItemSummary where
return TransactionSummary{..}

instance FromProto Proto.AccountTransactionDetails where
type Output Proto.AccountTransactionDetails = (Maybe TransactionType, ValidResult)
type Output Proto.AccountTransactionDetails = (Maybe TransactionType, SupplementedValidResult)
fromProto atDetails = do
let senderAcc = atDetails ^. ProtoFields.sender
sender <- fromProto senderAcc
Expand Down Expand Up @@ -2080,6 +2080,7 @@ instance FromProto Proto.AccountTransactionDetails where
ecAmount <- fromProto $ cInitialized ^. ProtoFields.amount
ecInitName <- fromProto $ cInitialized ^. ProtoFields.initName
ecEvents <- mapM fromProto $ cInitialized ^. ProtoFields.events
ecParameter <- fmap Parameters.CTrue . fromProto $ cInitialized ^. ProtoFields.parameter
return (Just TTInitContract, TxSuccess [ContractInitialized{..}])
ProtoFields.AccountTransactionEffects'ContractUpdateIssued' cuIssued -> do
vrEvents <- mapM fromProto $ cuIssued ^. ProtoFields.effects
Expand Down Expand Up @@ -2165,7 +2166,7 @@ instance FromProto Proto.AccountTransactionDetails where
return (Just tType, TxSuccess{..})

instance FromProto (Proto.AccountAddress, Proto.DelegationEvent) where
type Output (Proto.AccountAddress, Proto.DelegationEvent) = Event
type Output (Proto.AccountAddress, Proto.DelegationEvent) = SupplementedEvent
fromProto (senderAcc, dEvent) = do
sender <- fromProto senderAcc
de <- case dEvent ^. Proto.maybe'event of
Expand Down Expand Up @@ -2208,7 +2209,7 @@ instance FromProto (Proto.AccountAddress, Proto.DelegationEvent) where
return BakerRemoved{..}

instance FromProto (Proto.AccountAddress, Proto.BakerEvent) where
type Output (Proto.AccountAddress, Proto.BakerEvent) = Event
type Output (Proto.AccountAddress, Proto.BakerEvent) = SupplementedEvent
fromProto (senderAcc, bEvent) = do
sender <- fromProto senderAcc
be <- case bEvent ^. Proto.maybe'event of
Expand Down Expand Up @@ -2280,7 +2281,7 @@ instance FromProto (Proto.AccountAddress, Proto.BakerEvent) where
return BakerResumed{..}

instance FromProto Proto.BlockItemStatus where
type Output Proto.BlockItemStatus = TransactionStatus
type Output Proto.BlockItemStatus = SupplementedTransactionStatus
fromProto biStatus = do
bis <- case biStatus ^. Proto.maybe'status of
Nothing ->
Expand Down Expand Up @@ -3064,6 +3065,13 @@ instance FromProto Proto.ConsensusDetailedStatus where
cdsTerminalBlock <- mapM fromProto (consensusDetailedStatus ^. ProtoFields.maybe'terminalBlock)
return ConsensusDetailedStatus{..}

instance FromProto Proto.AccountPending where
type Output Proto.AccountPending = AccountPending
fromProto acctPending = do
apAccountIndex <- fromProto (acctPending ^. ProtoFields.accountIndex)
apFirstTimestamp <- fromProto (acctPending ^. ProtoFields.firstTimestamp)
return AccountPending{..}

type LoggerMethod = Text -> IO ()

data GrpcConfig = GrpcConfig
Expand Down Expand Up @@ -3181,7 +3189,7 @@ getBlockSpecialEvents bhInput =
msg = toProto bhInput

-- | Get all transaction events in a given block.
getBlockTransactionEvents :: (MonadIO m) => BlockHashInput -> ClientMonad m (GRPCResult (FromProtoResult (Seq.Seq TransactionSummary)))
getBlockTransactionEvents :: (MonadIO m) => BlockHashInput -> ClientMonad m (GRPCResult (FromProtoResult (Seq.Seq SupplementedTransactionSummary)))
getBlockTransactionEvents bhInput =
withServerStreamCollect (call @"getBlockTransactionEvents") msg ((fmap . mapM) fromProto)
where
Expand Down Expand Up @@ -3361,7 +3369,7 @@ getBlockFinalizationSummary bhInput = withUnary (call @"getBlockFinalizationSumm
msg = toProto bhInput

-- | Get the status of and information about a specific block item (transaction).
getBlockItemStatus :: (MonadIO m) => TransactionHash -> ClientMonad m (GRPCResult (FromProtoResult TransactionStatus))
getBlockItemStatus :: (MonadIO m) => TransactionHash -> ClientMonad m (GRPCResult (FromProtoResult SupplementedTransactionStatus))
getBlockItemStatus tHash = withUnary (call @"getBlockItemStatus") msg (fmap fromProto)
where
msg = toProto tHash
Expand Down Expand Up @@ -3455,6 +3463,34 @@ getNextUpdateSequenceNumbers bhInput = withUnary (call @"getNextUpdateSequenceNu
where
msg = toProto bhInput

-- | Get all accounts that have scheduled releases.
getScheduledReleaseAccounts :: (MonadIO m) => BlockHashInput -> ClientMonad m (GRPCResult (FromProtoResult (Seq.Seq AccountPending)))
getScheduledReleaseAccounts bhInput =
withServerStreamCollect (call @"getScheduledReleaseAccounts") msg (fmap (mapM fromProto))
where
msg = toProto bhInput

-- | Get all accounts that have stake in cooldown.
getCooldownAccounts :: (MonadIO m) => BlockHashInput -> ClientMonad m (GRPCResult (FromProtoResult (Seq.Seq AccountPending)))
getCooldownAccounts bhInput =
withServerStreamCollect (call @"getCooldownAccounts") msg (fmap (mapM fromProto))
where
msg = toProto bhInput

-- | Get all accounts that have stake in pre-cooldown.
getPreCooldownAccounts :: (MonadIO m) => BlockHashInput -> ClientMonad m (GRPCResult (FromProtoResult (Seq.Seq AccountIndex)))
getPreCooldownAccounts bhInput =
withServerStreamCollect (call @"getPreCooldownAccounts") msg (fmap (mapM fromProto))
where
msg = toProto bhInput

-- | Get all accounts that have stake in pre-pre-cooldown.
getPrePreCooldownAccounts :: (MonadIO m) => BlockHashInput -> ClientMonad m (GRPCResult (FromProtoResult (Seq.Seq AccountIndex)))
getPrePreCooldownAccounts bhInput =
withServerStreamCollect (call @"getPrePreCooldownAccounts") msg (fmap (mapM fromProto))
where
msg = toProto bhInput

-- | Get information related to the baker election for a particular block.
getElectionInfo :: (MonadIO m) => BlockHashInput -> ClientMonad m (GRPCResult (FromProtoResult BlockBirkParameters))
getElectionInfo bhInput = withUnary (call @"getElectionInfo") msg (fmap fromProto)
Expand Down
60 changes: 60 additions & 0 deletions src/Concordium/Client/LegacyCommands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ data LegacyCmd
{legacyEpoch :: !EpochSpecifier}
| GetFirstBlockEpoch
{legacyEpoch :: !EpochSpecifier}
| -- | Get the list of accounts with scheduled releases.
GetScheduledReleaseAccounts
{legacyBlockHash :: !(Maybe Text)}
| -- | Get the list of accounts with stake in cooldown.
GetCooldownAccounts
{legacyBlockHash :: !(Maybe Text)}
| -- | Get the list of accounts with stake in pre-cooldown.
GetPreCooldownAccounts
{legacyBlockHash :: !(Maybe Text)}
| -- | Get the list of accounts with stake in pre-pre-cooldown.
GetPrePreCooldownAccounts
{legacyBlockHash :: !(Maybe Text)}
deriving (Show)

legacyProgramOptions :: Parser LegacyCmd
Expand Down Expand Up @@ -213,6 +225,10 @@ legacyProgramOptions =
<> getAnonymityRevokersCommand
<> getCryptographicParametersCommand
<> getNextUpdateSequenceNumbersCommand
<> getScheduledReleaseAccountsCommand
<> getCooldownAccountsCommand
<> getPreCooldownAccountsCommand
<> getPrePreCooldownAccountsCommand
<> getBakersRewardPeriodCommand "GetValidatorsRewardPeriod"
<> getBlockCertificatesCommand
<> getBakerEarliestWinTimeCommand "GetValidatorEarliestWinTime"
Expand Down Expand Up @@ -426,6 +442,50 @@ getNextUpdateSequenceNumbersCommand =
(progDesc "Query the gRPC server for the next update sequence numbers for all update queues.")
)

getScheduledReleaseAccountsCommand :: Mod CommandFields LegacyCmd
getScheduledReleaseAccountsCommand =
command
"GetScheduledReleaseAccounts"
( info
( GetScheduledReleaseAccounts
<$> optional (strArgument (metavar "BLOCK-HASH" <> help "Hash of the block to query (default: Query the best block)"))
)
(progDesc "Query the gRPC server for all accounts that have scheduled releases, with the timestamp of the first pending scheduled release for that account.")
)

getCooldownAccountsCommand :: Mod CommandFields LegacyCmd
getCooldownAccountsCommand =
command
"GetCooldownAccounts"
( info
( GetCooldownAccounts
<$> optional (strArgument (metavar "BLOCK-HASH" <> help "Hash of the block to query (default: Query the best block)"))
)
(progDesc "Query the gRPC server for all accounts that have stake in cooldown, with the timestamp of the first pending cooldown expiry for each account.")
)

getPreCooldownAccountsCommand :: Mod CommandFields LegacyCmd
getPreCooldownAccountsCommand =
command
"GetPreCooldownAccounts"
( info
( GetPreCooldownAccounts
<$> optional (strArgument (metavar "BLOCK-HASH" <> help "Hash of the block to query (default: Query the best block)"))
)
(progDesc "Query the gRPC server for all accounts that have stake in pre-cooldown.")
)

getPrePreCooldownAccountsCommand :: Mod CommandFields LegacyCmd
getPrePreCooldownAccountsCommand =
command
"GetPrePreCooldownAccounts"
( info
( GetPrePreCooldownAccounts
<$> optional (strArgument (metavar "BLOCK-HASH" <> help "Hash of the block to query (default: Query the best block)"))
)
(progDesc "Query the gRPC server for all accounts that have stake in pre-pre-cooldown.")
)

getBakersRewardPeriodCommand :: String -> Mod CommandFields LegacyCmd
getBakersRewardPeriodCommand name =
command
Expand Down
24 changes: 12 additions & 12 deletions src/Concordium/Client/Output.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Codec.CBOR.Read
import qualified Concordium.Client.Types.ConsensusStatus as ConsensusStatus
import Concordium.Client.Types.Contract.BuildInfo (showBuildInfo)
import Concordium.Common.Time (DurationSeconds (durationSeconds))
import Concordium.Types.Execution (Event (ecEvents))
import Concordium.Types.Execution (Event' (ecEvents), SupplementedEvent)
import Control.Monad
import Control.Monad.Writer
import qualified Data.Aeson as AE
Expand Down Expand Up @@ -609,9 +609,9 @@ showAccountKeyPair = showPrettyJSON

data TransactionBlockResult
= NoBlocks
| SingleBlock Types.BlockHash Types.TransactionSummary
| MultipleBlocksUnambiguous [Types.BlockHash] Types.TransactionSummary
| MultipleBlocksAmbiguous [(Types.BlockHash, Types.TransactionSummary)]
| SingleBlock Types.BlockHash Types.SupplementedTransactionSummary
| MultipleBlocksUnambiguous [Types.BlockHash] Types.SupplementedTransactionSummary
| MultipleBlocksAmbiguous [(Types.BlockHash, Types.SupplementedTransactionSummary)]

parseTransactionBlockResult :: TransactionStatusResult -> TransactionBlockResult
parseTransactionBlockResult status =
Expand All @@ -637,7 +637,7 @@ parseTransactionBlockResult status =
printTransactionStatus ::
TransactionStatusResult ->
Bool ->
Maybe (Map.Map Types.BlockHash [(Types.Event, Maybe CI.ContractInfo)]) ->
Maybe (Map.Map Types.BlockHash [(Types.SupplementedEvent, Maybe CI.ContractInfo)]) ->
Printer
printTransactionStatus status verbose contrInfoWithSchemas =
case tsrState status of
Expand Down Expand Up @@ -699,10 +699,10 @@ printTransactionStatus status verbose contrInfoWithSchemas =
tell ["Transaction is finalized into multiple blocks - this should never happen and may indicate a serious problem with the chain!"]
where
-- Look up event and schema data associated with the transaction in block with hash h.
lookupContrInfo :: Types.BlockHash -> Maybe [(Event, Maybe CI.ContractInfo)]
lookupContrInfo :: Types.BlockHash -> Maybe [(SupplementedEvent, Maybe CI.ContractInfo)]
lookupContrInfo h = contrInfoWithSchemas >>= (Map.!? h)

showOutcomeFragment :: Types.TransactionSummary -> String
showOutcomeFragment :: Types.SupplementedTransactionSummary -> String
showOutcomeFragment outcome =
printf
"status \"%s\" and cost %s"
Expand All @@ -712,7 +712,7 @@ printTransactionStatus status verbose contrInfoWithSchemas =
Types.TxSuccess _ -> "success"
Types.TxReject _ -> "rejected"

showOutcomeCost :: Types.TransactionSummary -> String
showOutcomeCost :: Types.SupplementedTransactionSummary -> String
showOutcomeCost outcome = showCost (Types.tsCost outcome) (Types.tsEnergyCost outcome)

showCost :: Types.Amount -> Types.Energy -> String
Expand All @@ -723,9 +723,9 @@ showOutcomeResult ::
-- | Whether the output should be verbose.
Verbose ->
-- | Map holding contract info that should be used for displaying events of the outcome.
Maybe [(Types.Event, Maybe CI.ContractInfo)] ->
Maybe [(Types.SupplementedEvent, Maybe CI.ContractInfo)] ->
-- | The transaction outcome to show.
Types.ValidResult ->
Types.SupplementedValidResult ->
[String]
showOutcomeResult verbose contrInfoWithEventsM = \case
Types.TxSuccess es ->
Expand Down Expand Up @@ -756,7 +756,7 @@ showOutcomeResult verbose contrInfoWithEventsM = \case
--
-- The reason for using a @Maybe String@ is that the output is only produced
-- if the verbose flag is set.
fHelper :: (Int, [Maybe String]) -> (Event, Maybe CI.ContractInfo) -> (Int, [Maybe String])
fHelper :: (Int, [Maybe String]) -> (SupplementedEvent, Maybe CI.ContractInfo) -> (Int, [Maybe String])
fHelper (idt, out) (ev, cInfo) =
let
-- compute the new indentation level for the current event (idtCurrent) and
Expand Down Expand Up @@ -791,7 +791,7 @@ showEvent ::
-- | Contract information holding schema information to be used for displaying the event.
Maybe CI.ContractInfo ->
-- | The event to show.
Types.Event ->
Types.SupplementedEvent ->
Maybe String
showEvent verbose ciM = \case
Types.ModuleDeployed ref ->
Expand Down
Loading

0 comments on commit 231ae66

Please sign in to comment.