Interface Implementation
Interface Implementation
From the previous sections, it has been illustrated that every encoded piece of a contract (such as Schema, States and Operation) and Interface are distinct entities that can be developed independently. In order to connect them, an additional piece of code is required. Interface Implementation represents a simple set of instructions that maps the semantics of the interfaces to the actual strict type data structure of the Schema.
As a distinctive characteristic, the Interface Implementation can explicitly map only a subset of the data structure or state operation both from the Schema side and from the Interface side. This way the interface implementation can restrict implicitly the functionality of some Schema from being accessed as well as it can restrict the use of some endpoints provided in the Interface.
In the following code section, we report the default Interface Implementation which associates Non-Inflatable Asset Schema to the RGB20 Interface. It is worth pointing out that the following piece of code is placed in the same file as the NIA Schema, but that doesn't represent a mandatory choice as even Interface Implementation can be developed independently from both Schema and Interfaces.
As we can see from the block code above, the Interface Implementation:
References the Schema,
nia_schema()
, and Interface,Rgb20::iface()
and commit to them throughschema.schema_id()
andiface.iface_id()
statements.Contains a map between the strict type data structure of the contract (e.g.
GS_NOMINAL
,GS_DATA,
etc.) to those of the Interface defined viafname!
statement (e.g."spec"
,"data"
, etc). The same type of mapping is performed for contract operations, in this caseTS_TRANSFER
is mapped to"Transfer"
.
The Interface Implementation is compiled separately from Schema and Interface producing a separate .rgb
or .rbga
file, which can then be imported in the wallet.
Last updated