I am trying to figure out the way to set contract which has deferred transactions at run time from front-end.
Is it even doable?
Any suggestions would be appreciated.
-
from front-end meaning from a user-facing interface? you can just process the user input and trigger a transaction to a contract that has an action which handles deferred transactions – confused00 Jul 30 '18 at 14:18
-
Yes, from GUI. But if user has to provide the delay for deferred transaction, then don't we have to set a whole new contract or that already deployed contract can handle the dynamic delay? If yes, can you show me some piece of code how can I achieve that. – Rajat Chaudhary Jul 31 '18 at 5:32
-
can't you just pass the delay as an argument to the function? – confused00 Jul 31 '18 at 9:14
-
Yes, That's exactly what I am doing right now. Thanks for the clue. – Rajat Chaudhary Jul 31 '18 at 9:53
Add a comment
|
If I understand your question correctly, you can send a deferred transaction like you usually would but defining the delay as a function parameter:
void send(account_name account, std::string message, uint64_t delay) {
eosio::transaction t{};
t.actions.emplace_back(
eosio::permission_level(account, N(active)),
N(othercontract),
N(othermethod),
std::make_tuple(contractargs));
t.delay_sec = delay; // Here you set the delay dynamically
t.send(N(message), account);
}
};
you'd have to make sure you set the permissions right:
$ cleos set account permission account active '{"threshold": 1,"keys": [{"key": "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","weight": 1}],"accounts": [{"permission":{"actor":"contractaccount","permission":"eosio.code"},"weight":1}]}' owner -p account
and then you'd call the contract passing the delay at run-time
-
In your code above, I am little bit confused about
othercontract
,othermethod
,contractargs
._________othercontract
: is this the contract name?othermethod
: is this the action name defined in cpp file which we have to execute after the given delay?contractargs
: are they the arguments to theothermethod
action name? – Rajat Chaudhary Jul 31 '18 at 12:24 -
othercontract
is the contract to which you want to send a deferred transaction,othermethod
is the name of the action that you want to call,otherargs
are the arguments passed to that action. I wrote a skeleton for this somewhere else if it helps (without dynamic delay) – confused00 Jul 31 '18 at 12:41