mirror of https://github.com/oxen-io/oxen-core.git
add daemon comms submit tx endpoint
TODO: more complete response handling
This commit is contained in:
parent
e42cc7c79b
commit
eb8f4a51a6
|
@ -4,6 +4,11 @@
|
|||
#include <memory>
|
||||
#include <future>
|
||||
|
||||
namespace cryptonote
|
||||
{
|
||||
struct transaction;
|
||||
}
|
||||
|
||||
namespace wallet
|
||||
{
|
||||
class Wallet;
|
||||
|
@ -44,6 +49,9 @@ namespace wallet
|
|||
// available and simply pick numbers between the indexes according to our distribution function.
|
||||
virtual std::future<std::vector<Decoy>>
|
||||
fetch_decoys(const std::vector<int64_t>& indexes) = 0;
|
||||
|
||||
virtual std::future<std::string>
|
||||
submit_transaction(const cryptonote::transaction& tx, bool blink) = 0;
|
||||
};
|
||||
|
||||
} // namespace wallet
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "block.hpp"
|
||||
#include "block_tx.hpp"
|
||||
|
||||
#include <cryptonote_basic/cryptonote_format_utils.h>
|
||||
#include <common/string_util.h>
|
||||
#include <epee/misc_log_ex.h>
|
||||
#include "oxenmq/oxenmq.h"
|
||||
|
@ -365,6 +366,56 @@ namespace wallet
|
|||
return fut;
|
||||
}
|
||||
|
||||
std::future<std::string>
|
||||
DefaultDaemonComms::submit_transaction(const cryptonote::transaction& tx, bool blink)
|
||||
{
|
||||
auto p = std::make_shared<std::promise<std::string> >();
|
||||
auto fut = p->get_future();
|
||||
auto req_cb = [p=std::move(p)](bool ok, std::vector<std::string> response)
|
||||
{
|
||||
// TODO: handle various error cases.
|
||||
if (not ok or response.size() != 2 or response[0] != "200")
|
||||
{
|
||||
p->set_value("Unknown Error");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
oxenmq::bt_dict_consumer dc{response[1]};
|
||||
if (not dc.skip_until("reason"))
|
||||
{
|
||||
p->set_value("Invalid response from daemon");
|
||||
return;
|
||||
}
|
||||
auto reason = dc.consume_string();
|
||||
|
||||
if (not dc.skip_until("status"))
|
||||
{
|
||||
p->set_value("Invalid response from daemon");
|
||||
return;
|
||||
}
|
||||
|
||||
auto status = dc.consume_string();
|
||||
|
||||
if (status == "OK")
|
||||
p->set_value("OK");
|
||||
else
|
||||
p->set_value(std::string("Something getting wrong.") + reason);
|
||||
}
|
||||
};
|
||||
|
||||
auto tx_str = tx_to_blob(tx);
|
||||
|
||||
oxenmq::bt_dict req_params_dict;
|
||||
|
||||
req_params_dict["tx"] = tx_str;
|
||||
req_params_dict["blink"] = blink;
|
||||
|
||||
omq->request(conn, "rpc.submit_transaction", req_cb, oxenmq::bt_serialize(req_params_dict));
|
||||
|
||||
return fut;
|
||||
}
|
||||
|
||||
void
|
||||
DefaultDaemonComms::register_wallet(wallet::Wallet& wallet, int64_t height, bool check_sync_height)
|
||||
{
|
||||
|
|
|
@ -50,6 +50,9 @@ namespace wallet
|
|||
std::future<std::vector<Decoy>>
|
||||
fetch_decoys(const std::vector<int64_t>& indexes);
|
||||
|
||||
std::future<std::string>
|
||||
submit_transaction(const cryptonote::transaction& tx, bool blink);
|
||||
|
||||
private:
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue