hyperledger-iroha / iroha

Iroha - A simple, enterprise-grade decentralized ledger
https://wiki.hyperledger.org/display/iroha
Apache License 2.0
438 stars 280 forks source link

refactor: add client entity to smart contracts #5073

Closed mversic closed 2 weeks ago

mversic commented 1 month ago

Context

Closes #4898

Migration guide

Smart contract

Previous API:

#[iroha_smart_contract::main]
fn main(owner: AccountId) {
}

New API:

#[iroha_smart_contract::main]
fn main(host: Iroha, context: Context) {
}

Trigger

Previous API:

#[iroha_trigger::main]
fn main(id: TriggerId, owner: AccountId, event: EventBox) {
    let EventBox::ExecuteTrigger(event) = event else {
        dbg_panic("Only work as by call trigger");
    };

    let rose_id = AssetId::new("rose#wonderland".parse().unwrap(), owner);
    let val: u32 = query_single(FindTriggerMetadata::new(id, "VAL".parse().unwrap()))
}

New API:

#[iroha_trigger::main]
fn main(host: Iroha, context: Context) {
    let EventBox::ExecuteTrigger(event) = context.event else {
        dbg_panic("Only work as by call trigger");
    };

    let rose_id = AssetId::new("rose#wonderland".parse().unwrap(), context.authority);
    let val: u32 = host
        .query_single(FindTriggerMetadata::new(context.id, "VAL".parse().unwrap()))
        .dbg_unwrap()
        .try_into_any()
        .dbg_unwrap();
}

Executor

Previous API:

#[entrypoint]
fn migrate(block_height: u64) {
    Executor::ensure_genesis(block_height);
    DataModelBuilder::with_default_permissions().build_and_set();
}

New API:

#[entrypoint]
fn migrate(host: Iroha, context: Context) {
    Executor::ensure_genesis(context.block_height);
    DataModelBuilder::with_default_permissions().build_and_set(&host);
}
DCNick3 commented 4 weeks ago

The docs for iroha_trigger_derive::main and iroha_smart_contract_derive::main are out of date now

DCNick3 commented 4 weeks ago

And a migration guide for other kinds of entry points should be provided (smart contracts, executor's validate and migrate entrypoints)