Add TZIP-016 (Contract Metadata) implementation (library + tezos-client)
This is an implementation of
tzip-16.md
as a pure-ish-OCaml library tezos-contract-metadata
and a few new commands for
tezos-client
.
The tezos-contract-metadata
library and a few of its dependencies library are
used by TZComet client-side with
js_of_ocaml
; that explains some extra parametrization in the API and the
fact that the implementation tries to stay as much as possible on the Micheline
side (this also avoids even more code duplication in protocol-dependent code, see below).
The real git history of this work is still available in this branch:
smondet/tezos!7 (closed). It is
transformed into a linear fake history with tzip16-merge-request.sh
which can
be found at this
gist.
New Client Commands
-
get contract metadata schema [--with-examples] [--output <PATH>]
-
get metadata for contract <src> [--format <FORMAT>] [--output <PATH>] [--validate <BOOL>]
- where format is: 'text', 'text:short', 'text:full', 'raw', or 'json'.
get metadata element <key> from <src>
call-off-chain-view <name> from <contract> [--output <PATH>] [--json] [--arg <MICHELSON>]
Examples
Fetch and display the metadata for a contract:
$ tezos-client --endpoint https://delphinet.SmartPy.io:443 \
get metadata for contract KT1J158fCCVKJzH8pXi8FDGR4j5LrA6DANPB \
--format text:short | head -n 30
Contract-Metadata-TZIP-16:
Description: This is a didactic reference implementation of FA2, a.k.a.
TZIP-012, using SmartPy.
This particular contract uses the configuration named: FA2-mutez.
It is “The default with mutez transfer entry-point.”
Version: version_20201222_tzip_330b33a_mutran_contract
Authors: Seb Mondet <https://seb.mondet.org>
Homepage: https://gitlab.com/smondet/fa2-smartpy
Source:
Tools:
["SmartPy releases/20201120-0e11eab499f3fc5a3aef0abb35a0dde20810eff7",
"Flextesa", "Dune", "Fatoo"] Location:
https://gitlab.com/smondet/fa2-smartpy/-/tree/50a2d58-dirty/
Interfaces: TZIP-012-2020-12-24
Views:
View "get_balance" (This is the `get_balance` view defined in TZIP-12.):
Michelson-storage:
Parameter: '(pair (nat %token_id) (address %owner))'
Return-type: 'nat'
Annotations:
View "token_metadata"
(
Return the token-metadata URI for the given token.
For a reference implementation, dynamic-views seem to be the
most flexible choice.
):
Michelson-storage:
Call an off-chain-view provided by the contract:
$ tezos-client --endpoint https://delphinet.SmartPy.io:443 \
call-off-chain-view get_balance \
from KT1J158fCCVKJzH8pXi8FDGR4j5LrA6DANPB \
--arg '(Pair 0 "tz1TPMLao12CbmrxCzuM6tQpAZcw1hVciW4d")'
20000
You can checkout that same contract fully on TZComet: KT1J158fCCVKJzH8pXi8FDGR4j5LrA6DANPB.
Test
The automatic tests use Tezt and the mockup-client.
Some improvements are made to Tezt, including the update of the relevant protocols (remove Carthage and add Edo).
They run all “active” protocols, which doesn't seem like the norm with tezt (why?).
Help For Reviewers
This MR adds a bunch of protocol-client code, so of course there is a bunch of code duplication between the protocols.
So here are interesting diffs between the various files in the client-commands libraries (all computed by the same gist):
Diff between: {src/proto_006_PsCARTHA,src/proto_007_PsDELPH1}/lib_client_commands/alpha_commands_registration.ml
⇒ Empty!
Diff between: {src/proto_006_PsCARTHA,src/proto_007_PsDELPH1}/lib_client_commands/contract_metadata_commands.ml
⇒ Empty!
Diff between: {src/proto_alpha,src/proto_007_PsDELPH1}/lib_client_commands/alpha_commands_registration.ml
37d36
< @ Client_sapling_commands.commands ()
→ Only sapling was added by Edo (master branch).
Diff between: {src/proto_alpha,src/proto_007_PsDELPH1}/lib_client_commands/contract_metadata_commands.ml
47,49c47
< ?gas:None
< ~data
< ~ty:typ
---
> (data, typ, None)
117,120c115
< get_big_map_string_at_string
< cctxt
< (Protocol.Alpha_context.Big_map.Id.parse_z one)
< ~key
---
> get_big_map_string_at_string cctxt one ~key
554,555d548
< ~balance:Alpha_context.Tez.zero
< (* Balance has been fixed by build_off_chain_view_contract *)
→ A couple of RPC arguments changed.
Diff between: {src/proto_alpha,src/proto_008_PtEdoTez}/lib_client_commands/alpha_commands_registration.ml
⇒ Empty!
Diff between: {src/proto_alpha,src/proto_008_PtEdoTez}/lib_client_commands/contract_metadata_commands.ml
⇒ Empty!
Manually testing the MR
Try the commands on contract that have some TZIP-016 metadata.
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Provide automatic testing (see the testing guide). -
Add item in the Development Version
section ofCHANGES.md
(only for new features and bug fixes).
Reviewers
@rafoo_ → client / michelson stuff
@romain.nl → Tezt