Skip to content
Permalink
Browse files

editing

  • Loading branch information...
simonjohnthompson committed Apr 11, 2019
1 parent 150143a commit 3767e91d95ebf02f0fc8bfdb6f66f866b8badd3c
Showing with 10 additions and 6 deletions.
  1. +10 −6 docs/tutorial-v2.0/marlowe-semantics.md
@@ -1,27 +1,31 @@
# The semantics of Marlowe 2.0

This tutorial gives a high-level formal semantics of Marlowe 2.0 by describing the types of inputs supported, and by showing the Haskell code for the main functions that constituite the semantics.
This tutorial gives a high-level formal semantics of Marlowe 2.0 by describing the types of inputs supported, and by showing the Haskell code for the main functions that constitute the semantics.

In general, participants of a Marlowe contract can communicate with the contract by issuing transactions. From the point of view of Marlowe's semantics, a transaction consists basically of a list of inputs that may be signed by one or more participants. In the semantics, we represent a transaction as a list of inputs together with a set of integer numbers (the set of integer numbers represents the set of participants that signed the transaction).
In general, participants in a Marlowe contract communicate with the contract by issuing _transactions_. From the point of view of Marlowe's semantics, a transaction consists of a list of inputs, and the transaction may be _signed_ by one or more participants. Concretely, we represent a transaction as a list of `AnyInput`s together with a set of integers representing the set of signatories of the transaction.

As we mentioned in the previous tutorial, inputs can have one out of four types: `Commit`, `Pay`, `Choice`, and `Oracle`. From these four types, `Commit` and `Pay` are considered actions and have typically associated the transference of some money between the participant and the contract. `Choice` and `Oracle` are used to provide information from the external world to the contract.
As we mentioned in [the previous tutorial](./marlowe-data.md), inputs can have one out of four kinds: `Commit`, `Pay`, `Choice`, and `Oracle`. Of these, `Commit` and `Pay` are considered to be _actions_ and are typically associated with the transfer of money between a participant and the contract. `Choice` and `Oracle` are used to provide information from the external world to the contract.

## The `applyTransaction` function

The effect that a transaction has in a Marlowe contract is modelled by the top-level function `applyTransaction`, which takes the transaction to process and the current state of the contract (including the internal state, the remaining contract, and the amount of funds remaining in the contract), and it returns the new state of the contract together with the amount of money that each participant is suppoused to transfer to or from the contract as part of the transaction.
The effect of executing a transaction in a Marlowe contract is modelled by the top-level function `applyTransaction`. This takes the transaction to process and the current state of the contract (including the internal state, the remaining contract, and the amount of funds remaining in the contract), and it returns the new state of the contract together with the amount of money that each participant is supposed to transfer to or from the contract as part of the transaction.

<p align="center">
<img width="100%" src="pix/applyTransaction.svg">
</p>

In Haskell the type of the `applyTransaction` function remains as follows:
The `applyTransaction` function has the following Haskell type:

```haskell
applyTransaction :: [AnyInput] -> S.Set Person -> BlockNumber -> State -> Contract -> Integer
-> MApplicationResult (Integer, TransactionOutcomes, State, Contract)
```

In turn, the `applyTransaction` function calls three fundamental auxiliar functions in the semantics: `reduce`, `fetchPrimitive`, and `eval`. The `reduce` function is applied before and after every input, `fetchPrimitve` is applied only for inputs that are actions (i.e: `Commit` and `Pay` inputs), and `eval` is applied to the result of `fetchPrimitive` whenever appropriate.
In turn, the `applyTransaction` function calls three principal auxiliary functions: `reduce`, `fetchPrimitive`, and `eval`.

- The `reduce` function is applied before and after every input,
- `fetchPrimitive` is applied only for inputs that are actions (i.e: `Commit` and `Pay` inputs), and
- `eval` is applied to the result of `fetchPrimitive` whenever appropriate.

In addition to these three functions, there are three additional functions that are applied in every transaction. Before processing the inputs, the function `expireCommits` is applied, and after processing the inputs the functions `redeemMoney` and `simplify` are applied.

0 comments on commit 3767e91

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