EOS自动的延迟转账

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yhc166188/article/details/82830722

transaction 里面有一个 delay_sec 的参数,默认是0,可以通过自定义实现延迟EOS转账。
具体代码可以查看 contracts/eosiolib/transaction.hpp
我们通过写一个新的合约,实现延时转账的 send 功能

void send(account_name from, account_name to, asset amount, string memo, uint64_t delay) {
    eosio::transaction t{};
    t.actions.emplace_back(
    eosio::permission_level(from, N(active)), // with `from@active` permission
    N(eosio.token), // You're sending this to `eosio.token`
    N(transfer),   // to their `transfer` action
    std::make_tuple(from, to, amount, memo));  // with the appropriate args
    t.delay_sec = delay; // Set the delay
    t.send(eosio::string_to_name(memo.c_str()), from); // Send the transaction with some ID derived from the memo
    }
};

最后需要记得对发送者账户进行权限设置,让该合约有权限进行转账操作。

参考:https://eosio.stackexchange.com/questions/1900/how-to-transfer-eos-after-a-particular-delay

$ cleos set account permission <sender-account> active '{"threshold": 1,"keys": [{"key": "<sender-pubkey>","weight": 1}],"accounts": [{"permission":{"actor":"<contract-account>","permission":"eosio.code"},"weight":1}]}' owner -p <sender-account>

猜你喜欢

转载自blog.csdn.net/yhc166188/article/details/82830722
eos