From 326f1364a88b2bea6b04e7919877b90e66f751a1 Mon Sep 17 00:00:00 2001 From: Dzianis Andreyenka Date: Mon, 29 Jan 2024 23:14:37 +0800 Subject: [PATCH] DA-587 Update tezos docs (FFI section) Signed-off-by: Dzianis Andreyenka --- docs/reference/firefly_interface_format.md | 1 + docs/tutorials/custom_contracts/tezos.md | 129 +++++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/docs/reference/firefly_interface_format.md b/docs/reference/firefly_interface_format.md index 4d3eb12f1..64b6064c9 100644 --- a/docs/reference/firefly_interface_format.md +++ b/docs/reference/firefly_interface_format.md @@ -95,6 +95,7 @@ The type field here is the JSON input type when making a request to FireFly to i ### Schema details + The details field is quite important in some cases. Because the `details` field is passed to the blockchain plugin, it is used to encapsulate blockchain specific type information about a particular field. Additionally, because each blockchain plugin can add rules to the list of schema requirements above, a blockchain plugin can enforce that certain fields are always present within the `details` field. For example, the Ethereum plugin always needs to know what Solidity type the field is. It also defines several optional fields. A full Ethereum details field may look like: diff --git a/docs/tutorials/custom_contracts/tezos.md b/docs/tutorials/custom_contracts/tezos.md index eb5a297c3..d35dae3dd 100644 --- a/docs/tutorials/custom_contracts/tezos.md +++ b/docs/tutorials/custom_contracts/tezos.md @@ -90,6 +90,135 @@ Here we can see that our new contract address is `KT1ED4gj2xZnp8318yxa5NpvyvW15p As we know from the previous section - smart contracts on the Tezos blockchain are using the domain-specific, stack-based programming language called [Michelson](https://tezos.gitlab.io/active/michelson.html). It is a key component of the Tezos platform and plays a fundamental role in defining the behavior of smart contracts and facilitating their execution. This language is very efficient but also a bit tricky and challenging for learning, so in order to teach FireFly how to interact with the smart contract, we will be using [FireFly Interface (FFI)](../../reference/firefly_interface_format.md) to define the contract inteface which later will be encoded to Michelson. +### Schema details + +The `details` field is used to encapsulate blockchain specific type information about a specific field. (More details at [schema details](../../reference/firefly_interface_format.md#schema-details)) + +#### Supported Tezos types + +- nat +- integer +- string +- address +- bytes +- boolean +- variant +- list +- struct + +#### Internal type vs Internal schema + +internalType is a field which is used to describe tezos primitive types + +``` json +{ + "details": { + "type": "address", + "internalType": "address" + } +} +``` + +internalSchema in turn is used to describe more complex tezos types as list, struct or variant + +Struct example: + +``` json +{ + "details": { + "type": "schema", + "internalSchema": { + "type": "struct", + "args": [ + { + "name": "metadata", + "type": "bytes" + }, + { + "name": "token_id", + "type": "nat" + } + ] + } + } +} +``` + +List example: + +``` json +{ + "details": { + "type": "schema", + "internalSchema": { + "type": "struct", + "args": [ + { + "name": "metadata", + "type": "bytes" + }, + { + "name": "token_id", + "type": "nat" + } + ] + } + } +} +``` + +Variant example: + +``` json +{ + "details": { + "type": "schema", + "internalSchema": { + "type": "variant", + "variants": [ + "add_operator", + "remove_operator" + ], + "args": [ + { + "type": "struct", + "args": [ + { + "name": "owner", + "type": "address" + }, + { + "name": "operator", + "type": "address" + }, + { + "name": "token_id", + "type": "nat" + } + ] + } + ] + } + } +} +``` + +#### Options + +Option type is used to indicate a value as optional (see more at [smartpy options](https://smartpy.io/manual/syntax/options-and-variants#options)) + +``` json +{ + "details": { + "type": "string", + "internalType": "string", + "kind": "option" + } +} +``` + +### FA2 example + The following FFI sample demonstrates the specification for the widely used FA2 (analogue of ERC721 for EVM) smart contract: ```json