Cardinal-Cryptography / Cardinal-Cryptography/ink-wrapper

Generate ink traits out of contract's metadata.

Open
#53 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Rust
Stars
12
Forks
4
PR merge metrics
No merged PRs in 30d

Description

https://github.com/paritytech/ink/pull/1673 introduced macro (`ink::contract_ref!`) that generates a type-safe API of a contract out of its trait. The dependant trait has to be available during compilation for the macro to work. This is difficult for projects that want to depend on others without having access to all of their repository. In the future where on-chain contracts are verified, it will be easier to download contract's metadata files and generate API than pulling in all of the contracts code as our dependency.

This issue is a feature request to generate ink-compatible trait definitions out of contract's metadata.

-------

A more concrete example: imagine a project `my-contract` that needs to call something with `PSP22` interface. To do that right now, the project would have to look like this:
```
- psp22-traits
- - Cargo.toml
- - lib.rs
- my-contract
- - Cargo.toml
- - lib.rs
```
where `psp22-traits/lib.rs` defines the PSP22 trait:
```rust
#[ink::trait_definition]
trait PSP22 {
#[ink(message)]
pub fn balance_of(&self, account: AccountId) -> Balance

// other methods
}
```
`my-contract/Cargo.toml` needs to specify it as dependency:
```toml
psp22-traits = { path = "../psp22-traits" , default-features = false }
```
so that it can use type-safe API for PSP22:
```rust
let psp22_ref: ink::contract_ref!(PSP22) = (*reward_token).into();
let balance: Balance = psp22_ref.balance_of(Self::env().account_id());
```

If `ink-wrapper` was capable of generating ink trait definitions out of contract's metadata, the first part of the setup would go away and we'd be left with:
```
- my-contract
- - Cargo.toml
- - lib.rs
- - resources
- - - psp22_metadata.json
```
and in `my-contract/lib.rs` generate the ref
```rust

#[ink_wrapper::contract_ref("resources/psp22_metadata.json")]
mod psp22_trait;
// ...
let psp22_ref = psp22_trait::PSP22::from_account(*reward_token);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.