language

package
v0.0.0-...-e1b9ab0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package language contains types and methods that implement the Marlowe DSL in Go See: https://github.com/input-output-hk/marlowe-cardano/tree/main/marlowe/specification See: https://github.com/input-output-hk/marlowe-cardano/blob/main/marlowe/src/Language/Marlowe/Core/V1/Semantics/Types.hs

Package language contains types and methods that implement the Marlowe DSL in Go See: https://github.com/input-output-hk/marlowe-cardano/tree/main/marlowe/specification See: https://github.com/input-output-hk/marlowe-cardano/blob/main/marlowe/src/Language/Marlowe/Core/V1/Semantics/Types.hs

Package language contains types and methods that implement the Marlowe DSL in Go See: https://github.com/input-output-hk/marlowe-cardano/tree/main/marlowe/specification See: https://github.com/input-output-hk/marlowe-cardano/blob/main/marlowe/src/Language/Marlowe/Core/V1/Semantics/Types.hs

Package language contains types and methods that implement the Marlowe DSL in Go See: https://github.com/input-output-hk/marlowe-cardano/tree/main/marlowe/specification See: https://github.com/input-output-hk/marlowe-cardano/blob/main/marlowe/src/Language/Marlowe/Core/V1/Semantics/Types.hs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	AccountId AccountId
	Token     Token
}

Go lacks tuples; Account implements an intermediate data structure that is not a type within the Marlowe Core spec.

type AccountId

type AccountId Party

type Accounts

type Accounts map[Account]uint64 // This is a type in the Marlowe Core specs.

type Action

type Action interface {
	// contains filtered or unexported methods
}

type AddValue

type AddValue struct {
	Add Value `json:"add"`
	To  Value `json:"and"`
}

add() value (addition)

func (AddValue) IsValue

func (v AddValue) IsValue()

type Address

type Address string

"An address party is defined by a Blockhain specific Address §1.4 and it cannot be traded (it is fixed for the lifetime of a contract).

func (Address) ValidateEncoding

func (a Address) ValidateEncoding() error

Validate that an address will decode from a Bech32 encoding to a valid ledger address.

type AndObs

type AndObs struct {
	Both Observation `json:"both"`
	And  Observation `json:"and"`
}

func (AndObs) IsValue

func (o AndObs) IsValue()

type Assert

type Assert struct {
	Observe Observation `json:"assert"`
	Then    Contract    `json:"then"`
}

"An assertion contract Assert b c does not have any effect on the state of the contract, it immediately continues as c, but it issues a warning if the observation b evaluates to false. It can be used to ensure that a property holds in a given point of the contract, since static analysis will fail if any execution causes a warning. The Assert term might be removed from future on-chain versions of Marlowe." (§2.1.6)

type AvailableMoney

type AvailableMoney struct {
	Amount  Token     `json:"amount_of_token"`
	Account AccountId `json:"in_account"`
}

"AvailableMoney p t reports the amount of token t in the internal account of party p" (§2.1.5)

func (AvailableMoney) IsValue

func (v AvailableMoney) IsValue()

type BoolObs

type BoolObs bool
const FalseObs BoolObs = false
const TrueObs BoolObs = true

func (BoolObs) IsValue

func (o BoolObs) IsValue()

type Bound

type Bound struct {
	Upper uint64 `json:"from"`
	Lower uint64 `json:"to"`
}

"Choices are Bounded. As an argument for the Choice action §2.1.6, we pass a list of Bounds that limit the integer that we can choose. The Bound data type is a tuple of integers that represents an inclusive lower and upper bound." (§2.1.4)

type Case

type Case struct {
	Action Action   `json:"case"`
	Then   Contract `json:"then"`
}

type Choice

type Choice struct {
	ChoiceId ChoiceId `json:"for_choice"`
	Bounds   []Bound  `json:"choose_between"`
}

"A choice Choice i bs is made for a particular choice identified by the ChoiceId §2.1.4 i with a list of inclusive bounds bs on the values that are acceptable. For example, [Bound 0 0 , Bound 3 5 ] offers the choice of one of 0, 3, 4 and 5." (§2.1.6)

type ChoiceId

type ChoiceId struct {
	Name  string `json:"choice_name"`
	Owner Party  `json:"choice_owner"`
}

"Choices – of integers – are identified by ChoiceId which is defined with a canonical name and the Party who had made the choice." (§2.1.4)

type ChoiceValue

type ChoiceValue struct {
	Value ChoiceId `json:"value_of_choice"`
}

"ChoiceValue i reports the most recent value chosen for choice i, or zero if no such choice has been made" (§2.1.5)

func (ChoiceValue) IsValue

func (v ChoiceValue) IsValue()

type ChoseSomething

type ChoseSomething struct {
	Choice ChoiceId `json:"chose_something_for"`
}

func (ChoseSomething) IsValue

func (o ChoseSomething) IsValue()

type ChosenNum

type ChosenNum int

"For each Action, there is a corresponding Input that can be included inside a Transaction:

