Crate fvm_macros

Source
Expand description

Provides the macros needed to write fvm contracts

§Basic Usage

Macros can be used in contract for simplify contract preparation process, like this:

use fvm_macros::contract;
use fvm_macros::storage;
use fvm_std::collections::hyper_map::HyperMap;

#[storage]
pub struct SetHash {
    map: HyperMap<String, String>,
}

#[contract]
impl SetHash {
    fn new() -> Self {
        Self { map: HyperMap::new() }
    }

    pub fn set_hash(&mut self, key: String, value: String) {
        self.map.insert(key, value);
    }

    pub fn get_hash(&mut self, key: String) -> &String {
        self.map.get(&key).unwrap()
    }
}

§Contract Mode

Now write contract have two mode:

  • normal mode

Contract with normal mode limited data storage format, and user can write contract more convenient. User can use all macros except advance_contract.

  • advance mode

Contract with advance mode not limited data storage format, and it must open advance feature with fvm-std and ‘fvm-macros’ lib to use this mode. The execute speed of contract in this mode would be fast then the contract in normal mode.

Attribute Macros§

advance_contract
Mark method implementation as advance contract method
contract
Mark method implementation as contract method
cross
Generate cross call attribute this macro has two ways to use.
parallel_call_method
Mark parallel call method
parallel_contract
Parallel level 1
parallel_cross
Used while cross call the parallel the attribute has three fields. address: cross contract address address_index: if address is empty, then you should declare the cross address in function params, this is the index of params. methods: the name of cross call the methods cns_name: CNS of contract. cns_index: CNS of contract index.
parallel_field
Parallel level 2 This attribute could have two fields. field_name and para_index. field_name point out which StoreField will parallel para_index the para index of this StoreField, used for HyperMap
storage
Generate storage attribute for struct