【问题标题】:What does payable decorator in near-sdk-rs do?Near-sdk-rs 中的应付装饰器有什么作用?
【发布时间】:2021-03-10 00:26:42
【问题描述】:

文档说:

付款方式。我们可以允许方法接受代币转移 连同函数调用。这样做是为了让合同可以 定义使用时需要支付的代币费用。经过 默认情况下,这些方法是不支付的,如果有人会惊慌 将在调用期间尝试将令牌转移给他们。这是 出于安全原因,以防有人意外转移代币 在函数调用期间。

https://github.com/near/near-sdk-rs

这里的token是不是只指native near tokens?

为什么这个功能必须支付?支付附近的代币用于存储?

/// Transfer `amount` of tokens from the caller of the contract (`predecessor_id`) to
/// `new_owner_id`.
/// Act the same was as `transfer_from` with `owner_id` equal to the caller of the contract
/// (`predecessor_id`).
/// Requirements:
/// * Caller of the method has to attach deposit enough to cover storage difference at the
///   fixed storage price defined in the contract.
#[payable]
pub fn transfer(&mut self, new_owner_id: AccountId, amount: U128) {
    // NOTE: New owner's Account ID checked in transfer_from.
    // Storage fees are also refunded in transfer_from.
    self.transfer_from(env::predecessor_account_id(), new_owner_id, amount);
}

https://github.com/near-examples/FT/blob/master/contracts/rust/src/lib.rs#L211

【问题讨论】:

    标签: nearprotocol


    【解决方案1】:

    这里的token是不是只指native near tokens?

    是的

    为什么这个功能必须支付?支付附近的代币用于存储?

    如果您希望此功能能够接受存款。押金如何使用由合同决定。

    【讨论】:

      猜你喜欢
      • 2021-01-12
      • 1970-01-01
      • 2021-06-13
      • 1970-01-01
      • 2012-01-09
      • 2014-04-09
      • 2022-01-22
      • 1970-01-01
      • 2016-11-25
      相关资源
      最近更新 更多