Update documentation, definitely WIP

This commit is contained in:
Robert Virding 2019-04-23 11:34:19 +02:00
parent d9be8b2fca
commit 04b3227317

View File

@ -35,19 +35,48 @@ generates the following JSON structure representing the contract interface:
{ {
"name": "state", "name": "state",
"vars": [], "vars": [],
"typedef": "{a : map(string,int)}" "typedef": {
"record": [
{
"name": "a",
"type": {
"map": {
"key": "string",
"value": "int"
}
}
}
]
}
}, },
{ {
"name": "answers", "name": "answers",
"vars": [], "vars": [],
"typedef": "map(string,int)" "typedef": {
"map": {
"key": "string",
"value": "int"
}
}
} }
], ],
"functions": [ "functions": [
{ {
"name": "init", "name": "init",
"arguments": [], "arguments": [],
"type": "{a : map(string,int)}", "returns": {
"record": [
{
"name": "a",
"type": {
"map": {
"key": "string",
"value": "int"
}
}
}
]
},
"stateful": true "stateful": true
}, },
{ {
@ -55,14 +84,23 @@ generates the following JSON structure representing the contract interface:
"arguments": [ "arguments": [
{ {
"name": "q", "name": "q",
"type": "string" "type": [
"string"
]
}, },
{ {
"name": "a", "name": "a",
"type": "int" "type": [
"int"
]
} }
], ],
"type": "map(string,int)", "returns": {
"map": {
"key": "string",
"value": "int"
}
},
"stateful": false "stateful": false
} }
] ]
@ -74,7 +112,7 @@ When that encoding is decoded the following include definition is generated:
``` ```
contract Answers = contract Answers =
function new_answer : (string, int) => map(string,int) function new_answer : (string, int) => map(string, int)
``` ```
### Types ### Types
@ -85,7 +123,7 @@ json_string() = binary()
### Exports ### Exports
#### encode(ContractString) -> {ok,JSONstring} | {error,ErrorString} #### encode_contract(ContractString) -> {ok,JSONstring} | {error,ErrorString}
Types Types
@ -96,7 +134,7 @@ JSONstring = json_string()
Generate the JSON encoding of the interface to a contract. The type definitions and non-private functions are included in the JSON string. Generate the JSON encoding of the interface to a contract. The type definitions and non-private functions are included in the JSON string.
#### decode(JSONstring) -> ConstractString. #### decode_contract(JSONstring) -> ConstractString.
Types Types
@ -107,6 +145,12 @@ JSONstring = json_string()
Take a JSON encoding of a contract interface and generate and generate a contract definition which can be included in another contract. Take a JSON encoding of a contract interface and generate and generate a contract definition which can be included in another contract.
#### encode_type(TypeAST) -> JSONstring.
#### encode_stmt(StmtAST) -> JSONstring.
#### encode_expr(ExprAST) -> JSONstring.
### Example run ### 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. 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.
@ -114,12 +158,12 @@ This is an example of using the ACI generator from an Erlang shell. The file cal
``` erlang ``` erlang
1> {ok,Contract} = file:read_file("aci_test.aes"). 1> {ok,Contract} = file:read_file("aci_test.aes").
{ok,<<"contract Answers =\n record state = { a : answers }\n type answers() = map(string, int)\n\n stateful function"...>>} {ok,<<"contract Answers =\n record state = { a : answers }\n type answers() = map(string, int)\n\n stateful function"...>>}
2> {ok,Encoding} = aeso_aci:encode(Contract). 2> {ok,Encoding} = aeso_aci:encode_contract(Contract).
<<"{\"contract\":{\"name\":\"Answers\",\"type_defs\":[{\"name\":\"state\",\"vars\":[],\"typedef\":\"{a : map(string,int)}\"},{\"name\":\"ans"...>> <<"{\"contract\":{\"name\":\"Answers\",\"type_defs\":[{\"name\":\"state\",\"vars\":[],\"typedef\":\"{a : map(string,int)}\"},{\"name\":\"ans"...>>
3> file:write_file("aci_test.aci", Encoding). 3> file:write_file("aci_test.aci", Encoding).
ok ok
4> Decoded = aeso_aci:decode(Encoding). 4> Decoded = aeso_aci:decode_contract(Encoding).
<<"contract Answers =\n function new_answer : (string, int) => map(string,int)\n">> <<"contract Answers =\n function new_answer : (string, int) => map(string, int)\n">>
5> file:write_file("aci_test.include", Decoded). 5> file:write_file("aci_test.include", Decoded).
ok ok
6> jsx:prettify(Encoding). 6> jsx:prettify(Encoding).