mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Implemented sending contract output back to the user.
This commit is contained in:
46
src/main.cpp
46
src/main.cpp
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user