The Rekoner Programming Model

The Rekoner Programming Model

The Rekoner uses a simple, elegant, and powerful programming model. All objects in the Rekoner are represented as JSON documents, and the JSONata query and transformation language (restricted, see below) is used for data transformations. First, some terms:

  1. Ledgers are key pairs and represent accounts.
  2. Templates are a set of Reducers, which are named bits of JSONata code that execute the contract logic.
  3. Coins in the Rekoner are very abstract and general, and can represent any asset. Coins are ‘minted’ by Contracts, and have a symbol, a globally unique mint identifier, and an amount.
  4. Contracts are running instances of Templates.
  5. The State is a JSON object containing the current state of the Contract, and the current Coins available in the Contract.
  6. The available Coins and data in a Ledger that are available for consumption are represented as Outputs. Basically, Outputs are the generalized equivalent of Bitcoin UTXO’s.
  7. Minted Outputs are new Coins minted by the Contract.
  8. Inputs are signed Outputs.
  9. Actions are Inputs and a Reducer name.

Key Concepts

There are a few key concepts to understand in order to write contracts with the Rekoner effectively.

Contract Execution

A Contract is started by instantiating a Template. Actions are then sent to the Contract to execute the contract logic. When an Action is executed, the Reducer is passed the Action, the Inputs, the current State, and the current Coins in the Contract. It produces zero or more Outputs, zero or more Minted Outputs, and a new State.

It’s that simple.

This leads to a very modular programming style, and makes the contract logic very understandable.

Using Outputs

Perhaps the most important concept in the Rekoner is how to use Outputs correctly. Outputs in a Ledger are anything that is available for consumption by the owner of the Output. In other words, they can be signed by the Ledger and used as Inputs to Actions on contracts. An Output usually contains Coins, but this is not required. This is a key point. Outputs are used as the communication mechanism for Contract developers. If your Contract logic requires some signed data or Coins from a Ledger in order to continue, just create an Output on that Ledger asking for the appropriate data. Each Ledger can easily see its list of available Outputs, so the Ledger can act on any that need processing.

Coins

Each Output and the Contract State can contain any number of different Coins. As stated above, Coins are an abstract representation of any asset. They can be used as normal Coins, or to monetize any asset. Once something is converted to a Rekoner Coin, it can be used in a Contract.

Coins are ‘minted’ by Contracts. One of the possible outputs from an Action are called Minted Coins. These are just like normal Coins, but they have their origin and identity derived from the Contract.

Coins are input and output from Contracts. The Contract checks that the input amount for each Coin is greater than or equal to the Outputs for the life of the Contract. If this invariant is not satisfied, the Action will fail.

Note on JSONata

The JSONata language subset allowed is restricted to be deterministic.

2018-09-26T03:36:34+00:00August 29th, 2018|Categories: coin, dag, intro, programming|Tags: , , , , , , , |