Skip to content

Commit

Permalink
#667 Add ref-script-size query command
Browse files Browse the repository at this point in the history
  • Loading branch information
carbolymer committed Mar 26, 2024
1 parent 644294c commit 52819a2
Show file tree
Hide file tree
Showing 18 changed files with 431 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Commands/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Cardano.CLI.EraBased.Commands.Query
, QueryPoolStateCmdArgs(..)
, QueryTxMempoolCmdArgs(..)
, QuerySlotNumberCmdArgs(..)
, QueryRefScriptSizeCmdArgs(..)
, QueryNoArgCmdArgs(..)
, QueryDRepStateCmdArgs(..)
, QueryDRepStakeDistributionCmdArgs(..)
Expand All @@ -34,6 +35,7 @@ import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key
import qualified Ouroboros.Network.Protocol.LocalStateQuery.Type as Consensus

import Data.Set (Set)
import Data.Text (Text)
import Data.Time.Clock
import GHC.Generics
Expand All @@ -54,6 +56,7 @@ data QueryCmds era
| QueryPoolStateCmd !QueryPoolStateCmdArgs
| QueryTxMempoolCmd !QueryTxMempoolCmdArgs
| QuerySlotNumberCmd !QuerySlotNumberCmdArgs
| QueryRefScriptSizeCmd !QueryRefScriptSizeCmdArgs
| QueryConstitutionCmd !(QueryNoArgCmdArgs era)
| QueryGovStateCmd !(QueryNoArgCmdArgs era)
| QueryDRepStateCmd !(QueryDRepStateCmdArgs era)
Expand Down Expand Up @@ -193,6 +196,16 @@ data QuerySlotNumberCmdArgs = QuerySlotNumberCmdArgs
, utcTime :: !UTCTime
} deriving (Generic, Show)

data QueryRefScriptSizeCmdArgs = QueryRefScriptSizeCmdArgs
{ nodeSocketPath :: !SocketPath
, consensusModeParams :: !ConsensusModeParams
, transactionInputs :: !(Set TxIn)
, networkId :: !NetworkId
, target :: !(Consensus.Target ChainPoint)
, format :: Maybe QueryOutputFormat
, mOutFile :: !(Maybe (File () Out))
} deriving (Generic, Show)

data QueryNoArgCmdArgs era = QueryNoArgCmdArgs
{ eon :: !(ConwayEraOnwards era)
, nodeSocketPath :: !SocketPath
Expand Down Expand Up @@ -272,6 +285,8 @@ renderQueryCmds = \case
"query tx-mempool" <> renderTxMempoolQuery q
QuerySlotNumberCmd {} ->
"query slot-number"
QueryRefScriptSizeCmd {} ->
"query ref-script-size"
QueryConstitutionCmd {} ->
"constitution"
QueryGovStateCmd {} ->
Expand Down
25 changes: 25 additions & 0 deletions cardano-cli/src/Cardano/CLI/EraBased/Options/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Cardano.CLI.Types.Common
import Cardano.CLI.Types.Key

import Data.Foldable
import GHC.Exts (IsList (..))
import Options.Applicative hiding (help, str)
import qualified Options.Applicative as Opt

Expand Down Expand Up @@ -109,6 +110,10 @@ pQueryCmds era envCli =
$ subParser "slot-number"
$ Opt.info (pQuerySlotNumberCmd era envCli)
$ Opt.progDesc "Query slot number for UTC timestamp"
, Just
. subParser "ref-script-size"
. Opt.info (pQueryRefScriptSizeCmd era envCli)
$ Opt.progDesc "Calculate the reference input scripts size in bytes for provided transaction ids"
, pQueryGetConstitutionCmd era envCli
, pQueryGetGovStateCmd era envCli
, pQueryDRepStateCmd era envCli
Expand Down Expand Up @@ -295,6 +300,26 @@ pQuerySlotNumberCmd era envCli =
, Opt.help "UTC timestamp in YYYY-MM-DDThh:mm:ssZ format"
]

pQueryRefScriptSizeCmd :: CardanoEra era -> EnvCli -> Parser (QueryCmds era)
pQueryRefScriptSizeCmd era envCli =
fmap QueryRefScriptSizeCmd $
QueryRefScriptSizeCmdArgs
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> (fromList <$> some pByTxIn)
<*> pNetworkId envCli
<*> pTarget era
<*> (optional $ pQueryOutputFormat "reference inputs")
<*> pMaybeOutputFile
where
pByTxIn :: Parser TxIn
pByTxIn =
Opt.option (readerFromParsecParser parseTxIn) $ mconcat
[ Opt.long "tx-in"
, Opt.metavar "TX-IN"
, Opt.help "Transaction input (TxId#TxIx)."
]