type-synonym ChosenNum = int datatype Input = IDeposit AccountId Party Token int | IChoice ChoiceId ChosenNum | INotify"

type CloseContract

type CloseContract string

"Close is the simplest contract, when we evaluate it, the execution is completed and we generate Payments §?? for the assets in the internal accounts to their default owners." (§2.1.6)

const Close CloseContract = "close"

type Cond

type Cond struct {
	Observation bool
	IfTrue      Value
	IfFalse     Value
}

"Cond b x y represents a condition expression that evaluates to x if b is true and to y otherwise." (§2.1.5)

func (Cond) IsValue

func (v Cond) IsValue()

type Constant

type Constant Integer

"Constant v evaluates to the integer v, while NegValue x, AddValue x y, SubValue x y, MulValue x y, and DivValue x y provide the common arithmetic operations - x, x + y, x − y, x ∗ y, and x / y, where division always rounds (truncates) its result towards zero." (§2.1.5)

func SetConstant

func SetConstant(s string) Constant

func (Constant) IsValue

func (v Constant) IsValue()

func (Constant) MarshalJSON

func (i Constant) MarshalJSON() ([]byte, error)

Make Constant a custom type for the JSON marshaller, converting big.Int to a string

type Contract

type Contract interface {
	// contains filtered or unexported methods
}

type Deposit

type Deposit struct {
	IntoAccount AccountId `json:"into_account"`
	Party       Party     `json:"party"`
	Token       Token     `json:"of_token"`
	Deposits    Value     `json:"deposits"`
}

"A Deposit a p t v makes a deposit of #v Tokens t from Party p into account a." (§2.1.6)

type DivValue

type DivValue struct {
	Divide Value `json:"divide"`
	By     Value `json:"by"`
}

div() value (division)

func (DivValue) IsValue

func (v DivValue) IsValue()

type Environment

type Environment struct {
	TimeInterval TimeInterval
}

record Environment = timeInterval :: TimeInterval"

type IChoice

type IChoice struct {
	ChoiceId  ChoiceId
	ChosenNum ChosenNum
}

"Choice defines a list of valid Bounds while IChoice has the actual ChosenNum." (§2.1.6)

type IDeposit

type IDeposit struct {
	AccountId AccountId
	Party     Party
	Token     Token
	Value     big.Int
}

"Deposit uses a Value while IDeposit has the int it was evaluated to with evalValue §2.2.10." (§2.1.6)

type INotify

type INotify struct{}

"Notify has an Observation while INotify does not have arguments, the Observation must evaluate to true inside the Transaction." (§2.1.6)

type If

type If struct {
	Observe Observation `json:"if"`
	Then    Contract    `json:"then"`
	Else    Contract    `json:"else"`
}

"The contract If obs x y allows branching. We continue to branch x if the Observation obs evaluates to true, or to branch y otherwise." (§2.1.6)

type Input

type Input interface {
	// contains filtered or unexported methods
}

type Integer

type Integer big.Int

use arbitrary-precision integers similar to Haskell's Integer primative

type Let

type Let struct {
	Name  ValueId  `json:"let"`
	Value Value    `json:"be"`
	Then  Contract `json:"then"`
}

"A Let contract Let i v c allows a contract to record a value using an identifier i. In this case, the expression v is evaluated, and the result is stored with the name i. The contract then continues as c. As well as allowing us to use abbreviations, this mechanism also means that we can capture and save volatile values that might be changing with time, e.g. the current price of oil, or the current time, at a particular point in the execution of the contract, to be used later on in contract execution." (§2.1.6)

type MulValue

type MulValue struct {
	Multiply Value `json:"multiply"`
	By       Value `json:"times"`
}

multiply() value (multiplication)

func (MulValue) IsValue

func (v MulValue) IsValue()

type NegValue

type NegValue struct {
	Neg Value `json:"negate"`
}

func (NegValue) IsValue

func (v NegValue) IsValue()

type NotObs

type NotObs struct {
	Not Observation `json:"not"`
}

func (NotObs) IsValue

func (o NotObs) IsValue()

type Notify

type Notify struct {
	If Observation `json:"notify_if"`
}

"A notification can be triggered by anyone as long as the Observation evaluates to true. If multiple Notify are present in the Case list, the first one with a true observation is matched." (§2.1.6)

type Observation

type Observation interface {
	Value
	// contains filtered or unexported methods
}

type OrObs

type OrObs struct {
	Either Observation `json:"either"`
	Or     Observation `json:"or"`
}

func (OrObs) IsValue

func (o OrObs) IsValue()

type POSIXTime

type POSIXTime int

func (POSIXTime) IsTimeout

func (t POSIXTime) IsTimeout()

type Party

type Party interface {
	// contains filtered or unexported methods
}

"We should separate the notions of participant, role, and address in a Marlowe contract. A participant (or Party) in the contract can be represented by either a fixed Address or a Role.

type-synonym RoleName = ByteString

datatype Party =
	Address Address
	| Role RoleName

type Pay

type Pay struct {
	From  AccountId `json:"from_account"`
	To    Payee     `json:"to"`
	Token Token     `json:"token"`
	Pay   Value     `json:"pay"`
	Then  Contract  `json:"then"`
}

"The contract Pay a p t v c, generates a Payment from the internal account a to a payee §2.1.3 p of #v Tokens and then continues to contract c. Warnings will be generated if the value v is not positive, or if there is not enough in the account to make the payment in full. In the latter case, a partial payment (of the available amount) is made." (§2.1.6)

type Payee

type Payee struct {
	Party Party
}

type Role

type Role struct {
	Name string `json:"role_token"`
}

"A Role, on the other hand, allows the participation of the contract to be dynamic. Any user that can prove to have permission to act as RoleName is able to carry out the actions assigned §2.1.6, and redeem the payments issued to that role. The roles could be implemented as tokens that can be traded. By minting multiple tokens for a particular role, several people can be given permission to act on behalf of that role simultaneously, this allows for more complex use cases." (§2.1.1)

type State

type State struct {
	Accounts    Accounts
	BoundValues map[ValueId]uint64
	MinTime     POSIXTime
}

record State = accounts :: Accounts choices :: (ChoiceId × ChosenNum) list boundValues :: (ValueId × int) list minTime :: POSIXTime

type SubValue

type SubValue struct {
	Subtract Value `json:"minus"`
	From     Value `json:"value"`
}

subtract() value (subtraction)

func (SubValue) IsValue

func (v SubValue) IsValue()

type TimeInterval

type TimeInterval struct {
	// contains filtered or unexported fields
}

Spec specifies a tuple, but Go doesn't have that datatype natively

type TimeIntervalValue

type TimeIntervalValue string
const TimeIntervalEnd TimeIntervalValue = "time_interval_end"
const TimeIntervalStart TimeIntervalValue = "time_interval_start"

func (TimeIntervalValue) IsValue

func (v TimeIntervalValue) IsValue()

type Timeout

type Timeout interface {
	IsTimeout()
}

type Token

type Token struct {
	Symbol string `json:"currency_symbol"`
	Name   string `json:"token_name"`
}

In order to allow Token to be used with AccountId in the Account type as a map index for Account we cannot use []byte for these values, since arrays are not Comparable types--a requirement for map index types. Convert to a []byte using the []byte(string) function to get the []byte representations if necessary.

var Ada Token = Token{} // empty token defaults to $ADA

Belongs in Cardano-specific implementation semantics

type UseValue

type UseValue struct {
	Value ValueId `json:"use_value"`
}

"UseValue i reports the most recent value of the variable i, or zero if that variable has not yet been set to a value." (§2.1.5)

func (UseValue) IsValue

func (v UseValue) IsValue()

type Value

type Value interface{ IsValue() }

"Values and Observations are language terms that interact with most of the other constructs. Value evaluates to an integer and Observation evaluates to a boolean using evalValue §2.2.10 and evalObservation §2.2.11 respectively. They are defined in a mutually recursive way as follows:

datatype Value = AvailableMoney AccountId Token | Constant int | NegValue Value | AddValue Value Value | SubValue Value Value | MulValue Value Value | DivValue Value Value | ChoiceValue ChoiceId | TimeIntervalStart | TimeIntervalEnd | UseValue ValueId | Cond Observation Value Value"

type ValueEQ

type ValueEQ struct {
	Value Value `json:"value"`
	Eq    Value `json:"equal_to"`
}

func (ValueEQ) IsValue

func (o ValueEQ) IsValue()

type ValueGE

type ValueGE struct {
	Value Value `json:"value"`
	Ge    Value `json:"ge_than"`
}

func (ValueGE) IsValue

func (o ValueGE) IsValue()

type ValueGT

type ValueGT struct {
	Value Value `json:"value"`
	Gt    Value `json:"gt"`
}

func (ValueGT) IsValue

func (o ValueGT) IsValue()

type ValueId

type ValueId string

"We can store a Value in the Marlowe State §2.1.8 using the Let construct §2.1.7, and we use a ValueId to referrence it" (§2.1.5)

type ValueLE

type ValueLE struct {
	Value Value `json:"value"`
	Le    Value `json:"le_than"`
}

func (ValueLE) IsValue

func (o ValueLE) IsValue()

type ValueLT

type ValueLT struct {
	Value Value `json:"value"`
	Lt    Value `json:"lt"`
}

func (ValueLT) IsValue

func (o ValueLT) IsValue()

type When

type When struct {
	Cases   []Case   `json:"when"`
	Timeout Timeout  `json:"timeout"`
	Then    Contract `json:"timeout_continuation"`
}

"When is the most complex constructor for contracts, with the form When cs t c. The list cs contains zero or more pairs of Actions and Contract continuations. When we do a computeTransaction §2.2.1, we follow the continuation associated to the first Action that matches the Input. If no action is matched it returns a ApplyAllNoMatchError. If a valid Transaction is computed with a TimeInterval with a start time bigger than the Timeout t, the contingency continuation c is evaluated. The explicit timeout mechanism is what allows Marlowe to avoid waiting forever for external inputs." (§2.1.6)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL