Skip to content
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

Remove command transactionSignAndSubmit #308

Merged
merged 3 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Remove command `raw SendTransaction`.
- Remove command `transaction sign-and-submit`.
- Remove command `transaction send-shielded` to disable the transfer of CCD from the shielded balance of the account to the shielded balance of another account.
- Remove command `account shield` to disable the transfer of CCD from the public balance to the shielded balance of an account.
- Rename command `transaction submit` to `transaction sign-and-submit`.
Expand Down
21 changes: 2 additions & 19 deletions src/Concordium/Client/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,7 @@ registerDataParser =
<|> (RegisterRaw <$> strOption (long "raw" <> metavar "FILE" <> help "File with raw bytes to be registered on chain."))

data TransactionCmd
= TransactionSignAndSubmit
{ tssFile :: !FilePath,
tssInteractionOpts :: !InteractionOpts
}
| TransactionSubmit
= TransactionSubmit
{ tsFile :: !FilePath,
tsInteractionOpts :: !InteractionOpts
}
Expand Down Expand Up @@ -695,8 +691,7 @@ transactionCmds =
( info
( TransactionCmd
<$> hsubparser
( transactionSignAndSubmitCmd
<> transactionSubmitCmd
( transactionSubmitCmd
<> transactionAddSignatureCmd
<> transactionStatusCmd
<> transactionSendCcdCmd
Expand All @@ -708,18 +703,6 @@ transactionCmds =
(progDesc "Commands for submitting and inspecting transactions.")
)

transactionSignAndSubmitCmd :: Mod CommandFields TransactionCmd
transactionSignAndSubmitCmd =
command
"sign-and-submit"
( info
( TransactionSignAndSubmit
<$> strArgument (metavar "FILE" <> help "File containing the transaction parameters in JSON format.")
<*> interactionOptsParser
)
(progDesc "Parse a JSON transaction with keys, sign it, and send it to the node.")
)

transactionSubmitCmd :: Mod CommandFields TransactionCmd
transactionSubmitCmd =
command
Expand Down
23 changes: 2 additions & 21 deletions src/Concordium/Client/LegacyCommands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ parseEpochSpecifier =
<*> optional (option auto (long "block" <> metavar "BLOCKHASH" <> help "Block hash"))

data LegacyCmd
= -- | Loads a transaction in the context of the local database and sends it to the specified RPC server
SendTransaction
{ legacySourceFile :: !FilePath
}
| -- | Queries the gRPC for the information about the execution of a transaction
= -- | Queries the gRPC for the information about the execution of a transaction
GetTransactionStatus
{ legacyTransactionHash :: !Text
}
Expand Down Expand Up @@ -176,8 +172,7 @@ data LegacyCmd
legacyProgramOptions :: Parser LegacyCmd
legacyProgramOptions =
hsubparser
( sendTransactionCommand
<> getTransactionStatusCommand
( getTransactionStatusCommand
<> getConsensusInfoCommand
<> getBlockInfoCommand
<> getBlockPendingUpdatesCommand
Expand Down Expand Up @@ -247,20 +242,6 @@ getNodeInfoCommand =
(progDesc "Query the gRPC server for the node information.")
)

sendTransactionCommand :: Mod CommandFields LegacyCmd
sendTransactionCommand =
command
"SendTransaction"
( info
( SendTransaction
<$> strArgument
(metavar "TX-SOURCE" <> help "JSON file with the transaction")
)
( progDesc
"Parse transaction in current context and send it to the node."
)
)

getTransactionStatusCommand :: Mod CommandFields LegacyCmd
getTransactionStatusCommand =
command
Expand Down
93 changes: 0 additions & 93 deletions src/Concordium/Client/Runner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module Concordium.Client.Runner (
withClient,
EnvData (..),
GrpcConfig,
processTransaction_,
sendBlockItem,
awaitState,

Expand Down Expand Up @@ -687,22 +686,6 @@ readSignedTransactionFromFile fname = do
processTransactionCmd :: TransactionCmd -> Maybe FilePath -> Verbose -> Backend -> IO ()
processTransactionCmd action baseCfgDir verbose backend =
case action of
TransactionSignAndSubmit fname intOpts -> do
-- TODO Ensure that the "nonce" field is optional in the payload.
source <- handleReadFile BSL.readFile fname

-- TODO Print transaction details

when (ioConfirm intOpts) $ do
confirmed <- askConfirmation $ Just "Do you want to send the transaction on chain? "
unless confirmed exitTransactionCancelled

withClient backend $ do
tx <- processTransaction source
let hash = getBlockItemHash tx
logSuccess [printf "transaction '%s' sent to the node" (show hash)]
when (ioTail intOpts) $ do
tailTransaction_ verbose hash
TransactionSubmit fname intOpts -> do
-- Read signedTransaction from file
signedTransaction <- readSignedTransactionFromFile fname
Expand Down Expand Up @@ -3993,12 +3976,6 @@ processIdentityShowCmd action backend =
processLegacyCmd :: LegacyCmd -> Backend -> IO ()
processLegacyCmd action backend =
case action of
SendTransaction fname -> do
source <- handleReadFile BSL.readFile fname
t <- withClient backend $ processTransaction source
putStrLn $
"Transaction sent to the node. Its hash is "
++ show (getBlockItemHash t)
GetConsensusInfo ->
withClient backend $
getConsensusInfo
Expand Down Expand Up @@ -4398,56 +4375,6 @@ printNodeInfo Queries.NodeInfo{..} =
Queries.NodeActive (Queries.BakerConsensusInfo bId Queries.ActiveFinalizer) ->
"In current finalizer committee with baker ID " <> show bId <> "'."

-- | Process a transaction from JSON payload given as a byte string
-- and with keys given explicitly.
-- The transaction is signed with all the provided keys.
processTransaction ::
(MonadFail m, MonadIO m) =>
BSL.ByteString ->
ClientMonad m Types.BareBlockItem
processTransaction source =
case AE.eitherDecode source of
Left err -> fail $ "Error decoding JSON: " ++ err
Right t -> processTransaction_ t True

-- | Process a transaction with unencrypted keys given explicitly.
-- The transaction is signed with all the provided keys.
processTransaction_ ::
(MonadFail m, MonadIO m) =>
TransactionJSON ->
Verbose ->
ClientMonad m Types.BareBlockItem
processTransaction_ transaction _verbose = do
let accountKeys = CT.keys transaction
tx <- do
let header = metadata transaction
sender = thSenderAddress header
nonce <-
case thNonce header of
Nothing -> do
res <- getAccountInfoOrDie (Types.AccAddress sender) Best
return $ Types.aiAccountNonce res
Just nonce -> return nonce
txPayload <- convertTransactionJsonPayload $ payload transaction
return $
Types.NormalTransaction $
encodeAndSignTransaction
txPayload
sender
(thEnergyAmount header)
nonce
(thExpiry header)
accountKeys
sbiRes <- sendBlockItem tx
let res = case sbiRes of
StatusOk resp -> Right resp
StatusNotOk (status, err) -> Left [i|GRPC response with status '#{status}': #{err}|]
StatusInvalid -> Left "GRPC response contained an invalid status code."
RequestFailed err -> Left $ "I/O error: " <> err
case res of
Left err -> logFatal ["Transaction not accepted by the baker: " <> err]
Right _ -> return tx

-- | Read a versioned credential from the bytestring, failing if any errors occur.
processCredential ::
(MonadFail m, MonadIO m) =>
Expand All @@ -4474,26 +4401,6 @@ processCredential source =
| otherwise ->
fail $ "Unsupported credential version: " ++ show (vVersion vCred)

-- | Convert JSON-based transaction type to one which is ready to be encoded, signed and sent.
convertTransactionJsonPayload :: (MonadFail m) => CT.TransactionJSONPayload -> ClientMonad m Types.Payload
convertTransactionJsonPayload = \case
(CT.DeployModule _) ->
fail "Use 'concordium-client module deploy' instead."
CT.InitContract{} ->
fail "Use 'concordium-client contract init' instead."
CT.Update{} ->
fail "Use 'concordium-client contract update' instead."
(CT.Transfer transferTo transferAmount) ->
return $ Types.Transfer transferTo transferAmount
CT.RemoveBaker -> return $ Types.RemoveBaker
CT.TransferToPublic{..} -> return $ Types.TransferToPublic{..}
-- Note: The following two types are not supported anymore in protocol version 7 or above.
-- FIXME: The following two should have the inputs changed so that they are usable.
-- They should only specify the amount and the index, and possibly the input encrypted amounts,
-- but the proofs should be automatically generated here.
CT.TransferToEncrypted{..} -> return $ Types.TransferToEncrypted{..}
CT.EncryptedAmountTransfer{..} -> return Types.EncryptedAmountTransfer{..}

-- | Sign a transaction payload and configuration into a "normal" AccountTransaction.
encodeAndSignTransaction ::
Types.Payload ->
Expand Down
91 changes: 0 additions & 91 deletions src/Concordium/Client/Types/Transaction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@

module Concordium.Client.Types.Transaction where

import Concordium.Client.Types.Account
import qualified Concordium.Cost as Cost
import Concordium.Crypto.EncryptedTransfers
import qualified Concordium.ID.Types as IDTypes
import Concordium.Types
import Concordium.Types.Execution as Types

import qualified Concordium.Types.Transactions as Types
import Data.Aeson as AE
import qualified Data.Aeson.TH as AETH
import Data.Text hiding (length, map)

Check warning on line 14 in src/Concordium/Client/Types/Transaction.hs

View workflow job for this annotation

GitHub Actions / concordium-client-build-and-test

The import of ‘Data.Text’ is redundant
import GHC.Generics (Generic)

-- | Base cost of checking the transaction. The cost is always at least this,
-- but in most cases it will have a transaction specific cost.
Expand Down Expand Up @@ -264,92 +259,6 @@
PayloadSize
transferWithSchedulePayloadSize numRels = 32 + 1 + 1 + fromIntegral numRels * 16

-- | Transaction header type
-- To be populated when deserializing a JSON object.
data TransactionJSONHeader = TransactionJSONHeader
{ -- | Address of the sender.
thSenderAddress :: IDTypes.AccountAddress,
-- | Nonce of the account. If not present it should be derived
-- from the context or queried to the state
thNonce :: Maybe Nonce,
-- | Amount dedicated for the execution of this transaction.
thEnergyAmount :: Energy,
-- | Absolute time after which transaction will not be executed.
thExpiry :: TransactionExpiryTime
}
deriving (Eq, Show)

data ModuleSource
= ByName Text
| FromSource Text
deriving (Eq, Show)

-- | Payload of a transaction
data TransactionJSONPayload
= -- | Deploys a blockchain-ready version of the module, as retrieved from the Context
DeployModule
{ moduleName :: !Text
}
| -- | Initializes a specific Contract in a Module
InitContract
{ amount :: !Amount,
moduleName :: !Text,
contractName :: !Text,
parameter :: !Text
}
| -- | Sends a specific message to a Contract
Update
{ moduleName :: !Text,
amount :: !Amount,
address :: !ContractAddress,
message :: !Text
}
| -- | Transfers specific amount to the recipent
Transfer
{ toaddress :: !IDTypes.AccountAddress,
amount :: !Amount
}
| RemoveBaker
| TransferToEncrypted
{ -- | Amount to transfer from public to encrypted balance of the account.
tteAmount :: !Amount
}
| TransferToPublic
{ -- | Amount the user wishes to transfer to the public balance.
ttpData :: !SecToPubAmountTransferData
}
| EncryptedAmountTransfer
{ eatTo :: !AccountAddress,
eatData :: !EncryptedAmountTransferData
}
deriving (Show, Generic)

AETH.deriveFromJSON
( AETH.defaultOptions
{ AETH.sumEncoding = AETH.TaggedObject "transactionType" "contents"
}
)
''TransactionJSONPayload

-- | Transaction as retrieved from a JSON object
data TransactionJSON = TransactionJSON
{ metadata :: TransactionJSONHeader,
payload :: TransactionJSONPayload,
keys :: AccountKeyMap
}
deriving (Generic, Show)

instance AE.FromJSON TransactionJSON where
parseJSON = withObject "Transaction" $ \v -> do
thSenderAddress <- v .: "sender"
thNonce <- v .:? "nonce"
thEnergyAmount <- v .: "energyAmount"
thExpiry <- v .: "expiry"
let tHeader = TransactionJSONHeader{..}
tPayload <- v .: "payload"
keyMap <- v .: "keys"
return $ TransactionJSON tHeader tPayload keyMap

-----------------------------------------------------------------

-- * JSON representation of a signed/partially-signed transaction
Expand Down
Loading