Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cpp/daemon/py_monero_daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ std::vector<std::shared_ptr<PyMoneroBan>> PyMoneroDaemonRpc::get_peer_bans() {

void PyMoneroDaemonRpc::set_peer_bans(std::vector<std::shared_ptr<PyMoneroBan>> bans) {
auto params = std::make_shared<PyMoneroSetBansParams>(bans);
PyMoneroJsonRequest request("set_bans");
PyMoneroJsonRequest request("set_bans", params);
std::shared_ptr<PyMoneroJsonResponse> response = m_rpc->send_json_request(request);
check_response_status(response);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/daemon/py_monero_daemon_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ class PyMoneroGetFeeEstimateParams : public PyMoneroJsonRequestParams {
rapidjson::Value to_rapidjson_val(rapidjson::Document::AllocatorType& allocator) const override;
};

class PyMoneroSetBansParams : public PyMoneroRequestParams {
class PyMoneroSetBansParams : public PyMoneroJsonRequestParams {
public:
std::vector<std::shared_ptr<PyMoneroBan>> m_bans;

Expand Down
20 changes: 10 additions & 10 deletions src/cpp/py_monero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
try { \
return expr; \
} catch (const PyMoneroRpcError& e) { \
throw e; \
throw; \
} \
catch (const std::exception& e) { \
throw PyMoneroError(e.what()); \
Expand Down Expand Up @@ -1456,10 +1456,10 @@ PYBIND11_MODULE(monero, m) {
assert_wallet_is_not_closed(&self);
MONERO_CATCH_AND_RETHROW(self.set_daemon_connection(connection));
}, py::arg("connection"))
.def("set_daemon_connection", [](PyMoneroWallet& self, std::string uri, std::string username, std::string password, std::string proxy) {
.def("set_daemon_connection", [](PyMoneroWallet& self, const std::string& uri, const std::string& username, const std::string& password, const std::string& proxy) {
assert_wallet_is_not_closed(&self);
MONERO_CATCH_AND_RETHROW(self.set_daemon_connection(uri, username, password, proxy));
}, py::arg("uri") = "", py::arg("username") = "", py::arg("password") = "", py::arg("proxy") = "")
}, py::arg("uri") = "", py::arg("username") = "", py::arg("password") = "", py::arg("proxy") = "")
.def("get_daemon_connection", [](PyMoneroWallet& self) {
assert_wallet_is_not_closed(&self);
MONERO_CATCH_AND_RETHROW(self.get_daemon_connection());
Expand Down Expand Up @@ -1894,8 +1894,8 @@ PYBIND11_MODULE(monero, m) {
}, py::arg("uri"))
.def("get_attribute", [](PyMoneroWallet& self, const std::string& key) {
assert_wallet_is_not_closed(&self);
std::string val;
try {
std::string val;
self.get_attribute(key, val);
return val;
} catch (const std::exception& e) {
Expand Down Expand Up @@ -2031,10 +2031,10 @@ PYBIND11_MODULE(monero, m) {
return &self;
}
catch(const PyMoneroRpcError& ex) {
throw ex;
throw;
}
catch(const PyMoneroError& ex) {
throw ex;
throw;
}
catch(const std::exception& ex) {
throw py::value_error(ex.what());
Expand All @@ -2047,10 +2047,10 @@ PYBIND11_MODULE(monero, m) {
return &self;
}
catch(const PyMoneroRpcError& ex) {
throw ex;
throw;
}
catch(const PyMoneroError& ex) {
throw ex;
throw;
}
catch(const std::exception& ex) {
throw py::value_error(ex.what());
Expand All @@ -2063,10 +2063,10 @@ PYBIND11_MODULE(monero, m) {
return &self;
}
catch(const PyMoneroRpcError& ex) {
throw ex;
throw;
}
catch(const PyMoneroError& ex) {
throw ex;
throw;
}
catch(const std::exception& ex) {
throw py::value_error(ex.what());
Expand Down
16 changes: 8 additions & 8 deletions src/cpp/wallet/py_monero_wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ void PyMoneroWalletPoller::poll() {
// announce new unlocked outputs
for (const auto &unlocked_tx : unlocked_txs) {
std::string tx_hash = unlocked_tx->m_hash.get();
m_prev_confirmed_notifications.erase(std::remove_if(m_prev_confirmed_notifications.begin(), m_prev_confirmed_notifications.end(), [&tx_hash](std::string iter){ return iter == tx_hash; }), m_prev_confirmed_notifications.end());
m_prev_unconfirmed_notifications.erase(std::remove_if(m_prev_unconfirmed_notifications.begin(), m_prev_unconfirmed_notifications.end(), [&tx_hash](std::string iter){ return iter == tx_hash; }), m_prev_unconfirmed_notifications.end());
m_prev_confirmed_notifications.erase(std::remove_if(m_prev_confirmed_notifications.begin(), m_prev_confirmed_notifications.end(), [&tx_hash](const std::string& iter){ return iter == tx_hash; }), m_prev_confirmed_notifications.end());
m_prev_unconfirmed_notifications.erase(std::remove_if(m_prev_unconfirmed_notifications.begin(), m_prev_unconfirmed_notifications.end(), [&tx_hash](const std::string& iter){ return iter == tx_hash; }), m_prev_unconfirmed_notifications.end());
notify_outputs(unlocked_tx);
}

Expand All @@ -266,8 +266,8 @@ void PyMoneroWalletPoller::poll() {
}
}

std::shared_ptr<monero::monero_tx_wallet> PyMoneroWalletPoller::get_tx(const std::vector<std::shared_ptr<monero::monero_tx_wallet>> txs, std::string tx_hash) {
for (auto &tx : txs) {
std::shared_ptr<monero::monero_tx_wallet> PyMoneroWalletPoller::get_tx(const std::vector<std::shared_ptr<monero::monero_tx_wallet>>& txs, const std::string& tx_hash) {
for (auto tx : txs) {
if (tx->m_hash == tx_hash) return tx;
}

Expand Down Expand Up @@ -428,7 +428,7 @@ std::vector<std::string> PyMoneroWalletRpc::get_seed_languages() const {

void PyMoneroWalletRpc::stop() {
PyMoneroJsonRequest request("stop_wallet");
std::shared_ptr<PyMoneroJsonResponse> response = m_rpc->send_json_request(request);
m_rpc->send_json_request(request);
}

bool PyMoneroWalletRpc::is_view_only() const {
Expand All @@ -440,7 +440,7 @@ bool PyMoneroWalletRpc::is_view_only() const {
catch (const PyMoneroRpcError& e) {
if (e.code == -29) return true;
if (e.code == -1) return false;
throw e;
throw;
}
}

Expand Down Expand Up @@ -1471,14 +1471,14 @@ std::shared_ptr<monero_tx_config> PyMoneroWalletRpc::parse_payment_uri(const std

void PyMoneroWalletRpc::set_attribute(const std::string& key, const std::string& val) {
auto params = std::make_shared<PyMoneroWalletAttributeParams>(key, val);
PyMoneroJsonRequest request("set_attribute");
PyMoneroJsonRequest request("set_attribute", params);
std::shared_ptr<PyMoneroJsonResponse> response = m_rpc->send_json_request(request);
}

bool PyMoneroWalletRpc::get_attribute(const std::string& key, std::string& value) const {
try {
auto params = std::make_shared<PyMoneroWalletAttributeParams>(key);
PyMoneroJsonRequest request("get_attribute");
PyMoneroJsonRequest request("get_attribute", params);
std::shared_ptr<PyMoneroJsonResponse> response = m_rpc->send_json_request(request);
if (response->m_result == boost::none) throw std::runtime_error("Invalid Monero JSONRPC response");
auto res = response->m_result.get();
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/wallet/py_monero_wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ class PyMoneroWalletPoller {
boost::optional<uint64_t> m_prev_height;
std::vector<std::shared_ptr<monero::monero_tx_wallet>> m_prev_locked_txs;

std::shared_ptr<monero::monero_tx_wallet> get_tx(const std::vector<std::shared_ptr<monero::monero_tx_wallet>> txs, std::string tx_hash);
std::shared_ptr<monero::monero_tx_wallet> get_tx(const std::vector<std::shared_ptr<monero::monero_tx_wallet>>& txs, const std::string& tx_hash);
void loop();
void on_new_block(uint64_t height);
void notify_outputs(const std::shared_ptr<monero::monero_tx_wallet> &tx);
Expand Down
19 changes: 9 additions & 10 deletions src/cpp/wallet/py_monero_wallet_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,9 @@ void PyMoneroTxSet::from_sent_txs(const boost::property_tree::ptree& node, const

for (boost::property_tree::ptree::const_iterator it = node.begin(); it != node.end(); ++it) {
std::string key = it->first;
int i = 0;
if (key == std::string("tx_hash_list") && num_txs == 0) {
auto node2 = it->second;
i = 0;
int i = 0;
for (auto it2 = node2.begin(); it2 != node2.end(); ++it2) {
auto tx = txs[i];
tx->m_hash = it2->second.data();
Expand All @@ -478,7 +477,7 @@ void PyMoneroTxSet::from_sent_txs(const boost::property_tree::ptree& node, const
}
else if (key == std::string("tx_key_list") && num_txs == 0) {
auto node2 = it->second;
i = 0;
int i = 0;
for (auto it2 = node2.begin(); it2 != node2.end(); ++it2) {
auto tx = txs[i];
tx->m_key = it2->second.data();
Expand All @@ -487,7 +486,7 @@ void PyMoneroTxSet::from_sent_txs(const boost::property_tree::ptree& node, const
}
else if (key == std::string("tx_blob_list") && num_txs == 0) {
auto node2 = it->second;
i = 0;
int i = 0;
for (auto it2 = node2.begin(); it2 != node2.end(); ++it2) {
auto tx = txs[i];
tx->m_full_hex = it2->second.data();
Expand All @@ -496,7 +495,7 @@ void PyMoneroTxSet::from_sent_txs(const boost::property_tree::ptree& node, const
}
else if (key == std::string("tx_metadata_list") && num_txs == 0) {
auto node2 = it->second;
i = 0;
int i = 0;
for (auto it2 = node2.begin(); it2 != node2.end(); ++it2) {
auto tx = txs[i];
tx->m_metadata = it2->second.data();
Expand All @@ -505,7 +504,7 @@ void PyMoneroTxSet::from_sent_txs(const boost::property_tree::ptree& node, const
}
else if (key == std::string("fee_list") && num_txs == 0) {
auto node2 = it->second;
i = 0;
int i = 0;
for (auto it2 = node2.begin(); it2 != node2.end(); ++it2) {
auto tx = txs[i];
tx->m_fee = it2->second.get_value<uint64_t>();
Expand All @@ -514,7 +513,7 @@ void PyMoneroTxSet::from_sent_txs(const boost::property_tree::ptree& node, const
}
else if (key == std::string("amount_list") && num_txs == 0) {
auto node2 = it->second;
i = 0;
int i = 0;
for (auto it2 = node2.begin(); it2 != node2.end(); ++it2) {
auto tx = txs[i];
auto outgoing_transfer = std::make_shared<monero::monero_outgoing_transfer>();
Expand All @@ -526,7 +525,7 @@ void PyMoneroTxSet::from_sent_txs(const boost::property_tree::ptree& node, const
}
else if (key == std::string("weight_list") && num_txs == 0) {
auto node2 = it->second;
i = 0;
int i = 0;
for (auto it2 = node2.begin(); it2 != node2.end(); ++it2) {
auto tx = txs[i];
tx->m_weight = it2->second.get_value<uint64_t>();
Expand All @@ -535,7 +534,7 @@ void PyMoneroTxSet::from_sent_txs(const boost::property_tree::ptree& node, const
}
else if (key == std::string("spent_key_images_list") && num_txs == 0) {
auto node2 = it->second;
i = 0;
int i = 0;
for (auto it2 = node2.begin(); it2 != node2.end(); ++it2) {
auto tx = txs[i];
if (tx->m_inputs.size() > 0) throw std::runtime_error("Expected no inputs in sent tx");
Expand All @@ -562,7 +561,7 @@ void PyMoneroTxSet::from_sent_txs(const boost::property_tree::ptree& node, const
}
else if (key == std::string("amounts_by_dest_list") && num_txs == 0) {
auto node2 = it->second;
i = 0;
int i = 0;
int destination_idx = 0;

for (auto it2 = node2.begin(); it2 != node2.end(); ++it2) {
Expand Down
8 changes: 6 additions & 2 deletions tests/test_monero_daemon_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
MoneroHardForkInfo, MoneroAltChain, MoneroTx, MoneroSubmitTxResult,
MoneroTxPoolStats
)
from utils import MoneroTestUtils as Utils, TestContext, BinaryBlockContext
from utils import MoneroTestUtils as Utils, TestContext, BinaryBlockContext, MiningUtils


# TODO enable rpc daemon tests
class TestMoneroDaemonRpc:
_daemon: MoneroDaemonRpc = Utils.get_daemon_rpc()
_wallet: MoneroWalletRpc #= Utils.get_wallet_rpc()
BINARY_BLOCK_CTX: BinaryBlockContext = BinaryBlockContext()

@pytest.fixture(scope="class", autouse=True)
def before_all(self):
MiningUtils.wait_for_height(101)
MiningUtils.try_stop_mining()

# Can get the daemon's version
@pytest.mark.skipif(Utils.TEST_NON_RELAYS is False, reason="TEST_NON_RELAYS disabled")
def test_get_version(self):
Expand Down
28 changes: 14 additions & 14 deletions tests/test_monero_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Config:
stagenet: AddressBook = AddressBook()
keys: KeysBook = KeysBook()
serialization_msg: str = ''

@classmethod
def parse(cls, parser: ConfigParser) -> TestMoneroUtils.Config:
config = cls()
Expand Down Expand Up @@ -111,19 +111,19 @@ def test_serialize_text_long(self, config: TestMoneroUtils.Config):
msg = config.serialization_msg
json_map: dict[str, str] = {
"msg": f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n"
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n" +
f"{msg}\n"
}

binary: bytes = MoneroUtils.dict_to_binary(json_map)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_monero_wallet_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_create_wallet_from_keys(self) -> None:

except Exception as e:
e2 = e

self._close_wallet(wallet)
if e2 is not None:
raise e2
Expand Down
2 changes: 1 addition & 1 deletion tests/test_monero_wallet_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _create_wallet(self, config: Optional[MoneroWalletConfig]):
config = MoneroWalletConfig()
print("create_wallet(self): created config")

print(f"""create_wallet():
print(f"""create_wallet():
seed: {config.seed},
address: {config.primary_address},
view key: {config.private_view_key},
Expand Down
2 changes: 2 additions & 0 deletions tests/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .monero_test_utils import MoneroTestUtils
from .mining_utils import MiningUtils
from .wallet_sync_printer import WalletSyncPrinter
from .connection_change_collector import ConnectionChangeCollector
from .address_book import AddressBook
Expand All @@ -14,6 +15,7 @@

__all__ = [
'MoneroTestUtils',
'MiningUtils',
'WalletSyncPrinter',
'ConnectionChangeCollector',
'AddressBook',
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/const.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MINING_ADDRESS = "9tsUiG9bwcU7oTbAdBwBk2PzxFtysge5qcEsHEpetmEKgerHQa1fDqH7a4FiquZmms7yM22jdifVAD7jAb2e63GSJMuhY75"
MINING_ADDRESS = "42U9v3qs5CjZEePHBZHwuSckQXebuZu299NSmVEmQ41YJZQhKcPyujyMSzpDH4VMMVSBo3U3b54JaNvQLwAjqDhKS3rvM3L"
Loading
Loading