Implemented sending contract output back to the user.

This commit is contained in:
Ravin Perera
2019-10-16 17:26:33 +05:30
parent 8b003aeaa2
commit 8a22748c8d
7 changed files with 121 additions and 44 deletions

View File

@@ -103,21 +103,41 @@ int main(int argc, char **argv)
// This will start hosting the contract and start consensus rounds.
// TODO
// Temp code to avoid exiting.
std::string s;
std::cin >> s;
// Test code to execute contract and collect outputs.
std::unordered_map<std::string, std::pair<std::string, std::string>> userbufs;
for (auto &[sid, user] : usr::users)
while (true)
{
std::pair<std::string, std::string> bufpair;
bufpair.first = std::move(user.inbuffer);
userbufs[user.pubkey] = bufpair;
}
sleep(1);
// Test code to execute contract and collect outputs.
std::unordered_map<std::string, std::pair<std::string, std::string>> userbufs;
for (auto &[sid, user] : usr::users)
{
std::pair<std::string, std::string> bufpair;
proc::ContractExecArgs eargs(123123345, userbufs);
proc::exec_contract(eargs);
std::string inputtosend;
inputtosend.swap(user.inbuffer);
bufpair.first = std::move(inputtosend);
userbufs[user.pubkey] = bufpair;
}
proc::ContractExecArgs eargs(123123345, userbufs);
proc::exec_contract(eargs);
for (auto &[pubkey, bufpair] : userbufs)
{
if (!bufpair.second.empty())
{
// Find the user session id by the pubkey.
const std::string sessionid = usr::sessionids[pubkey];
// Find the user by session id.
auto itr = usr::users.find(sessionid);
const usr::connected_user &user = itr->second;
user.session->send(std::move(bufpair.second));
}
}
userbufs.clear();
}
// Free resources.
usr::deinit();