Skip to content
Permalink
Browse files

Address first comment in marlowe-semantics.md

  • Loading branch information...
palas committed Apr 11, 2019
1 parent c7ceae5 commit dae3d8fda3ce485c6cbc14fd8ced8bd39a1b0db3
Showing with 25 additions and 8 deletions.
  1. +25 −8 docs/tutorial-v2.0/marlowe-semantics.md
@@ -67,7 +67,7 @@ fetchPrimitive :: IdAction -> BlockNumber -> State -> Contract

### `Commit`

A `Commit` allows a participant `person` to transfer to the contract an amount of money `value`. This money will be recorded in the contract under the identifier `idCommit` and future payments can use this identifier as a source of money. Once the block specified by `timeout` (the second `Timeout` in `Commit`) is reached, any money from the `Commit` that has not been spent (through payments) will be frozen, and the participant that performed the commitment will be able to withdraw with the next transaction that he or she signs.
A `Commit` allows a participant `person` to transfer to the contract an amount of money `value`. This money will be recorded in the contract under the identifier `idCommit` and future payments can use this identifier as a source of money. Once the block specified by `timeout` (the second `Timeout` in `Commit`) is reached, any money from the `Commit` that has not been spent (through payments) will be frozen, and the participant that performed the commitment will be able to withdraw it with the next transaction that he or she signs.

```haskell
eval (DCommit idCommit person value timeout) state =
@@ -80,7 +80,20 @@ eval (DCommit idCommit person value timeout) state =

For a commitment to be valid, no commitment with the identifier `idCommit` must have been issued before (only one `Commit` per identifier is allowed).

In addition, `reduceRec` (the auxiliary function of `reduce`) specifies that a `Commit` will be reduced to its second `continuation` if any of the timeouts is reached.
If the `Commit` does not timeout and is issued correctly, the remaining contract, as returned by the `fetchPrimitive` function, will use the first `continuation` (the first `Contract` in `Commit`).

```haskell
fetchPrimitive idAction blockNum state (Commit idActionC idCommit person value _ timeout continuation _) =
if (idAction == idActionC && notCurrentCommit && notExpiredCommit)
then Picked ((DCommit idCommit person actualValue timeout),
continuation)
else NoMatch
where notCurrentCommit = not (isCurrentCommit idCommit state)
notExpiredCommit = not (isExpiredCommit idCommit state)
actualValue = evalValue blockNum state value
```

On the other hand, if any of the timeouts of the `Commit` are reached, `reduceRec` (the auxiliary function of `reduce`) specifies that a `Commit` will be reduced to its second `continuation`.

```haskell
reduceRec blockNum state env c@(Commit _ _ _ _ timeout_start timeout_end _ continuation) =
@@ -89,9 +102,6 @@ reduceRec blockNum state env c@(Commit _ _ _ _ timeout_start timeout_end _ conti
else c
```

**COMMENT: this next sentence seems not be linked with what comes before. Specifically, "instead of" what? (Same comment for `Pay` too)**
The `fetchPrimitive` function will use the first continuation (the first `Contract` in `Commit`) instead.

### `Pay`

A `Pay` allows a participant `person` to claim from the contract an amount of money `value`. This money will be discounted from the money committed under the identifier `idCommit`, and the contract will only pay up to the amount that remains available under `idCommit`, even if there is extra money available in the contract. In any case, `Pay` will pay no money if the commit `idCommit` has expired.
@@ -110,10 +120,19 @@ eval (DPay idCommit person value) state =
, fromJust $ discountAvailableMoneyFromCommit idCommit value state )
NoProblem)
where maxValue = getAvailableAmountInCommit idCommit state
```

If the `Pay` does not timeout and is claimed correctly, the remaining contract, as returned by the `fetchPrimitive` function, will use the first `continuation` (the first `Contract` in `Pay`).

```haskell
fetchPrimitive idAction blockNum state (Pay idActionC idCommit person value _ continuation _) =
if (idAction == idActionC)
then Picked ((DPay idCommit person actualValue), continuation)
else NoMatch
where actualValue = evalValue blockNum state value
```

Regarding `reduceRec`, `Pay` behaves similarly to `Commit` except in that `Pay` only has one `Timeout`; `Pay` will be reduced to its second `continuation` if its timeout is reached before it is claimed.
On the other hand, if the timeouts of the `Pay` is reached, `reduceRec` (the auxiliary function of `reduce`) specifies that a `Pay` will be reduced to its second `continuation`.

```haskell
reduceRec blockNum state env c@(Pay _ _ _ _ timeout _ continuation) =
@@ -122,8 +141,6 @@ reduceRec blockNum state env c@(Pay _ _ _ _ timeout _ continuation) =
else c
```

Again, the `fetchPrimitive` function will use the first continuation (the first `Contract` in `Pay`) instead.

## Non-action input processing

`Choice`s and `Oracle`s inputs are processed very differently to actions. They are relatively independent of the state of the contract, and they may be issued at any time, as long as the values provided can potentially be used by the contract. In other words, there must be somewhere in the code of the contract that inspects the `Choice` or `Oracle` value in order for a participant to be able to provide that value. Otherwise, the contract does not need to know the value, and providing it anyway would just be adding clutter and load to the contract and blockchain, which could end up translating into problems like DoS. For these reasons, the Marlowe 2.0 semantics disallows providing information that is not required.

0 comments on commit dae3d8f

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