Skip to content

Commit

Permalink
Remove command RawSendTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
DOBEN committed May 28, 2024
1 parent 3051db2 commit b8ea019
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 184 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 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.
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
77 changes: 0 additions & 77 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 @@ -3977,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 @@ -4382,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 @@ -4458,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
86 changes: 0 additions & 86 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)
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,11 @@ transferWithSchedulePayloadSize ::
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

0 comments on commit b8ea019

Please sign in to comment.