Skip to content

Commit

Permalink
Add types for tx commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jhbertra committed Sep 30, 2022
1 parent 477f30b commit c62ad8c
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 14 deletions.
27 changes: 21 additions & 6 deletions marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command/Apply.hs
@@ -1,22 +1,37 @@
{-# LANGUAGE ExistentialQuantification #-}

module Language.Marlowe.Runtime.CLI.Command.Apply
where

import Language.Marlowe (POSIXTime)
import Language.Marlowe.Runtime.CLI.Command.Tx (TxCommand)
import Language.Marlowe.Runtime.CLI.Monad (CLI)
import Language.Marlowe.Runtime.Core.Api (ContractId, IsMarloweVersion(Redeemer), MarloweVersion)
import Options.Applicative

data ApplyCommand
data ApplyCommand = forall v. ApplyCommand
{ contractId :: ContractId
, marloweVersion :: MarloweVersion v
, inputs :: ContractInputs v
, validityLowerBound :: Maybe POSIXTime
, validityUpperBound :: Maybe POSIXTime
}

data ContractInputs v
= ContractInputsByFile FilePath
| ContractInputsByValue (Redeemer v)

applyCommandParser :: ParserInfo ApplyCommand
applyCommandParser :: ParserInfo (TxCommand ApplyCommand)
applyCommandParser = info empty $ progDesc "Apply inputs to a contract"

depositCommandParser :: ParserInfo ApplyCommand
depositCommandParser :: ParserInfo (TxCommand ApplyCommand)
depositCommandParser = info empty $ progDesc "Deposit funds into a contract"

chooseCommandParser :: ParserInfo ApplyCommand
chooseCommandParser :: ParserInfo (TxCommand ApplyCommand)
chooseCommandParser = info empty $ progDesc "Make a choice in a contract"

notifyCommandParser :: ParserInfo ApplyCommand
notifyCommandParser :: ParserInfo (TxCommand ApplyCommand)
notifyCommandParser = info empty $ progDesc "Notify a contract to proceed"

runApplyCommand :: ApplyCommand -> CLI ()
runApplyCommand :: TxCommand ApplyCommand -> CLI ()
runApplyCommand = error "not implemented"
28 changes: 25 additions & 3 deletions marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command/Create.hs
@@ -1,13 +1,35 @@
module Language.Marlowe.Runtime.CLI.Command.Create
where

import Data.Map (Map)
import Language.Marlowe (POSIXTime)
import Language.Marlowe.Runtime.CLI.Command.Tx (TxCommand)
import Language.Marlowe.Runtime.CLI.Monad (CLI)
import Language.Marlowe.Runtime.ChainSync.Api (Address, TokenName)
import Language.Marlowe.Runtime.Core.Api (SomeMarloweVersion)
import Options.Applicative

data CreateCommand
data CreateCommand = CreateCommand
{ marloweVersion :: SomeMarloweVersion
, roles :: Map TokenName Address
, contractFiles :: ContractFiles
}

createCommandParser :: ParserInfo CreateCommand
data ContractFiles
= CoreFile FilePath
| ExtendedFiles FilePath ContractArgs

data ContractArgs
= ContractArgsByFile FilePath
| ContractArgsByValue ContractArgsValue

data ContractArgsValue = ContractArgsValue
{ timeoutArguments :: Map String POSIXTime
, valueArguments :: Map String Integer
}

createCommandParser :: ParserInfo (TxCommand CreateCommand)
createCommandParser = info empty $ progDesc "Create a new Marlowe Contract"

runCreateCommand :: CreateCommand -> CLI ()
runCreateCommand :: TxCommand CreateCommand -> CLI ()
runCreateCommand = error "not implemented"
Expand Up @@ -4,10 +4,10 @@ module Language.Marlowe.Runtime.CLI.Command.Submit
import Language.Marlowe.Runtime.CLI.Monad (CLI)
import Options.Applicative

data SubmitCommand
data SubmitCommand = SubmitCommand

submitCommandParser :: ParserInfo SubmitCommand
submitCommandParser = info empty $ progDesc "Submit a signed transaction to the Cardano node."
submitCommandParser = info (pure SubmitCommand) $ progDesc "Submit a signed transaction to the Cardano node."

runSubmitCommand :: SubmitCommand -> CLI ()
runSubmitCommand = error "not implemented"
13 changes: 13 additions & 0 deletions marlowe-runtime/cli/Language/Marlowe/Runtime/CLI/Command/Tx.hs
@@ -0,0 +1,13 @@
module Language.Marlowe.Runtime.CLI.Command.Tx
where

import Language.Marlowe.Runtime.Transaction.Api (WalletAddresses)

data TxCommand cmd = TxCommand
{ walletAddresses :: WalletAddresses
, signingMethod :: SigningMethod
, subCommand :: cmd
}

data SigningMethod
= Manual
@@ -1,13 +1,19 @@
module Language.Marlowe.Runtime.CLI.Command.Withdraw
where

import Language.Marlowe.Runtime.CLI.Command.Tx (TxCommand)
import Language.Marlowe.Runtime.CLI.Monad (CLI)
import Language.Marlowe.Runtime.ChainSync.Api (TokenName)
import Language.Marlowe.Runtime.Core.Api (ContractId)
import Options.Applicative

data WithdrawCommand
data WithdrawCommand = WithdrawCommand
{ contractId :: ContractId
, role :: TokenName
}

withdrawCommandParser :: ParserInfo WithdrawCommand
withdrawCommandParser :: ParserInfo (TxCommand WithdrawCommand)
withdrawCommandParser = info empty $ progDesc "Withdraw funds paid to a role in a contract"

runWithdrawCommand :: WithdrawCommand -> CLI ()
runWithdrawCommand :: TxCommand WithdrawCommand -> CLI ()
runWithdrawCommand = error "not implemented"
1 change: 1 addition & 0 deletions marlowe-runtime/marlowe-runtime.cabal
Expand Up @@ -137,6 +137,7 @@ executable marlowe
Language.Marlowe.Runtime.CLI.Command.Ls
Language.Marlowe.Runtime.CLI.Command.Rm
Language.Marlowe.Runtime.CLI.Command.Submit
Language.Marlowe.Runtime.CLI.Command.Tx
Language.Marlowe.Runtime.CLI.Command.Withdraw
Language.Marlowe.Runtime.CLI.Env
Language.Marlowe.Runtime.CLI.Monad
Expand Down

0 comments on commit c62ad8c

Please sign in to comment.