Skip to content

btn-group/az_smart_contract_hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AZ Smart Contract Hub

A smart contract that allows the decentralised sharing of smart contract info:

pub struct SmartContract {
    id: u32,
    smart_contract_address: AccountId,
    chain: u8,
    caller: AccountId,
    enabled: bool,
    azero_id: String,
    abi_url: String,
    contract_url: Option<String>,
    wasm_url: Option<String>,
    audit_url: Option<String>,
    group_id: Option<u32>,
    project_name: Option<String>,
    project_website: Option<String>,
    github: Option<String>,
}

A use case is the easing of development and auditing by allowing users to easily access abis to use in Substrate Contracts UI, smart contracts and front end dapp development.

Rules & notes

Creating a smart contract record:

  • Chain will be left as type u8 to account for new testnets that may appear. Production will be 0 and Testnet will be 1.
  • Caller must own an AZERO.ID and associate it with a record.
  • A link to the abi_url (metadata.json) must be provided. In an ideal world, the link would be directed at the location of the smart contract's metadata.json on a CDN.
  • If a group_id is provided, the caller must be a member of that group.
  • The smart contract record is enabled by default.
  • There is a fee to create which is sent to the admin.
fn create(
    &mut self,
    smart_contract_address: AccountId,
    chain: u8,
    azero_id: String,
    abi_url: String,
    contract_url: Option<String>,
    wasm_url: Option<String>,
    audit_url: Option<String>,
    group_id: Option<u32>,
    project_name: Option<String>,
    project_website: Option<String>,
    github: Option<String>,
) -> Result<SmartContract> {

Updating a smart contract record:

  • Can only update own smart contract records.
  • Caller must own an AZERO.ID and associate it with a record. This means that if a user relinquishes the original azero_id, they must associate a new one on update.
  • If a group_id is provided, the caller must be a member of that group.
  • Some fields are unable to be updated for security purposes. If some fields are incorrect and are unable to be changed, the user should disable the record and create a new one.
fn update(
    &mut self,
    id: u32,
    enabled: bool,
    azero_id: String,
    group_id: Option<u32>,
    audit_url: Option<String>,
    project_name: Option<String>,
    project_website: Option<String>,
    github: Option<String>,
) -> Result<SmartContract> {

Getting Started

Prerequisites

cargo install --git https://github.com/paritytech/cargo-contract cargo-contract --force

Checking code

cargo checkmate
cargo sort

Testing

A combination of unit tests and integration tests are present. Integration tests were written mainly to test interactions with the AZ Groups smart contract. Integration tests with the AZERO.ID router could not be written as that contract is private. Different scenarios that could happen while interacting with the AZERO.ID router are simulated with mock addresses and domains that can't exist in production.

Run unit tests

cargo test

Run integration tests

export CONTRACTS_NODE="/Users/myname/.cargo/bin/substrate-contracts-node"
cargo test --features e2e-tests

Deployment

  1. Build contract:
# You may need to run
# chmod +x build.sh f
./build.sh
  1. If setting up locally, start a local development chain.
substrate-contracts-node --dev
  1. Upload, initialise and interact with contract at Contracts UI.

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published