aeso_aci
Module
aeso_aci
The ACI interface encoder and decoder.
Description
This module provides an interface to generate and convert between Sophia contracts and a suitable JSON encoding of contract interface. As yet the interface is very basic.
Encoding this contract:
contract Answers =
record state = { a : answers }
type answers() = map(string, int)
stateful function init() = { a = {} }
private function the_answer() = 42
function new_answer(q : string, a : int) : answers() = { [q] = a }generates the following JSON structure representing the contract interface:
{
"contract": {
"functions": [
{
"arguments": [],
"name": "init",
"returns": "Answers.state",
"stateful": true
},
{
"arguments": [
{
"name": "q",
"type": "string"
},
{
"name": "a",
"type": "int"
}
],
"name": "new_answer",
"returns": {
"map": [
"string",
"int"
]
},
"stateful": false
}
],
"name": "Answers",
"state": {
"record": [
{
"name": "a",
"type": "Answers.answers"
}
]
},
"typedefs": [
{
"name": "answers",
"typedef": {
"map": [
"string",
"int"
]
},
"vars": []
}
]
}
}When that encoding is decoded the following include definition is generated:
Types
Exports
contract_interface(aci_type(), string()) -> {ok, json() | string()} | {error, term()}
Generate the JSON encoding of the interface to a contract. The type definitions and non-private functions are included in the JSON string.
render_aci_json(json() | json_text()) -> string().
Take a JSON encoding of a contract interface and generate a contract interface that can be included in another contract.
Example run
This is an example of using the ACI generator from an Erlang shell. The file
called aci_test.aes contains the contract in the description from which we
want to generate files aci_test.json which is the JSON encoding of the
contract interface and aci_test.include which is the contract definition to
be included inside another contract.
The final call to jsx:prettify(jsx:encode(JsonACI)) returns the encoding in a
more easily readable form. This is what is shown in the description above.
Last updated
Was this helpful?