mirror of https://github.com/oxen-io/oxen-core.git
rename wallet3 functions to be more in line with the rest of the codebase
This commit is contained in:
parent
089ddd0e72
commit
b85c01ba60
|
@ -247,7 +247,7 @@ omq_rpc::omq_rpc(cryptonote::core& core, core_rpc_server& rpc, const boost::prog
|
|||
}
|
||||
|
||||
omq.add_request_command("rpc", "get_blocks", [this](oxenmq::Message& m) {
|
||||
OnGetBlocks(m);
|
||||
on_get_blocks(m);
|
||||
});
|
||||
|
||||
// Subscription commands
|
||||
|
@ -257,11 +257,11 @@ omq_rpc::omq_rpc(cryptonote::core& core, core_rpc_server& rpc, const boost::prog
|
|||
omq.add_category("sub", AuthLevel::basic);
|
||||
|
||||
omq.add_request_command("sub", "mempool", [this](oxenmq::Message& m) {
|
||||
OnMempoolSubRequest(m);
|
||||
on_mempool_sub_request(m);
|
||||
});
|
||||
|
||||
omq.add_request_command("sub", "block", [this](oxenmq::Message& m) {
|
||||
OnBlockSubRequest(m);
|
||||
on_block_sub_request(m);
|
||||
});
|
||||
|
||||
core_.get_blockchain_storage().hook_block_added(*this);
|
||||
|
@ -353,7 +353,7 @@ void omq_rpc::send_mempool_notifications(const crypto::hash& id, const transacti
|
|||
/// - \p global_indices -- list of output indices for the transaction's created outputs
|
||||
/// - \p hash -- the transaction hash
|
||||
/// - \p tx -- base64 string of raw transaction data \todo properly serialized transaction
|
||||
void omq_rpc::OnGetBlocks(oxenmq::Message& m)
|
||||
void omq_rpc::on_get_blocks(oxenmq::Message& m)
|
||||
{
|
||||
if (m.data.size() == 0)
|
||||
{
|
||||
|
@ -512,7 +512,7 @@ void omq_rpc::OnGetBlocks(oxenmq::Message& m)
|
|||
// such as txes that came from an existing block during a rollback). Note that both txhash and
|
||||
// txblob are binary: in particular, txhash is *not* hex-encoded.
|
||||
//
|
||||
void omq_rpc::OnMempoolSubRequest(oxenmq::Message& m)
|
||||
void omq_rpc::on_mempool_sub_request(oxenmq::Message& m)
|
||||
{
|
||||
if (m.data.size() != 1) {
|
||||
m.send_reply("Invalid subscription request: no subscription type given");
|
||||
|
@ -558,7 +558,7 @@ void omq_rpc::OnMempoolSubRequest(oxenmq::Message& m)
|
|||
// The block notification for new blocks consists of a message [notify.block, height, blockhash]
|
||||
// containing the latest height/hash. (Note that blockhash is the hash in bytes, *not* the hex
|
||||
// encoded block hash).
|
||||
void omq_rpc::OnBlockSubRequest(oxenmq::Message& m)
|
||||
void omq_rpc::on_block_sub_request(oxenmq::Message& m)
|
||||
{
|
||||
std::unique_lock lock{subs_mutex_};
|
||||
auto expiry = std::chrono::steady_clock::now() + 30min;
|
||||
|
|
|
@ -70,11 +70,11 @@ public:
|
|||
void send_mempool_notifications(const crypto::hash& id, const transaction& tx, const std::string& blob, const tx_pool_options& opts);
|
||||
|
||||
private:
|
||||
void OnGetBlocks(oxenmq::Message& m);
|
||||
void on_get_blocks(oxenmq::Message& m);
|
||||
|
||||
void OnMempoolSubRequest(oxenmq::Message& m);
|
||||
void on_mempool_sub_request(oxenmq::Message& m);
|
||||
|
||||
void OnBlockSubRequest(oxenmq::Message& m);
|
||||
void on_block_sub_request(oxenmq::Message& m);
|
||||
};
|
||||
|
||||
}} // namespace cryptonote::rpc
|
||||
|
|
|
@ -14,10 +14,10 @@ namespace wallet
|
|||
public:
|
||||
|
||||
virtual void
|
||||
SetRemote(std::string_view address) = 0;
|
||||
set_remote(std::string_view address) = 0;
|
||||
|
||||
virtual int64_t
|
||||
GetHeight() = 0;
|
||||
get_height() = 0;
|
||||
|
||||
/* Called by a wallet to tell the daemon comms it exists, as well
|
||||
* as what height it needs to sync from. Updates existing registration
|
||||
|
@ -31,10 +31,10 @@ namespace wallet
|
|||
* When the wallet finishes processing a batch of blocks. Pass check_sync_height=false.
|
||||
*/
|
||||
virtual void
|
||||
RegisterWallet(Wallet& wallet, int64_t height, bool check_sync_height = false) = 0;
|
||||
register_wallet(Wallet& wallet, int64_t height, bool check_sync_height = false) = 0;
|
||||
|
||||
virtual void
|
||||
DeregisterWallet(Wallet& wallet, std::promise<void>& p) = 0;
|
||||
deregister_wallet(Wallet& wallet, std::promise<void>& p) = 0;
|
||||
};
|
||||
|
||||
} // namespace wallet
|
||||
|
|
|
@ -13,20 +13,20 @@
|
|||
namespace wallet
|
||||
{
|
||||
void
|
||||
DefaultDaemonComms::OnGetBlocksResponse(std::vector<std::string> response)
|
||||
DefaultDaemonComms::on_get_blocks_response(std::vector<std::string> response)
|
||||
{
|
||||
if (not response.size())
|
||||
{
|
||||
std::cout << "OnGetBlocksResponse(): empty GetBlocks response\n";
|
||||
std::cout << "on_get_blocks_response(): empty get_blocks response\n";
|
||||
//TODO: error handling
|
||||
return;
|
||||
}
|
||||
std::cout << "OnGetBlocksResponse() got " << response.size() - 1 << " blocks.\n";
|
||||
std::cout << "on_get_blocks_response() got " << response.size() - 1 << " blocks.\n";
|
||||
|
||||
const auto& status = response[0];
|
||||
if (status != "OK" and status != "END")
|
||||
{
|
||||
std::cout << "GetBlocks response: " << response[0] << "\n";
|
||||
std::cout << "get_blocks response: " << response[0] << "\n";
|
||||
//TODO: error handling
|
||||
return;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ namespace wallet
|
|||
// TODO: decide/confirm this behavior on the daemon side of things
|
||||
if (response.size() == 1)
|
||||
{
|
||||
std::cout << "GetBlocks response.size() == 1\n";
|
||||
std::cout << "get_blocks response.size() == 1\n";
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -115,43 +115,43 @@ namespace wallet
|
|||
|
||||
int64_t start_height = blocks.front().height;
|
||||
int64_t end_height = blocks.back().height;
|
||||
std::cout << "OnGetBlocksResponse() got blocks [" << start_height << " to " << end_height << "]\n";
|
||||
std::cout << "on_get_blocks_response() got blocks [" << start_height << " to " << end_height << "]\n";
|
||||
|
||||
if (status == "END")
|
||||
{
|
||||
std::cout << "Finished syncing wallets, height: " << end_height << "\n";
|
||||
oxenMQ->job([this](){ syncing = false; }, sync_thread);
|
||||
omq->job([this](){ syncing = false; }, sync_thread);
|
||||
}
|
||||
else
|
||||
{
|
||||
oxenMQ->job([this,start_height,end_height](){GotBlocks(start_height, end_height);}, sync_thread);
|
||||
omq->job([this,start_height,end_height](){got_blocks(start_height, end_height);}, sync_thread);
|
||||
}
|
||||
|
||||
oxenMQ->job([blocks=std::move(blocks),this](){
|
||||
ForEachWallet([&](std::shared_ptr<Wallet> wallet){
|
||||
wallet->AddBlocks(blocks);
|
||||
omq->job([blocks=std::move(blocks),this](){
|
||||
for_each_wallet([&](std::shared_ptr<Wallet> wallet){
|
||||
wallet->add_blocks(blocks);
|
||||
});
|
||||
}, sync_thread);
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
DefaultDaemonComms::RequestTopBlockInfo()
|
||||
DefaultDaemonComms::request_top_block_info()
|
||||
{
|
||||
auto timeout_job = [self=weak_from_this()](){
|
||||
if (auto comms = self.lock())
|
||||
comms->RequestTopBlockInfo();
|
||||
comms->request_top_block_info();
|
||||
};
|
||||
|
||||
oxenMQ->cancel_timer(status_timer);
|
||||
omq->cancel_timer(status_timer);
|
||||
if (top_block_height == 0)
|
||||
{
|
||||
oxenMQ->add_timer(status_timer, timeout_job, 3s);
|
||||
omq->add_timer(status_timer, timeout_job, 3s);
|
||||
}
|
||||
else
|
||||
oxenMQ->add_timer(status_timer, timeout_job, 15s);
|
||||
omq->add_timer(status_timer, timeout_job, 15s);
|
||||
|
||||
oxenMQ->request(conn, "rpc.get_height",
|
||||
omq->request(conn, "rpc.get_height",
|
||||
[this](bool ok, std::vector<std::string> response)
|
||||
{
|
||||
if (not ok or response.size() != 2 or response[0] != "200")
|
||||
|
@ -177,15 +177,15 @@ namespace wallet
|
|||
}, "de");
|
||||
}
|
||||
|
||||
DefaultDaemonComms::DefaultDaemonComms(std::shared_ptr<oxenmq::OxenMQ> oxenMQ)
|
||||
: oxenMQ(oxenMQ),
|
||||
sync_thread(oxenMQ->add_tagged_thread("sync"))
|
||||
DefaultDaemonComms::DefaultDaemonComms(std::shared_ptr<oxenmq::OxenMQ> omq)
|
||||
: omq(omq),
|
||||
sync_thread(omq->add_tagged_thread("sync"))
|
||||
{
|
||||
oxenMQ->MAX_MSG_SIZE = max_response_size;
|
||||
omq->MAX_MSG_SIZE = max_response_size;
|
||||
}
|
||||
|
||||
void
|
||||
DefaultDaemonComms::SetRemote(std::string_view address)
|
||||
DefaultDaemonComms::set_remote(std::string_view address)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -198,13 +198,13 @@ namespace wallet
|
|||
}
|
||||
|
||||
// TODO: proper callbacks
|
||||
conn = oxenMQ->connect_remote(remote, [](auto){}, [](auto,auto){});
|
||||
conn = omq->connect_remote(remote, [](auto){}, [](auto,auto){});
|
||||
|
||||
RequestTopBlockInfo();
|
||||
request_top_block_info();
|
||||
}
|
||||
|
||||
void
|
||||
DefaultDaemonComms::GetBlocks()
|
||||
DefaultDaemonComms::get_blocks()
|
||||
{
|
||||
auto req_cb = [this](bool ok, std::vector<std::string> response)
|
||||
{
|
||||
|
@ -215,9 +215,9 @@ namespace wallet
|
|||
// Retry after a delay to not spam/spin
|
||||
auto timer = std::make_shared<oxenmq::TimerID>();
|
||||
auto& timer_ref = *timer;
|
||||
oxenMQ->add_timer(timer_ref, [this,timer=std::move(timer)]{
|
||||
oxenMQ->cancel_timer(*timer);
|
||||
GetBlocks();
|
||||
omq->add_timer(timer_ref, [this,timer=std::move(timer)]{
|
||||
omq->cancel_timer(*timer);
|
||||
get_blocks();
|
||||
},
|
||||
500ms,
|
||||
true,
|
||||
|
@ -225,7 +225,7 @@ namespace wallet
|
|||
return;
|
||||
}
|
||||
|
||||
OnGetBlocksResponse(response);
|
||||
on_get_blocks_response(response);
|
||||
};
|
||||
|
||||
std::map<std::string, int64_t> req_params_dict{
|
||||
|
@ -233,38 +233,38 @@ namespace wallet
|
|||
{"size_limit", max_response_size},
|
||||
{"start_height", sync_from_height}};
|
||||
|
||||
oxenMQ->request(conn, "rpc.get_blocks", req_cb, oxenmq::bt_serialize(req_params_dict));
|
||||
omq->request(conn, "rpc.get_blocks", req_cb, oxenmq::bt_serialize(req_params_dict));
|
||||
}
|
||||
|
||||
void
|
||||
DefaultDaemonComms::RegisterWallet(wallet::Wallet& wallet, int64_t height, bool check_sync_height)
|
||||
DefaultDaemonComms::register_wallet(wallet::Wallet& wallet, int64_t height, bool check_sync_height)
|
||||
{
|
||||
oxenMQ->job([this,w=wallet.shared_from_this(),height,check_sync_height](){
|
||||
omq->job([this,w=wallet.shared_from_this(),height,check_sync_height](){
|
||||
wallets.insert_or_assign(w, height);
|
||||
if (check_sync_height)
|
||||
sync_from_height = std::min(sync_from_height, height);
|
||||
StartSyncing();
|
||||
start_syncing();
|
||||
}, sync_thread);
|
||||
}
|
||||
|
||||
void
|
||||
DefaultDaemonComms::DeregisterWallet(wallet::Wallet& wallet, std::promise<void>& p)
|
||||
DefaultDaemonComms::deregister_wallet(wallet::Wallet& wallet, std::promise<void>& p)
|
||||
{
|
||||
oxenMQ->job([this,w=wallet.shared_from_this(),&p]() mutable {
|
||||
omq->job([this,w=wallet.shared_from_this(),&p]() mutable {
|
||||
wallets.erase(w);
|
||||
w.reset();
|
||||
p.set_value();
|
||||
auto itr = std::min_element(wallets.begin(), wallets.end(),
|
||||
[](const auto& l, const auto& r){ return l.second < r.second; });
|
||||
sync_from_height = itr->second;
|
||||
std::cout << "DeregisterWallet() setting sync_from_height to " << sync_from_height << "\n";
|
||||
std::cout << "deregister_wallet() setting sync_from_height to " << sync_from_height << "\n";
|
||||
if (sync_from_height != 0 and sync_from_height == top_block_height)
|
||||
syncing = false;
|
||||
}, sync_thread);
|
||||
}
|
||||
|
||||
void
|
||||
DefaultDaemonComms::ForEachWallet(std::function<void(std::shared_ptr<Wallet>)> func)
|
||||
DefaultDaemonComms::for_each_wallet(std::function<void(std::shared_ptr<Wallet>)> func)
|
||||
{
|
||||
for (auto [wallet,h] : wallets)
|
||||
{
|
||||
|
@ -273,7 +273,7 @@ namespace wallet
|
|||
}
|
||||
|
||||
void
|
||||
DefaultDaemonComms::GotBlocks(int64_t start_height, int64_t end_height)
|
||||
DefaultDaemonComms::got_blocks(int64_t start_height, int64_t end_height)
|
||||
{
|
||||
// if we get caught up, or all wallets are removed, no need to request more blocks
|
||||
if (not syncing)
|
||||
|
@ -283,16 +283,16 @@ namespace wallet
|
|||
{
|
||||
sync_from_height = end_height + 1;
|
||||
}
|
||||
GetBlocks();
|
||||
get_blocks();
|
||||
}
|
||||
|
||||
void
|
||||
DefaultDaemonComms::StartSyncing()
|
||||
DefaultDaemonComms::start_syncing()
|
||||
{
|
||||
if ((not syncing and sync_from_height < top_block_height) or (top_block_height == 0))
|
||||
{
|
||||
syncing = true;
|
||||
GetBlocks();
|
||||
get_blocks();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,47 +22,44 @@ namespace wallet
|
|||
static constexpr int64_t DEFAULT_MAX_SYNC_BLOCKS = 200;
|
||||
|
||||
void
|
||||
OnGetBlocksResponse(std::vector<std::string> response);
|
||||
on_get_blocks_response(std::vector<std::string> response);
|
||||
|
||||
void
|
||||
RequestTopBlockInfo();
|
||||
|
||||
void
|
||||
UpdateTopBlockInfo();
|
||||
request_top_block_info();
|
||||
|
||||
public:
|
||||
|
||||
DefaultDaemonComms(std::shared_ptr<oxenmq::OxenMQ> oxenMQ);
|
||||
DefaultDaemonComms(std::shared_ptr<oxenmq::OxenMQ> omq);
|
||||
|
||||
void
|
||||
SetRemote(std::string_view address);
|
||||
set_remote(std::string_view address);
|
||||
|
||||
int64_t
|
||||
GetHeight() { return top_block_height; }
|
||||
get_height() { return top_block_height; }
|
||||
|
||||
void
|
||||
RegisterWallet(wallet::Wallet& wallet, int64_t height, bool check_sync_height);
|
||||
register_wallet(wallet::Wallet& wallet, int64_t height, bool check_sync_height);
|
||||
|
||||
void
|
||||
DeregisterWallet(Wallet& wallet, std::promise<void>& p);
|
||||
deregister_wallet(Wallet& wallet, std::promise<void>& p);
|
||||
|
||||
private:
|
||||
|
||||
void
|
||||
ForEachWallet(std::function<void(std::shared_ptr<Wallet>)> func);
|
||||
for_each_wallet(std::function<void(std::shared_ptr<Wallet>)> func);
|
||||
|
||||
void
|
||||
GetBlocks();
|
||||
get_blocks();
|
||||
|
||||
void
|
||||
GotBlocks(int64_t start_height, int64_t end_height);
|
||||
got_blocks(int64_t start_height, int64_t end_height);
|
||||
|
||||
void
|
||||
StartSyncing();
|
||||
start_syncing();
|
||||
|
||||
std::unordered_map<std::shared_ptr<Wallet>, int64_t> wallets;
|
||||
|
||||
std::shared_ptr<oxenmq::OxenMQ> oxenMQ;
|
||||
std::shared_ptr<oxenmq::OxenMQ> omq;
|
||||
oxenmq::address remote;
|
||||
oxenmq::ConnectionID conn;
|
||||
oxenmq::TimerID status_timer;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
namespace wallet
|
||||
{
|
||||
std::vector<Output>
|
||||
TransactionScanner::ScanTransactionReceived(
|
||||
TransactionScanner::scan_received(
|
||||
const BlockTX& tx, int64_t height, int64_t timestamp)
|
||||
{
|
||||
const auto tx_public_keys = tx.tx.get_public_keys();
|
||||
|
@ -92,7 +92,7 @@ namespace wallet
|
|||
}
|
||||
|
||||
std::vector<crypto::key_image>
|
||||
TransactionScanner::ScanTransactionSpent(const cryptonote::transaction& tx)
|
||||
TransactionScanner::scan_spent(const cryptonote::transaction& tx)
|
||||
{
|
||||
std::vector<crypto::key_image> spends;
|
||||
|
||||
|
|
|
@ -19,15 +19,15 @@ namespace wallet
|
|||
class TransactionScanner
|
||||
{
|
||||
public:
|
||||
TransactionScanner(std::shared_ptr<Keyring> _keys, std::shared_ptr<db::Database> _db)
|
||||
: wallet_keys(_keys), db(_db)
|
||||
TransactionScanner(std::shared_ptr<Keyring> keys, std::shared_ptr<db::Database> db)
|
||||
: wallet_keys(keys), db(db)
|
||||
{}
|
||||
|
||||
std::vector<Output>
|
||||
ScanTransactionReceived(const BlockTX& tx, int64_t height, int64_t timestamp);
|
||||
scan_received(const BlockTX& tx, int64_t height, int64_t timestamp);
|
||||
|
||||
std::vector<crypto::key_image>
|
||||
ScanTransactionSpent(const cryptonote::transaction& tx);
|
||||
scan_spent(const cryptonote::transaction& tx);
|
||||
|
||||
private:
|
||||
std::shared_ptr<Keyring> wallet_keys;
|
||||
|
|
|
@ -19,18 +19,18 @@
|
|||
namespace wallet
|
||||
{
|
||||
Wallet::Wallet(
|
||||
std::shared_ptr<oxenmq::OxenMQ> oxenMQ,
|
||||
std::shared_ptr<oxenmq::OxenMQ> omq,
|
||||
std::shared_ptr<Keyring> keys,
|
||||
std::shared_ptr<TransactionConstructor> txConstructor,
|
||||
std::shared_ptr<DaemonComms> daemonComms,
|
||||
std::shared_ptr<TransactionConstructor> tx_constructor,
|
||||
std::shared_ptr<DaemonComms> daemon_comms,
|
||||
std::string_view dbFilename,
|
||||
std::string_view dbPassword)
|
||||
: oxenMQ(oxenMQ)
|
||||
: omq(omq)
|
||||
, db{std::make_shared<db::Database>(std::filesystem::path(dbFilename), dbPassword)}
|
||||
, keys{keys}
|
||||
, txScanner{keys, db}
|
||||
, txConstructor{txConstructor}
|
||||
, daemonComms{daemonComms}
|
||||
, tx_scanner{keys, db}
|
||||
, tx_constructor{tx_constructor}
|
||||
, daemon_comms{daemon_comms}
|
||||
{
|
||||
create_schema(db->db);
|
||||
last_scanned_height = db->prepared_get<int64_t>("SELECT last_scan_height FROM metadata WHERE id=0;");
|
||||
|
@ -40,7 +40,7 @@ namespace wallet
|
|||
void
|
||||
Wallet::init()
|
||||
{
|
||||
daemonComms->RegisterWallet(*this, last_scanned_height + 1 /*next needed block*/, true);
|
||||
daemon_comms->register_wallet(*this, last_scanned_height + 1 /*next needed block*/, true);
|
||||
}
|
||||
|
||||
Wallet::~Wallet()
|
||||
|
@ -49,25 +49,13 @@ namespace wallet
|
|||
}
|
||||
|
||||
uint64_t
|
||||
Wallet::GetBalance()
|
||||
Wallet::get_balance()
|
||||
{
|
||||
return db->prepared_get<int64_t>("SELECT balance FROM metadata WHERE id=0;");
|
||||
}
|
||||
|
||||
int64_t
|
||||
Wallet::ScannedHeight()
|
||||
{
|
||||
return last_scanned_height;
|
||||
}
|
||||
|
||||
int64_t
|
||||
Wallet::ScanTargetHeight()
|
||||
{
|
||||
return scan_target_height;
|
||||
}
|
||||
|
||||
void
|
||||
Wallet::AddBlock(const Block& block)
|
||||
Wallet::add_block(const Block& block)
|
||||
{
|
||||
SQLite::Transaction db_tx(db->db);
|
||||
|
||||
|
@ -79,15 +67,15 @@ namespace wallet
|
|||
|
||||
for (const auto& tx : block.transactions)
|
||||
{
|
||||
if (auto outputs = txScanner.ScanTransactionReceived(tx, block.height, block.timestamp);
|
||||
if (auto outputs = tx_scanner.scan_received(tx, block.height, block.timestamp);
|
||||
not outputs.empty())
|
||||
{
|
||||
StoreTransaction(tx.hash, block.height, outputs);
|
||||
store_transaction(tx.hash, block.height, outputs);
|
||||
}
|
||||
|
||||
if (auto spends = txScanner.ScanTransactionSpent(tx.tx); not spends.empty())
|
||||
if (auto spends = tx_scanner.scan_spent(tx.tx); not spends.empty())
|
||||
{
|
||||
StoreSpends(tx.hash, block.height, spends);
|
||||
store_spends(tx.hash, block.height, spends);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,7 +84,7 @@ namespace wallet
|
|||
}
|
||||
|
||||
void
|
||||
Wallet::AddBlocks(const std::vector<Block>& blocks)
|
||||
Wallet::add_blocks(const std::vector<Block>& blocks)
|
||||
{
|
||||
if (not running)
|
||||
return;
|
||||
|
@ -107,20 +95,20 @@ namespace wallet
|
|||
|
||||
if (blocks.front().height > last_scanned_height + 1)
|
||||
{
|
||||
daemonComms->RegisterWallet(*this, last_scanned_height + 1 /*next needed block*/, true);
|
||||
daemon_comms->register_wallet(*this, last_scanned_height + 1 /*next needed block*/, true);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto& block : blocks)
|
||||
{
|
||||
if (block.height == last_scanned_height + 1)
|
||||
AddBlock(block);
|
||||
add_block(block);
|
||||
}
|
||||
daemonComms->RegisterWallet(*this, last_scanned_height + 1 /*next needed block*/, false);
|
||||
daemon_comms->register_wallet(*this, last_scanned_height + 1 /*next needed block*/, false);
|
||||
}
|
||||
|
||||
void
|
||||
Wallet::UpdateTopBlockInfo(int64_t height, const crypto::hash& hash)
|
||||
Wallet::update_top_block_info(int64_t height, const crypto::hash& hash)
|
||||
{
|
||||
if (not running)
|
||||
return;
|
||||
|
@ -133,20 +121,20 @@ namespace wallet
|
|||
}
|
||||
|
||||
void
|
||||
Wallet::Deregister()
|
||||
Wallet::deregister()
|
||||
{
|
||||
auto self = weak_from_this();
|
||||
std::cout << "Wallet ref count before Deregister: " << self.use_count() << "\n";
|
||||
std::cout << "Wallet ref count before deregister: " << self.use_count() << "\n";
|
||||
running = false;
|
||||
std::promise<void> p;
|
||||
auto f = p.get_future();
|
||||
daemonComms->DeregisterWallet(*this, p);
|
||||
daemon_comms->deregister_wallet(*this, p);
|
||||
f.wait();
|
||||
std::cout << "Wallet ref count after Deregister: " << self.use_count() << "\n";
|
||||
std::cout << "Wallet ref count after deregister: " << self.use_count() << "\n";
|
||||
}
|
||||
|
||||
void
|
||||
Wallet::StoreTransaction(
|
||||
Wallet::store_transaction(
|
||||
const crypto::hash& tx_hash, const int64_t height, const std::vector<Output>& outputs)
|
||||
{
|
||||
auto hash_str = tools::type_to_hex(tx_hash);
|
||||
|
@ -192,7 +180,7 @@ namespace wallet
|
|||
}
|
||||
|
||||
void
|
||||
Wallet::StoreSpends(
|
||||
Wallet::store_spends(
|
||||
const crypto::hash& tx_hash,
|
||||
const int64_t height,
|
||||
const std::vector<crypto::key_image>& spends)
|
||||
|
|
|
@ -27,10 +27,10 @@ namespace wallet
|
|||
{
|
||||
protected:
|
||||
Wallet(
|
||||
std::shared_ptr<oxenmq::OxenMQ> oxenMQ,
|
||||
std::shared_ptr<oxenmq::OxenMQ> omq,
|
||||
std::shared_ptr<Keyring> keys,
|
||||
std::shared_ptr<TransactionConstructor> txConstructor,
|
||||
std::shared_ptr<DaemonComms> daemonComms,
|
||||
std::shared_ptr<TransactionConstructor> tx_constructor,
|
||||
std::shared_ptr<DaemonComms> daemon_comms,
|
||||
std::string_view dbFilename,
|
||||
std::string_view dbPassword);
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace wallet
|
|||
public:
|
||||
template <typename... T>
|
||||
[[nodiscard]] static std::shared_ptr<Wallet>
|
||||
MakeWallet(T&&... args)
|
||||
create(T&&... args)
|
||||
{
|
||||
std::shared_ptr<Wallet> p{new Wallet(std::forward<T>(args)...)};
|
||||
p->init();
|
||||
|
@ -50,73 +50,64 @@ namespace wallet
|
|||
~Wallet();
|
||||
|
||||
uint64_t
|
||||
GetBalance();
|
||||
get_balance();
|
||||
uint64_t
|
||||
GetUnlockedBalance();
|
||||
get_unlocked_balance();
|
||||
address
|
||||
GetAddress();
|
||||
get_address();
|
||||
|
||||
// FIXME: argument nomenclature
|
||||
address
|
||||
GetSubaddress(int32_t account, int32_t index);
|
||||
|
||||
int64_t
|
||||
ScannedHeight();
|
||||
|
||||
int64_t
|
||||
ScanTargetHeight();
|
||||
get_subaddress(int32_t account, int32_t index);
|
||||
|
||||
// TODO: error types to throw
|
||||
PendingTransaction
|
||||
CreateTransaction(
|
||||
create_transaction(
|
||||
const std::vector<std::pair<address, int64_t>>& recipients, int64_t feePerKB);
|
||||
void
|
||||
SignTransaction(PendingTransaction& tx);
|
||||
sign_transaction(PendingTransaction& tx);
|
||||
void
|
||||
SubmitTransaction(const PendingTransaction& tx);
|
||||
submit_transaction(const PendingTransaction& tx);
|
||||
|
||||
void
|
||||
AddBlock(const Block& block);
|
||||
add_block(const Block& block);
|
||||
|
||||
void
|
||||
AddBlocks(const std::vector<Block>& blocks);
|
||||
add_blocks(const std::vector<Block>& blocks);
|
||||
|
||||
// Called by daemon comms to inform of new sync target.
|
||||
void
|
||||
UpdateTopBlockInfo(int64_t height, const crypto::hash& hash);
|
||||
update_top_block_info(int64_t height, const crypto::hash& hash);
|
||||
|
||||
/* Tells the wallet to inform comms that it is going away.
|
||||
*
|
||||
* This MUST be called before the wallet is destroyed.
|
||||
*/
|
||||
void
|
||||
Deregister();
|
||||
deregister();
|
||||
|
||||
int64_t scan_target_height = 0;
|
||||
int64_t last_scanned_height = -1;
|
||||
|
||||
protected:
|
||||
void
|
||||
StoreTransaction(
|
||||
store_transaction(
|
||||
const crypto::hash& tx_hash, const int64_t height, const std::vector<Output>& outputs);
|
||||
|
||||
void
|
||||
StoreSpends(
|
||||
store_spends(
|
||||
const crypto::hash& tx_hash,
|
||||
const int64_t height,
|
||||
const std::vector<crypto::key_image>& spends);
|
||||
|
||||
void
|
||||
RequestNextBlocks();
|
||||
|
||||
std::shared_ptr<oxenmq::OxenMQ> oxenMQ;
|
||||
std::shared_ptr<oxenmq::OxenMQ> omq;
|
||||
|
||||
std::shared_ptr<db::Database> db;
|
||||
|
||||
std::shared_ptr<Keyring> keys;
|
||||
TransactionScanner txScanner;
|
||||
std::shared_ptr<TransactionConstructor> txConstructor;
|
||||
std::shared_ptr<DaemonComms> daemonComms;
|
||||
|
||||
int64_t scan_target_height = 0;
|
||||
int64_t last_scanned_height = -1;
|
||||
TransactionScanner tx_scanner;
|
||||
std::shared_ptr<TransactionConstructor> tx_constructor;
|
||||
std::shared_ptr<DaemonComms> daemon_comms;
|
||||
bool running = true;
|
||||
};
|
||||
|
||||
|
|
|
@ -33,13 +33,13 @@ int main(void)
|
|||
auto comms = std::make_shared<wallet::DefaultDaemonComms>(oxenmq);
|
||||
oxenmq->start();
|
||||
|
||||
comms->SetRemote("ipc://./oxend.sock");
|
||||
comms->set_remote("ipc://./oxend.sock");
|
||||
|
||||
auto wallet = wallet::Wallet::MakeWallet(oxenmq, keyring, ctor, comms, ":memory:", "");
|
||||
auto wallet = wallet::Wallet::create(oxenmq, keyring, ctor, comms, ":memory:", "");
|
||||
|
||||
|
||||
std::this_thread::sleep_for(2s);
|
||||
auto chain_height = comms->GetHeight();
|
||||
auto chain_height = comms->get_height();
|
||||
|
||||
std::cout << "chain height: " << chain_height << "\n";
|
||||
|
||||
|
@ -52,24 +52,24 @@ int main(void)
|
|||
using namespace std::chrono_literals;
|
||||
|
||||
std::this_thread::sleep_for(1s);
|
||||
std::cout << "after block " << wallet->ScannedHeight() << ", balance is: " << wallet->GetBalance() << "\n";
|
||||
if (wallet->ScannedHeight() > 5000 and not made_second)
|
||||
std::cout << "after block " << wallet->last_scanned_height << ", balance is: " << wallet->get_balance() << "\n";
|
||||
if (wallet->last_scanned_height > 5000 and not made_second)
|
||||
{
|
||||
wallet2 = wallet::Wallet::MakeWallet(oxenmq, keyring, ctor, comms, ":memory:", "");
|
||||
wallet2 = wallet::Wallet::create(oxenmq, keyring, ctor, comms, ":memory:", "");
|
||||
made_second = true;
|
||||
}
|
||||
if (wallet2)
|
||||
{
|
||||
std::cout << "after block " << wallet2->ScannedHeight() << ", wallet2 balance is: " << wallet2->GetBalance() << "\n";
|
||||
std::cout << "after block " << wallet2->last_scanned_height << ", wallet2 balance is: " << wallet2->get_balance() << "\n";
|
||||
|
||||
if (wallet2->ScannedHeight() > 3000)
|
||||
if (wallet2->last_scanned_height > 3000)
|
||||
{
|
||||
if (not dereg_second)
|
||||
{
|
||||
wallet2->Deregister();
|
||||
wallet2->deregister();
|
||||
dereg_second = true;
|
||||
}
|
||||
std::cout << "After Deregister(), ref count = " << wallet2.use_count() << "\n";
|
||||
std::cout << "After deregister(), ref count = " << wallet2.use_count() << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ TEST_CASE("Transaction Scanner", "[wallet]")
|
|||
|
||||
SECTION("tx with no outputs created should yield no outputs for us")
|
||||
{
|
||||
REQUIRE(scanner->ScanTransactionReceived(block_tx, 0, 0).size() == 0);
|
||||
REQUIRE(scanner->scan_received(block_tx, 0, 0).size() == 0);
|
||||
}
|
||||
|
||||
cryptonote::add_tx_extra<cryptonote::tx_extra_pub_key>(tx, tx_pubkey1);
|
||||
|
@ -42,21 +42,21 @@ TEST_CASE("Transaction Scanner", "[wallet]")
|
|||
|
||||
SECTION("tx has one output which is not ours")
|
||||
{
|
||||
REQUIRE(scanner->ScanTransactionReceived(block_tx, 0, 0).size() == 0);
|
||||
REQUIRE(scanner->scan_received(block_tx, 0, 0).size() == 0);
|
||||
}
|
||||
|
||||
SECTION("tx has one output which is ours")
|
||||
{
|
||||
keys->add_key_index_pair_as_ours(tx_pubkey1, 0, 0, {0,0});
|
||||
REQUIRE(scanner->ScanTransactionReceived(block_tx, 0, 0).size() == 1);
|
||||
REQUIRE(scanner->ScanTransactionReceived(block_tx, 0, 0)[0].subaddress_index == cryptonote::subaddress_index{0,0});
|
||||
REQUIRE(scanner->scan_received(block_tx, 0, 0).size() == 1);
|
||||
REQUIRE(scanner->scan_received(block_tx, 0, 0)[0].subaddress_index == cryptonote::subaddress_index{0,0});
|
||||
}
|
||||
|
||||
SECTION("subaddress_index is correct for identified output")
|
||||
{
|
||||
keys->add_key_index_pair_as_ours(tx_pubkey1, 0, 0, {1,0});
|
||||
REQUIRE(scanner->ScanTransactionReceived(block_tx, 0, 0).size() == 1);
|
||||
REQUIRE(scanner->ScanTransactionReceived(block_tx, 0, 0)[0].subaddress_index == cryptonote::subaddress_index{1,0});
|
||||
REQUIRE(scanner->scan_received(block_tx, 0, 0).size() == 1);
|
||||
REQUIRE(scanner->scan_received(block_tx, 0, 0)[0].subaddress_index == cryptonote::subaddress_index{1,0});
|
||||
}
|
||||
|
||||
SECTION("multiple outputs for multiple subaddresses")
|
||||
|
@ -66,7 +66,7 @@ TEST_CASE("Transaction Scanner", "[wallet]")
|
|||
tx.vout.push_back(out1); // second copy of same dummy output
|
||||
block_tx.global_indices.resize(2, 0);
|
||||
|
||||
auto outs = scanner->ScanTransactionReceived(block_tx, 0, 0);
|
||||
auto outs = scanner->scan_received(block_tx, 0, 0);
|
||||
REQUIRE(outs.size() == 2);
|
||||
REQUIRE(outs[0].subaddress_index == cryptonote::subaddress_index{0,0});
|
||||
REQUIRE(outs[1].subaddress_index == cryptonote::subaddress_index{3,4});
|
||||
|
@ -78,7 +78,7 @@ TEST_CASE("Transaction Scanner", "[wallet]")
|
|||
tx.vout.push_back(out2); // diff output key, first not ours here, this one is
|
||||
block_tx.global_indices.resize(2, 0);
|
||||
|
||||
auto outs = scanner->ScanTransactionReceived(block_tx, 0, 0);
|
||||
auto outs = scanner->scan_received(block_tx, 0, 0);
|
||||
REQUIRE(outs.size() == 1);
|
||||
REQUIRE(outs[0].subaddress_index == cryptonote::subaddress_index{0,0});
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ TEST_CASE("Transaction Scanner", "[wallet]")
|
|||
SECTION("correct output amount")
|
||||
{
|
||||
keys->add_key_index_pair_as_ours(tx_pubkey1, 0, 42, {0,0});
|
||||
auto outs = scanner->ScanTransactionReceived(block_tx, 0, 0);
|
||||
auto outs = scanner->scan_received(block_tx, 0, 0);
|
||||
REQUIRE(outs.size() == 1);
|
||||
REQUIRE(outs[0].amount == 42);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue