Skip to content

chikai-io/contract-interface

Repository files navigation

Near Contract Interface

This is a WIP fork of near-sdk-macros that enables generics for Near contracts.

Motivation

Please see near-sdk-rs#606 and the following features for more details.

Features

  • Generics for traits, impls and structs (WIP) - #5
  • Public items (WIP) - #14
  • Builder-pattern for making requests (WIP) - #4
  • Wasm extern functions (WIP) - #12
  • Named arguments (WIP) - #10
  • Metadata gathering/exporting (design) - #1

Dev Hints

Documentation

As this library makes heavy usage of generated modules, it is always recommended to see the documentation of your project in order to know about the generated items, such as with:

cargo doc --no-deps --open -p contract-interface -p contract-standards

Then on the bottom-left you'll find the docs of both contract-interface and contract-standards, and also from other packages that you may want to add.

Rust-Analyzer

If you're visualizing/editing them on vscode with rust-analyzer, to best see the autocompletion hints and documentation of various items, the following settings are recommended:

settings.json

"rust-analyzer.procMacro.enable": true,
"rust-analyzer.experimental.procAttrMacros": true,
"rust-analyzer.checkOnSave.allTargets": true,
"rust-analyzer.checkOnSave.command": "clippy",

Examples

Fungible Token

Please check it's workspace to read more about testing it.
As it has it's own workspace, instead of viewing it from this root directory you should check/experiment on it on a separated workspace editor, such as with code ./examples/fungible-token/ or similar commands.

Dummy Examples

All other examples are currently dummy and drafty, where all method implementations are unimplemented!() but they otherwise are able to compile and showcase some usages of the #[contract] attribute.
They are also contained in the root workspace, so you don't need to open a separated editor for them.

Documentation

Also, to see a dummy example's documentation, such as of example_01, you can use:

cargo doc -p contract-standards -p contract-interface --no-deps --example example_01 --open

Dummy Example Files

  • example_01:
    Has methods that have different cases of self.
    Uses a generated builder for making external calls.
    For the motivation on this, please check #4 and #14.
    Shows manually and automatically created extern "C" functions for the binary.
  • example_02:
    Has traits that use many types of generics (all dummy usages).
    Shows manually and automatically created extern "C" functions for the binary.
    Note that all generics must be known or defined at that time.
  • example_03:
    Has a contract that contains a FungibleToken from the standard. Shows manually and automatically created extern "C" functions for the binary.
  • example_04:
    Has methods that have some argument diversity,
    such as receiving references. Shows manually and automatically created extern "C" functions for the binary.
  • example_05:
    Has methods that use some attributes, such as init and such). Shows manually and automatically created extern "C" functions for the binary.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages