#cross #contract #call #shard #near #macro #calimero

calimero-sdk

通过桥梁在NEAR和Calimero之间进行跨分片合约调用的Rust便捷库

1 个不稳定版本

0.0.1 2023年3月1日

#9 in #shard

GPL-3.0-only

4KB

用法

要指定您的合约将使用的跨分片调用合约连接器,在您的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_receive_response

例如。

#[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