Skip to content
Permalink
Browse files

Remove initial deposit for contract creation.

  • Loading branch information
nau committed Jan 14, 2020
1 parent d3022c0 commit d934561d59111387e3e457379137422b18d51fed
Showing with 16 additions and 24 deletions.
  1. +7 −10 marlowe/src/Language/Marlowe/Client.hs
  2. +9 −14 marlowe/src/Language/Marlowe/Semantics.hs
@@ -55,12 +55,11 @@ createContract contract = do
marloweState = emptyState slot }
ds = DataValue $ PlutusTx.toData marloweData

deposit = adaValueOf 1

(payment, change) <- createPaymentWithChange deposit
let o = scriptTxOut deposit validator ds
let payValue = adaValueOf 1
(payment, change) <- createPaymentWithChange payValue
let o = scriptTxOut P.zero validator ds
slotRange = interval slot (slot + 10)
outputs = o : maybeToList change
outputs = o : (pubKeyTxOut payValue creator) : maybeToList change

tx <- createTxAndSubmit slotRange payment outputs [ds]
return (marloweData, tx)
@@ -138,9 +137,7 @@ applyInputs :: (
-> [Input]
-> m (MarloweData, Tx)
applyInputs tx marloweData@MarloweData{..} inputs = do
let depositAmount = adaValueOf 1
depositPayment = Payment marloweCreator depositAmount
redeemer = mkRedeemer inputs
let redeemer = mkRedeemer inputs
validator = validatorScript marloweCreator
dataValue = DataValue (PlutusTx.toData marloweData)
address = scriptAddress validator
@@ -172,11 +169,11 @@ applyInputs tx marloweData@MarloweData{..} inputs = do
marloweState = txOutState }

let deducedTxOutputs = case txOutContract of
Close -> txPaymentOuts (depositPayment : txOutPayments)
Close -> txPaymentOuts txOutPayments
_ -> let
payouts = txPaymentOuts txOutPayments
totalPayouts = foldMap txOutValue payouts
finalBalance = totalIncome P.- totalPayouts P.+ depositAmount
finalBalance = totalIncome P.- totalPayouts
dataValue = DataValue (PlutusTx.toData marloweData)
scriptOut = scriptTxOut finalBalance validator dataValue
in scriptOut : payouts
@@ -754,15 +754,13 @@ validateBalances State{..} = all (\(_, balance) -> balance > 0) (Map.toList acco


{-| Ensure that 'pendingTx' contains expected payments. -}
validateTxOutputs :: PendingTx -> Party -> Money -> TransactionOutput -> Bool
validateTxOutputs pendingTx creator deposit expectedTxOutputs = case expectedTxOutputs of
validateTxOutputs :: PendingTx -> Party -> TransactionOutput -> Bool
validateTxOutputs pendingTx creator expectedTxOutputs = case expectedTxOutputs of
TransactionOutput {txOutPayments, txOutState, txOutContract} ->
case txOutContract of
Close -> let
-- if it's a last transaction, don't expect any continuation,
-- everything is payed out, including initial deposit.
payments = Payment creator deposit : txOutPayments
in validatePayments pendingTx payments
-- if it's a last transaction, don't expect any continuation,
-- everything is payed out.
Close -> validatePayments pendingTx txOutPayments
-- otherwise check the continuation
_ -> case getContinuingOutputs pendingTx of
[PendingTxOut
@@ -775,7 +773,7 @@ validateTxOutputs pendingTx creator deposit expectedTxOutputs = case expectedTxO
&& txOutState == expectedState
&& txOutContract == expectedContract
outputBalance = totalBalance (accounts txOutState)
outputBalanceOk = scriptOutputValue == (outputBalance + deposit)
outputBalanceOk = scriptOutputValue == outputBalance
in outputBalanceOk
&& validContract
&& validatePayments pendingTx txOutPayments
@@ -823,11 +821,8 @@ marloweValidator creator MarloweData{..} inputs pendingTx@PendingTx{..} = let
-- accounts must be positive, and we checked it above
inputBalance = totalBalance (accounts marloweState)

-- ensure that a contract TxOut has at least what it suppose to have
balancesOk = inputBalance `Val.leq` scriptInValue

-- calculate contract creation deposit
deposit = scriptInValue - inputBalance
-- ensure that a contract TxOut has what it suppose to have
balancesOk = inputBalance == scriptInValue

preconditionsOk = checkCreator
&& positiveBalances
@@ -838,7 +833,7 @@ marloweValidator creator MarloweData{..} inputs pendingTx@PendingTx{..} = let
txInput = TransactionInput { txInterval = slotInterval, txInputs = inputs }
expectedTxOutputs = computeTransaction txInput marloweState marloweContract

outputOk = validateTxOutputs pendingTx creator deposit expectedTxOutputs
outputOk = validateTxOutputs pendingTx creator expectedTxOutputs

in preconditionsOk && outputOk

0 comments on commit d934561

Please sign in to comment.
You can’t perform that action at this time.