Last active
July 23, 2018 09:34
-
-
Save cookie-ag/c3915fc27dacc5ef8b47bd1b3b72531e to your computer and use it in GitHub Desktop.
Communication Models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------- | |
test.hpp | |
----------------------------- | |
#ifndef TEST_HPP | |
#define TEST_HPP | |
#include <eosiolib/asset.hpp> | |
#include <eosiolib/eosio.hpp> | |
#include <eosiolib/transaction.hpp> | |
using namespace eosio; | |
class test: public contract { | |
public: | |
//@abi action | |
test(account_name _self): contract(_self) {} | |
void func(); | |
}; | |
#endif | |
----------------------------- | |
test.cpp | |
----------------------------- | |
#include "test.hpp" | |
void test::func() { | |
require_auth(_self); | |
transaction out{}; | |
out.actions.emplace_back( | |
permission_level {_self,N(active)}, | |
N(transfer), | |
std::make_tuple(transfer.id) | |
); | |
out.delay_sec = 10; | |
out.send(transfer.id, _self); | |
/* | |
// Another Way to do a deferred transaction | |
send_deferred( | |
(sender_id, | |
payer, | |
serialize.data(), | |
serialize.size(), | |
replace_existing | |
); | |
*/ | |
} | |
EOSIO_ABI(test,(func)) | |
----------------------------- | |
Calling the action via Cleos | |
----------------------------- | |
cleos --wallet-url http://localhost:8899 -u http://localhost:8788 set account permission test active '{"threshold":1,"keys":[{"key":"EOS5BL1oic5zZfefS681xPKgBGH8cE6f3FiMCoB2gfqDpu15fy7sY","weight":1}],"accounts":[{"permission":{"actor":"test","permission":"eosio.code"},"weight":1}],"waits":[]}' owner -p test -x 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------- | |
test.hpp | |
----------------------------- | |
#ifndef TEST_HPP | |
#define TEST_HPP | |
#include <eosiolib/asset.hpp> | |
#include <eosiolib/eosio.hpp> | |
using namespace eosio; | |
class test: public contract { | |
public: | |
//@abi action | |
test(account_name _self): contract(_self) {} | |
void func(); | |
}; | |
#endif | |
----------------------------- | |
test.cpp | |
----------------------------- | |
#include "test.hpp" | |
void test::func() { | |
require_auth(_self); | |
action( | |
permission_level {_self,N(active)}, | |
N(eosio.token),N(transfer), | |
std::make_tuple(_self,N(eosio.token),asset(10000,symbol_type(S(4,SYS))),std::string("")) | |
).send(); | |
} | |
EOSIO_ABI(test,(func)) | |
----------------------------- | |
Calling the action via Cleos | |
----------------------------- | |
cleos --wallet-url http://localhost:8899 -u http://localhost:8788 set account permission test active '{"threshold":1,"keys":[{"key":"EOS5BL1oic5zZfefS681xPKgBGH8cE6f3FiMCoB2gfqDpu15fy7sY","weight":1}],"accounts":[{"permission":{"actor":"test","permission":"eosio.code"},"weight":1}],"waits":[]}' owner -p test -x 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment