Skip to content

Commit

Permalink
Update SubmitTx to only require a socket path and tx file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimbo4350 committed Dec 6, 2019
1 parent 67a3f3a commit 0bf1d3d
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 44 deletions.
6 changes: 3 additions & 3 deletions cardano-config/src/Cardano/Config/CommonCLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ parseSocketDirLast =
\ ${dir}/node-{core,relay}-${node-id}.socket"
)

parseSocketPath :: Parser SocketPath
parseSocketPath =
parseSocketPath :: Text -> Parser SocketPath
parseSocketPath helpMessage =
SocketFile <$> strOption
( long "socket-path"
<> help "Path to a cardano-node socket"
<> (help $ toS helpMessage)
<> completer (bashCompleter "file")
<> metavar "FILEPATH"
)
Expand Down
3 changes: 1 addition & 2 deletions cardano-node/app/cardano-cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ parseTxRelatedValues =
"Submit a raw, signed transaction, in its on-wire representation."
$ SubmitTx
<$> parseTxFile "tx"
<*> parseTopologyInfo "Target node that will receive the transaction"
<*> parseNodeId "Node Id of target node"
<*> parseSocketPath "Socket path of the target node."
, command'
"issue-genesis-utxo-expenditure"
"Write a file with a signed transaction, spending genesis UTxO."
Expand Down
2 changes: 1 addition & 1 deletion cardano-node/app/chairman.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ parseChairmanArgs =
"timeout-is-success" "Exit successfully on timeout."
<*> (GenesisFile <$> parseGenesisPath)
<*> parseGenesisHash
<*> parseSocketPath
<*> parseSocketPath "Path to a cardano-node socket"
<*> (ConfigYamlFilePath <$> parseConfigFile)
<*> (optional $ SigningKeyFile <$> parseSigningKey)
<*> (optional $ DelegationCertFile <$> parseDelegationCert)
Expand Down
14 changes: 6 additions & 8 deletions cardano-node/src/Cardano/CLI/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import Cardano.Config.Types (CardanoConfiguration(..), Core(..),
DelegationCertFile(..), GenesisFile(..),
SigningKeyFile(..), SocketPath(..))
import Cardano.Config.Logging (LoggingLayer (..))
import Cardano.Config.Topology (NodeAddress(..), TopologyInfo(..))
import Cardano.Config.Topology (NodeAddress(..))

-- | Sub-commands of 'cardano-cli'.
data ClientCommand
Expand Down Expand Up @@ -124,8 +124,8 @@ data ClientCommand
| SubmitTx
TxFile
-- ^ Filepath of transaction to submit.
TopologyInfo
NodeId
SocketPath
-- ^ Socket path of target node.
| SpendGenesisUTxO
NewTxFile
-- ^ Filepath of the newly created transaction.
Expand Down Expand Up @@ -215,21 +215,19 @@ runCommand _ _(CheckDelegation magic cert issuerVF delegateVF) = do
liftIO $ checkByronGenesisDelegation cert magic issuerVK delegateVK

runCommand
(CardanoConfiguration{ccCore, ccProtocol, ccSocketDir, ccUpdate})
(CardanoConfiguration{ccCore, ccProtocol, ccUpdate})
_
(SubmitTx fp topology nid) = do
(SubmitTx fp targetSp) = do
tx <- liftIO $ readByronTx fp
liftIO $ nodeSubmitTx
topology
(coGenesisHash ccCore)
(nid)
(coNumCoreNodes ccCore)
(GenesisFile $ coGenesisFile ccCore)
(coRequiresNetworkMagic ccCore)
(coPBftSigThd ccCore)
(DelegationCertFile <$> (coStaticKeyDlgCertFile ccCore))
(SigningKeyFile <$> (coStaticKeySigningKeyFile ccCore))
(SocketFile ccSocketDir)
targetSp
ccUpdate
ccProtocol
tx
Expand Down
16 changes: 6 additions & 10 deletions cardano-node/src/Cardano/CLI/Tx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import Cardano.CLI.Tx.Submission
import Cardano.Config.Protocol
import Cardano.Config.Types (DelegationCertFile, GenesisFile,
SigningKeyFile, SocketPath, Update)
import Cardano.Config.Topology
import Cardano.Common.Orphans ()


