#cross #contract #shard #call #near #macro #response

calimero-sdk-macros

该库用于跨分片合约调用的主宏,用于NEAR和Calimero合约之间

1个不稳定版本

0.0.1 2023年3月1日

#11 in #shard


calimero-sdk中使用

GPL-3.0-only

8KB
111

用法

要指定合约将使用的跨分片调用合约连接器。在您的NEAR合约.rs文件中添加到顶部

calimero_cross_shard_connector!("xsc_connector.lal89.dev.calimero.testnet");

要触发跨调用,请执行此宏

calimero_cross_call_execute!(
    DESTINATION_CONTRACT_ID,
    DESTINATION_CONTRACT_METHOD,
    args,
    DESTINATION_GAS,
    DESTINATION_DEPOSIT,
    "game_started",
    CROSS_CALL_GAS
);

要指定从其他链接收响应的方法,请使用#[calimero_receive_response] proc_macro_attribute 此外,还需要在#[near_bindgen]之前调用#[calimero_expand],以便在NEAR合约上正确执行

例如:

#[calimero_expand]
#[near_bindgen]
impl MyContract {

    #[calimero_receive_response]
    pub fn foo(&mut self, arg1: Option<u64>) {
        if arg1.is_none() {
            // handle cross shard contract None response
            // e.g. panic!("Failed extracting response");
        } else {
            // arg1.unwrap() has the deserialized cross shard call execution result
            // code ...
        }
    }

    #[calimero_receive_response]
    pub fn bar(&mut self, bar_arg: usize) {
        // either panics or cross shard contract execution deserialized into bar_arg
        // code ...
    }
}

依赖项

~1.5MB
~35K SLoC