【问题标题】:Is there a way to call NonFungibleTokenCore from an external contract in NEAR using ext_contract?有没有办法使用 ext_contract 从 NEAR 中的外部合约调用 NonFungibleTokenCore?
【发布时间】:2021-11-04 19:21:32
【问题描述】:

我正在使用在依赖特征 NonFungibleTokenCore 上调用的函数,我想使用 ext_contract 的便利包装器来简化跨合约调用。

这是我添加它的尝试:

#[ext_contract(ext_non_fungible_token)]
trait NFTCore: NonFungibleTokenCore {}

来自:https://github.com/roshkins/sputnik-dao-contract/blob/nft-tokensv4/sputnik-nft-staking/src/lib.rs#L18

我使用rust-analyzer 的代码完成不提供任何完成。当我构建它时,我得到了这个错误:

error[E0425]: cannot find function `nft_transfer` in module `ext_non_fungible_token`
   --> sputnik-nft-staking/src/lib.rs:151:33
    |
151 |         ext_non_fungible_token::nft_transfer(sender_id.clone(), token_id.clone(), 0, None,
    |                                 ^^^^^^^^^^^^ not found in `ext_non_fungible_token`

您对如何正确使用宏有任何想法吗?

【问题讨论】:

    标签: rust rust-cargo cryptocurrency near-sdk-rs


    【解决方案1】:

    不幸的是,ext_contract proc 宏只知道该块内的代码,无法根据NonFungibleTokenCore 的 Supertrait 定义的方法生成代码,此处为https://github.com/roshkins/sputnik-dao-contract/blob/bc8398257cdbee248fdd6301af0dc41a9b7c5236/sputnik-nft-staking/src/lib.rs#L18

    目前,您必须重新定义界面,但我会询问是否有更简洁的方法来做到这一点。

    这样的事情可能会解决你眼前的问题:

    #[ext_contract(ext_non_fungible_token)]
    trait NonFungibleTokenCore {
        fn nft_transfer(
            &mut self,
            receiver_id: AccountId,
            token_id: TokenId,
            approval_id: Option<u64>,
            memo: Option<String>,
        );
        fn nft_transfer_call(
            &mut self,
            receiver_id: AccountId,
            token_id: TokenId,
            approval_id: Option<u64>,
            memo: Option<String>,
            msg: String,
        ) -> PromiseOrValue<bool>;
        fn nft_token(&self, token_id: TokenId) -> Option<Token>;
    }
    

    【讨论】:

      猜你喜欢
      • 2022-10-12
      • 2011-04-27
      • 2021-03-26
      • 2020-11-08
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 2021-08-01
      • 1970-01-01
      相关资源
      最近更新 更多