#include <eosiolib/eosio.hpp>
#include <eosiolib/asset.hpp>
using namespace eosio;

class allowancesample : public eosio::contract
{
  public:
    using contract::contract;

    /// @abi action
    void allow(account_name sender, account_name allowed, asset quantity)
    {
        require_auth(sender);

        allowancetable allowances(_self, sender);

        auto iter = allowances.find(allowed);
        if (iter == allowances.end())
            allowances.emplace(sender, [&](auto &row) {
                row.allowed = allowed;
                row.quantity = quantity;
            });
        else
            allowances.modify(iter, 0, [&](auto &row) {
                row.quantity = quantity;
            });
    }

  private:
    /// @abi table
    struct allowance
    {
        account_name allowed;
        asset quantity;
        auto primary_key() const { return allowed; }

        EOSLIB_SERIALIZE(allowance, (allowed)(quantity))
    };

    typedef multi_index<N(allowance), allowance> allowancetable;
};

EOSIO_ABI(allowancesample, (allow))

  • EOS

    第三代区块链到来了?赶紧学习 EOS 智能合约吧

    3 引用 • 3 回帖
  • 智能合约

    智能合约(英语:Smart contract )是一种旨在以信息化方式传播、验证或执行合同的计算机协议。

    20 引用 • 9 回帖
  • 额度
    1 引用
感谢    赞同    分享    收藏    关注    反对    举报    ...