pQueryGetConstitutionCmd :: ()
=> CardanoEra era
-> EnvCli
Expand Down
1 change: 1 addition & 0 deletions cardano-cli/test/cardano-cli-golden/Test/Golden/Help.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ hprop_golden_HelpCmds =
let usages = List.filter (not . null) $ fmap extractCmd $ maybeToList . selectCmd =<< lines

forM_ usages $ \usage -> do
-- FIXME: this is sloow
H.noteShow_ usage
let expectedCmdHelpFp = "test/cardano-cli-golden/files/golden/help" </> Text.unpack (Text.intercalate "_" usage) <> ".cli"

Expand Down
113 changes: 113 additions & 0 deletions cardano-cli/test/cardano-cli-golden/files/golden/help.cli
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ Usage: cardano-cli shelley query
| pool-state
| tx-mempool
| slot-number
| ref-script-size
)

Node query commands. Will query the local node whose Unix domain socket is
Expand Down Expand Up @@ -647,6 +648,21 @@ Usage: cardano-cli shelley query slot-number --socket-path SOCKET_PATH

Query slot number for UTC timestamp

Usage: cardano-cli shelley query ref-script-size --socket-path SOCKET_PATH
[--cardano-mode
[--epoch-slots SLOTS]]
(--tx-in TX-IN)
( --mainnet
| --testnet-magic NATURAL
)
[ --output-json
| --output-text
]
[--out-file FILE]

Calculate the reference input scripts size in bytes for provided transaction
ids

Usage: cardano-cli shelley stake-address
( key-gen
| key-hash
Expand Down Expand Up @@ -1624,6 +1640,7 @@ Usage: cardano-cli allegra query
| pool-state
| tx-mempool
| slot-number
| ref-script-size
)

Node query commands. Will query the local node whose Unix domain socket is
Expand Down Expand Up @@ -1819,6 +1836,21 @@ Usage: cardano-cli allegra query slot-number --socket-path SOCKET_PATH

Query slot number for UTC timestamp

Usage: cardano-cli allegra query ref-script-size --socket-path SOCKET_PATH
[--cardano-mode
[--epoch-slots SLOTS]]
(--tx-in TX-IN)
( --mainnet
| --testnet-magic NATURAL
)
[ --output-json
| --output-text
]
[--out-file FILE]

Calculate the reference input scripts size in bytes for provided transaction
ids

Usage: cardano-cli allegra stake-address
( key-gen
| key-hash
Expand Down Expand Up @@ -2794,6 +2826,7 @@ Usage: cardano-cli mary query
| pool-state
| tx-mempool
| slot-number
| ref-script-size
)

Node query commands. Will query the local node whose Unix domain socket is
Expand Down Expand Up @@ -2985,6 +3018,19 @@ Usage: cardano-cli mary query slot-number --socket-path SOCKET_PATH

Query slot number for UTC timestamp

Usage: cardano-cli mary query ref-script-size --socket-path SOCKET_PATH
[--cardano-mode
[--epoch-slots SLOTS]]
(--tx-in TX-IN)
( --mainnet
| --testnet-magic NATURAL
)
[--output-json | --output-text]
[--out-file FILE]

Calculate the reference input scripts size in bytes for provided transaction
ids

Usage: cardano-cli mary stake-address
( key-gen
| key-hash
Expand Down Expand Up @@ -3956,6 +4002,7 @@ Usage: cardano-cli alonzo query
| pool-state
| tx-mempool
| slot-number
| ref-script-size
)

Node query commands. Will query the local node whose Unix domain socket is
Expand Down Expand Up @@ -4151,6 +4198,21 @@ Usage: cardano-cli alonzo query slot-number --socket-path SOCKET_PATH

Query slot number for UTC timestamp

Usage: cardano-cli alonzo query ref-script-size --socket-path SOCKET_PATH
[--cardano-mode
[--epoch-slots SLOTS]]
(--tx-in TX-IN)
( --mainnet
| --testnet-magic NATURAL
)
[ --output-json
| --output-text
]
[--out-file FILE]

Calculate the reference input scripts size in bytes for provided transaction
ids

Usage: cardano-cli alonzo stake-address
( key-gen
| key-hash
Expand Down Expand Up @@ -5153,6 +5215,7 @@ Usage: cardano-cli babbage query
| pool-state
| tx-mempool
| slot-number
| ref-script-size
)

Node query commands. Will query the local node whose Unix domain socket is
Expand Down Expand Up @@ -5348,6 +5411,21 @@ Usage: cardano-cli babbage query slot-number --socket-path SOCKET_PATH

