Attribute Macro stellar_axelar_std_derive::contractimpl

source ·
#[contractimpl]
Expand description

Designates functions in an impl block as contract entrypoints.

This is a wrapper around the soroban-sdk’s #[contractimpl] attribute. It adds additional checks to ensure entrypoints don’t get accidentally, or maliciously, called after a contract upgrade, but before the data migration is complete.

§Example

use stellar_axelar_std_derive::{contractimpl, Upgradable};

#[contract]
#[derive(Upgradable)]
pub struct Contract;

// any function in this impl block will panic if called during migration
#[contractimpl]
impl Contract {
    pub fn __constructor(env: &Env) {
        // constructor code
    }

    pub fn do_something(env: &Env, arg: String) {
        // entrypoint code
    }
}

#[contracterror]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum ContractError {
    MigrationInProgress = 1,
}

// if an entrypoint is able to return a Result<_, ContractError>,
// it will return ContractError::MigrationInProgress instead of panicking when called during migration
#[contractimpl]
impl Contract {
    pub fn return_result(env: &Env, arg: String) -> Result<u32, ContractError> {
        // entrypoint code
    }
}