1
#include <eosiolib/eosio.hpp>
#include <eosiolib/transaction.hpp>
#include <lib/user.h>
using namespace eosio;
using namespace user;
class hello : public eosio::contract {
  public:
      using contract::contract;

     // @abi action 
      void hi( account_name user ) {
       print( "Hello, ", name{user} );
    }
    //@abi action
     void signup(uuid_t Id, string Name,string mobileNum,uint64_t password,uint64_t gender)
    {
     tableUsrde_t user(_self, _self);
    transaction out{};
        out.actions.emplace_back(permission_level{N(tester), N(active)}, N(tester), N(hello), std::make_tuple(0xff));
        out.delay_sec = 10;
        out.send(0xff,N(tester));
            user.emplace(_self,[&](auto& record){
                record.userId = Id;
                record.userName = Name;
                record.usermobileNum =mobileNum;
                record.userpassword = password;
                record.usergender =gender;

            });
    }

};

EOSIO_ABI( hello, (hi)(signup))

and

typedef uint64_t    uuid_t;
typedef int8_t     positionType_t;
using namespace std;    
namespace  user{
    //@abi table tableuserdet i64
    struct tableUsrdet{
        uuid_t userId;
        string userName;
        string usermobileNum;
        uint64_t userpassword;
        uint64_t usergender;
        uuid_t primary_key() const {return userId;}
        EOSLIB_SERIALIZE(tableUsrdet,(userId)(userName)(usermobileNum)(userpassword)(usergender))
    };    
    typedef eosio::multi_index<N(tableuserdet),tableUsrdet > tableUsrde_t;
}

1) My requirement is a such way that signin action execute after 10 sec when I call cleos push action

2) But currently cleos push action run without delay

I dont know how deferred action work ? Is there any example or doc ? Please suggest

2
  • 3
    I suggest you edit the question and indent it using Markdown format so that the code bits become readable. Commented Jun 22, 2018 at 9:15
  • you need scheduled transaction
    – Jimmy Guo
    Commented Jun 23, 2018 at 10:43

1 Answer 1

1

What's tester and tester::hello() looking like? Your code may look ok or not depending on how those are implemented. Any small error may result in the whole thing failing with no helpful error message.

Here's a full example of something that works on my machine fine:

sender.cpp

#include<eosiolib/eosio.hpp>
#include<eosiolib/transaction.hpp>
#include<string>

class sender : eosio::contract {
    public:
        sender (account_name account) : eosio::contract(account) {}

        void send(account_name account, std::string message) {

            eosio::transaction t{};
            t.actions.emplace_back(
                eosio::permission_level(account, N(active)),
                N(recipient),
                N(receive),
                std::make_tuple(message));
            t.delay_sec = 5;
            t.send(N(message), account);
        }
};

EOSIO_ABI(sender, (send))

recipient.cpp

#include<eosiolib/eosio.hpp>
#include<string>

class recipient : eosio::contract {
    public:
        recipient(account_name account) : eosio::contract(account) {}

        void receive(std::string message) {
            eosio::print(message);
        }
};

EOSIO_ABI(recipient, (receive))

cleos

$ cleos wallet unlock
$ cleos wallet keys
[
    "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
]
$ cleos account create eosio sender EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
$ cleos account create eosio recipient EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
$ cleos account create eosio controller EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
$ cleos set contract sender contracts/sender
$ cleos set contract recipient contracts/recipient
$ cleos set account permission controller active '{"threshold": 1,"keys": [{"key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","weight": 1}],"accounts": [{"permission":{"actor":"sender","permission":"eosio.code"},"weight":1}]}' owner -p controller
$ cleos push action sender send '["controller", "my_message"]' -p controller

The message should show up in nodeos output assuming it's configured with contracts-console=true

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.