Query slot number for UTC timestamp

Usage: cardano-cli babbage query ref-script-size --socket-path SOCKET_PATH
[--cardano-mode
[--epoch-slots SLOTS]]
(--tx-in TX-IN)
( --mainnet
| --testnet-magic NATURAL
)
[ --output-json
| --output-text
]
[--out-file FILE]

Calculate the reference input scripts size in bytes for provided transaction
ids

Usage: cardano-cli babbage stake-address
( key-gen
| key-hash
Expand Down Expand Up @@ -6601,6 +6679,7 @@ Usage: cardano-cli conway query
| pool-state
| tx-mempool
| slot-number
| ref-script-size
| constitution
| gov-state
| drep-state
Expand Down Expand Up @@ -6828,6 +6907,24 @@ Usage: cardano-cli conway query slot-number --socket-path SOCKET_PATH

Query slot number for UTC timestamp

Usage: cardano-cli conway query ref-script-size --socket-path SOCKET_PATH
[--cardano-mode
[--epoch-slots SLOTS]]
(--tx-in TX-IN)
( --mainnet
| --testnet-magic NATURAL
)
[ --volatile-tip
| --immutable-tip
]
[ --output-json
| --output-text
]
[--out-file FILE]

Calculate the reference input scripts size in bytes for provided transaction
ids

Usage: cardano-cli conway query constitution --socket-path SOCKET_PATH
[--cardano-mode
[--epoch-slots SLOTS]]
Expand Down Expand Up @@ -7991,6 +8088,7 @@ Usage: cardano-cli latest query
| pool-state
| tx-mempool
| slot-number
| ref-script-size
)

Node query commands. Will query the local node whose Unix domain socket is
Expand Down Expand Up @@ -8186,6 +8284,21 @@ Usage: cardano-cli latest query slot-number --socket-path SOCKET_PATH

Query slot number for UTC timestamp

Usage: cardano-cli latest query ref-script-size --socket-path SOCKET_PATH
[--cardano-mode
[--epoch-slots SLOTS]]
(--tx-in TX-IN)
( --mainnet
| --testnet-magic NATURAL
)
[ --output-json
| --output-text
]
[--out-file FILE]

Calculate the reference input scripts size in bytes for provided transaction
ids

Usage: cardano-cli latest stake-address
( key-gen
| key-hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Usage: cardano-cli allegra query
| pool-state
| tx-mempool
| slot-number
| ref-script-size
)

Node query commands. Will query the local node whose Unix domain socket is
Expand Down Expand Up @@ -47,3 +48,5 @@ Available commands:
pool-state Dump the pool state
tx-mempool Local Mempool info
slot-number Query slot number for UTC timestamp
ref-script-size Calculate the reference input scripts size in bytes
for provided transaction ids
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Usage: cardano-cli allegra query ref-script-size --socket-path SOCKET_PATH
[--cardano-mode
[--epoch-slots SLOTS]]
(--tx-in TX-IN)
( --mainnet
| --testnet-magic NATURAL
)
[ --output-json
| --output-text
]
[--out-file FILE]

Calculate the reference input scripts size in bytes for provided transaction
ids

Available options:
--socket-path SOCKET_PATH
Path to the node socket. This overrides the
CARDANO_NODE_SOCKET_PATH environment variable. The
argument is optional if CARDANO_NODE_SOCKET_PATH is
defined and mandatory otherwise.
--cardano-mode For talking to a node running in full Cardano mode
(default).
--epoch-slots SLOTS The number of slots per epoch for the Byron era.
(default: 21600)
--tx-in TX-IN Transaction input (TxId#TxIx).
--mainnet Use the mainnet magic id. This overrides the
CARDANO_NODE_NETWORK_ID environment variable
--testnet-magic NATURAL Specify a testnet magic id. This overrides the
CARDANO_NODE_NETWORK_ID environment variable
--output-json Format reference inputs query output to JSON. Default
format when writing to a file
--output-text Format reference inputs query output to TEXT. Default
format when writing to stdout
--out-file FILE Optional output file. Default is to write to stdout.
-h,--help Show this help text
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Usage: cardano-cli alonzo query
| pool-state
| tx-mempool
| slot-number
| ref-script-size
)

Node query commands. Will query the local node whose Unix domain socket is
Expand Down Expand Up @@ -47,3 +48,5 @@ Available commands:
pool-state Dump the pool state
tx-mempool Local Mempool info
slot-number Query slot number for UTC timestamp
ref-script-size Calculate the reference input scripts size in bytes
for provided transaction ids
Loading

0 comments on commit 52819a2

Please sign in to comment.