Expand Down Expand Up @@ -289,11 +288,10 @@ issueUTxOExpenditure

-- | Submit a transaction to a node specified by topology info.
nodeSubmitTx
:: TopologyInfo
-> Text
-> NodeId
:: Text
-- ^ Genesis hash.
-> Maybe Int
-- ^ Number of core nodes
-- ^ Number of core nodes.
-> GenesisFile
-> RequiresNetworkMagic
-> Maybe Double
Expand All @@ -305,22 +303,20 @@ nodeSubmitTx
-> GenTx ByronBlock
-> IO ()
nodeSubmitTx
topology
gHash
nId
mNumCoreNodes
genFile
nMagic
sigThresh
delCertFp
sKeyFp
socketFp
targetSocketFp
update
ptcl
gentx =
withRealPBFT gHash (Just nId) mNumCoreNodes genFile nMagic sigThresh delCertFp sKeyFp update ptcl $
withRealPBFT gHash Nothing mNumCoreNodes genFile nMagic sigThresh delCertFp sKeyFp update ptcl $
\p@Consensus.ProtocolRealPBFT{} -> do
case gentx of
ByronTx txid _ -> putStrLn $ sformat ("TxId: "%Crypto.hashHexF) txid
_ -> pure ()
handleTxSubmission socketFp p topology gentx stdoutTracer
handleTxSubmission targetSocketFp p gentx stdoutTracer
5 changes: 2 additions & 3 deletions cardano-node/src/Cardano/CLI/Tx/Generation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ import Ouroboros.Consensus.Ledger.Byron (ByronBlock (..),
GenTx (..),
ByronConsensusProtocol)
import qualified Ouroboros.Consensus.Ledger.Byron as Byron
import Ouroboros.Consensus.NodeId (NodeId (..))
import Ouroboros.Consensus.Protocol.Abstract (NodeConfig)
import Ouroboros.Consensus.Protocol.PBFT (pbftExtConfig)

Expand Down Expand Up @@ -420,7 +419,7 @@ prepareInitialFunds llTracer
genesisAddress
(NE.fromList [outForBig])

submitTx socketFp pInfoConfig (CoreId 0) genesisTx llTracer
submitTx socketFp pInfoConfig genesisTx llTracer
-- Done, the first transaction 'initGenTx' is submitted, now 'sourceAddress' has a lot of money.

let txIn = CC.UTxO.TxInUtxo (getTxIdFromGenTx genesisTx) 0
Expand Down Expand Up @@ -813,7 +812,7 @@ createMoreFundCoins llTracer
txOut
[]
liftIO $ forM_ splittingTxs $ \(tx, txDetailsList) -> do
submitTx socketFp pInfoConfig (CoreId 0) tx llTracer
submitTx socketFp pInfoConfig tx llTracer
-- Update available fundValueStatus to reuse the numSplittingTxOuts TxOuts.
forM_ txDetailsList addToAvailableFunds
where
Expand Down
14 changes: 5 additions & 9 deletions cardano-node/src/Cardano/CLI/Tx/Submission.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import Ouroboros.Consensus.Node.ProtocolInfo ( ProtocolInfo(..)
, protocolInfo)
import Ouroboros.Consensus.Node.Run (RunNode)
import qualified Ouroboros.Consensus.Node.Run as Node
import Ouroboros.Consensus.NodeId (NodeId(..))
import qualified Ouroboros.Consensus.Protocol as Consensus
import Ouroboros.Consensus.Protocol hiding (Protocol)

Expand All @@ -48,7 +47,6 @@ import Ouroboros.Network.Protocol.Handshake.Version ( Versions
import Ouroboros.Network.NodeToClient (NetworkConnectTracers (..))
import qualified Ouroboros.Network.NodeToClient as NodeToClient

import Cardano.Config.Topology
import Cardano.Common.LocalSocket
import Cardano.Config.Types (SocketPath(..))

Expand All @@ -67,35 +65,33 @@ handleTxSubmission :: forall blk.
)
=> SocketPath
-> Consensus.Protocol blk
-> TopologyInfo
-> GenTx blk
-> Tracer IO String
-> IO ()
handleTxSubmission socketFp ptcl tinfo tx tracer = do
handleTxSubmission targetSocketFp ptcl tx tracer = do
let pinfo :: ProtocolInfo blk
pinfo = protocolInfo ptcl

submitTx socketFp (pInfoConfig pinfo) (node tinfo) tx tracer
submitTx targetSocketFp (pInfoConfig pinfo) tx tracer

submitTx :: ( RunNode blk
, Show (ApplyTxErr blk)
)
=> SocketPath
-> NodeConfig (BlockProtocol blk)
-> NodeId
-> GenTx blk
-> Tracer IO String
-> IO ()
submitTx socketFp protoInfoConfig _ tx tracer = do
socketPath <- localSocketAddrInfo socketFp
submitTx targetSocketFp protoInfoConfig tx tracer = do
targetSocketFp' <- localSocketAddrInfo targetSocketFp
NodeToClient.connectTo
NetworkConnectTracers {
nctMuxTracer = nullTracer,
nctHandshakeTracer = nullTracer
}
(localInitiatorNetworkApplication tracer protoInfoConfig tx)
Nothing
socketPath
targetSocketFp'

localInitiatorNetworkApplication
:: forall blk m peer.
Expand Down
4 changes: 2 additions & 2 deletions cardano-node/src/Cardano/Common/Parsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ nodeMockParser = do
-- Filepaths
topFp <- parseTopologyFile
dbFp <- parseDbPath
socketFp <- parseSocketPath
socketFp <- parseSocketPath "Path to a cardano-node socket"

genHash <- parseGenesisHash

Expand Down Expand Up @@ -131,7 +131,7 @@ nodeRealParser = do
genFp <- optional parseGenesisPath
delCertFp <- optional parseDelegationCert
sKeyFp <- optional parseSigningKey
socketFp <- parseSocketPath
socketFp <- parseSocketPath "Path to a cardano-node socket"

genHash <- parseGenesisHash

Expand Down
4 changes: 1 addition & 3 deletions cardano-node/src/Cardano/Wallet/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import Ouroboros.Consensus.Block (BlockProtocol)
import Ouroboros.Consensus.Mempool
import Ouroboros.Consensus.Node.ProtocolInfo
import Ouroboros.Consensus.Node.Run
import Ouroboros.Consensus.NodeId
import Ouroboros.Consensus.Protocol

import Network.TypedProtocol.Codec
Expand Down Expand Up @@ -58,10 +57,9 @@ runWalletClient :: forall blk.
)
=> Protocol blk
-> SocketPath
-> CoreNodeId
-> Tracer IO String
-> IO ()
runWalletClient ptcl sockFp (CoreNodeId _) tracer = do
runWalletClient ptcl sockFp tracer = do

addr <- localSocketAddrInfo sockFp

Expand Down
2 changes: 1 addition & 1 deletion cardano-node/src/Cardano/Wallet/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ runClient WalletCLI{ waNodeCli , waGenesisHash} tracer = do
(ncUpdate nc)
(ncProtocol nc)
let socketDir = socketFile $ realMscFp waNodeCli
runWalletClient p socketDir coreNodeId tracer'
runWalletClient p socketDir tracer'

data WalletCLI = WalletCLI { waNodeCli :: !NodeCLI
, waGenesisHash :: !Text
Expand Down
2 changes: 0 additions & 2 deletions scripts/submit-tx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ NETARGS=(
--genesis-file "${genesis_file}"
--genesis-hash "${genesis_hash}"
submit-tx
--topology "configuration/simple-topology.json"
--node-id "0"
--tx "$TX"
)

Expand Down

0 comments on commit 0bf1d3d

Please sign in to comment.