Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add client entity to smart contracts #5073

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

mversic
Copy link
Contributor

@mversic mversic commented Sep 13, 2024

Context

  • introduce a host handle that smart contract writers use to interact with the host environment
  • introduce context of the execution that every smart contract is given (in the future this should be header of the block that is currently executing)
  • change all smart contract functions to receive (host, context)
  • rename Validate trait to Execute

Closes #4898

Migration guide

  • this is a breaking change for all smart contracts

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);
}

@mversic mversic force-pushed the wasm_client branch 3 times, most recently from c27b520 to b1328d9 Compare September 13, 2024 02:11
@github-actions github-actions bot added the api-changes Changes in the API for client libraries label Sep 13, 2024
@mversic mversic force-pushed the wasm_client branch 3 times, most recently from 7e6885c to 8cec7c0 Compare September 13, 2024 10:57
@mversic mversic assigned mversic, DCNick3 and 0x009922 and unassigned 0x009922 Sep 15, 2024
@Erigara Erigara self-assigned this Sep 19, 2024
Copy link
Contributor

@Erigara Erigara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since this is breaking change for smart-contracts, migration guide should be provided.

wasm_samples/executor_remove_permission/src/lib.rs Outdated Show resolved Hide resolved
wasm_samples/mint_rose_trigger/src/lib.rs Show resolved Hide resolved
@DCNick3
Copy link
Contributor

DCNick3 commented Sep 27, 2024

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

@DCNick3
Copy link
Contributor

DCNick3 commented Sep 27, 2024

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

Signed-off-by: Marin Veršić <marin.versic101@gmail.com>
@mversic mversic merged commit 7473d04 into hyperledger-iroha:main Oct 9, 2024
14 checks passed
@mversic mversic deleted the wasm_client branch October 9, 2024 08:05
@alexstroke1 alexstroke1 self-assigned this Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-changes Changes in the API for client libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce a client-like object for smart contracts
5 participants