In order to interact programmatically with compiled ola programs, Ola language supports passing arguments using an ABI.
contract BookExample {
struct Book {
u32 book_id;
string book_name;
}
fn createBook(u32 id, string name) -> (Book) {
Book myBook = Book({
book_name: name,
book_id: id
});
return myBook;
}
fn getBookName(Book _book) -> (string) {
return _book.book_name;
}
fn getBookId(Book _book) -> (u32) {
u32 b = _book.book_id + 1;
return b;
}
}
When compiling a ola program, an ABI specification is generated and describes the interface of the program.
[
{
"name": "createBook",
"type": "function",
"inputs": [
{
"name": "id",
"type": "u32",
"internalType": "u32"
},
{
"name": "name",
"type": "string",
"internalType": "string"
}
],
"outputs": [
{
"name": "",
"type": "tuple",
"internalType": "struct BookExample.Book",
"components": [
{
"name": "book_id",
"type": "u32",
"internalType": "u32"
},
{
"name": "book_name",
"type": "string",
"internalType": "string"
}
]
}
]
},
{
"name": "getBookName",
"type": "function",
"inputs": [
{
"name": "_book",
"type": "tuple",
"internalType": "struct BookExample.Book",
"components": [
{
"name": "book_id",
"type": "u32",
"internalType": "u32"
},
{
"name": "book_name",
"type": "string",
"internalType": "string"
}
]
}
],
"outputs": [
{
"name": "",
"type": "string",
"internalType": "string"
}
]
},
{
"name": "getBookId",
"type": "function",
"inputs": [
{
"name": "_book",
"type": "tuple",
"internalType": "struct BookExample.Book",
"components": [
{
"name": "book_id",
"type": "u32",
"internalType": "u32"
},
{
"name": "book_name",
"type": "string",
"internalType": "string"
}
]
}
],
"outputs": [
{
"name": "",
"type": "u32",
"internalType": "u32"
}
]
}
]
We can use the tools provided by ola-lang-abi to generate function selectors and function parameters corresponding to ABI.