aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbenevanoff <benjaminevanoff99@gmail.com>2023-11-03 18:40:57 -0500
committernahuhh <50635951+nahuhh@users.noreply.github.com>2025-07-07 22:21:39 +0000
commit678f5dab31aa27c9e6e1fb24a4c1f683ef242e1a (patch)
tree8bf8f3eb46f40f9f4d4da0d61fb687acd5fe0651
parent8f5a7b0f1a0c2954a249318cf2f3760096991b67 (diff)
downloadmonzero-core-678f5dab31aa27c9e6e1fb24a4c1f683ef242e1a.tar.gz
monzero-core-678f5dab31aa27c9e6e1fb24a4c1f683ef242e1a.tar.xz
monzero-core-678f5dab31aa27c9e6e1fb24a4c1f683ef242e1a.zip
wallet: create set_subaddress_lookahead wallet rpc endpoint
-rw-r--r--src/wallet/wallet_rpc_server.cpp12
-rw-r--r--src/wallet/wallet_rpc_server.h2
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h23
-rwxr-xr-xtests/functional_tests/wallet.py15
-rw-r--r--utils/python-rpc/framework/wallet.py12
5 files changed, 63 insertions, 1 deletions
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 3188c88db..37e0968b8 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -650,6 +650,18 @@ namespace tools
res.index = *index;
return true;
}
+ bool wallet_rpc_server::on_set_subaddr_lookahead(const wallet_rpc::COMMAND_RPC_SET_SUBADDR_LOOKAHEAD::request& req, wallet_rpc::COMMAND_RPC_SET_SUBADDR_LOOKAHEAD::response& res, epee::json_rpc::error& er, const connection_context *ctx)
+ {
+ if (!m_wallet) return not_open(er);
+ try {
+ m_wallet->set_subaddress_lookahead(req.major_idx, req.minor_idx);
+ }
+ catch (const std::exception& e) {
+ handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
+ return false;
+ }
+ return true;
+ }
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_create_address(const wallet_rpc::COMMAND_RPC_CREATE_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_CREATE_ADDRESS::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index c9657a430..51d768ed2 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -71,6 +71,7 @@ namespace tools
MAP_JON_RPC_WE("get_balance", on_getbalance, wallet_rpc::COMMAND_RPC_GET_BALANCE)
MAP_JON_RPC_WE("get_address", on_getaddress, wallet_rpc::COMMAND_RPC_GET_ADDRESS)
MAP_JON_RPC_WE("get_address_index", on_getaddress_index, wallet_rpc::COMMAND_RPC_GET_ADDRESS_INDEX)
+ MAP_JON_RPC_WE("set_subaddress_lookahead", on_set_subaddr_lookahead, wallet_rpc::COMMAND_RPC_SET_SUBADDR_LOOKAHEAD)
MAP_JON_RPC_WE("getbalance", on_getbalance, wallet_rpc::COMMAND_RPC_GET_BALANCE)
MAP_JON_RPC_WE("getaddress", on_getaddress, wallet_rpc::COMMAND_RPC_GET_ADDRESS)
MAP_JON_RPC_WE("create_address", on_create_address, wallet_rpc::COMMAND_RPC_CREATE_ADDRESS)
@@ -171,6 +172,7 @@ namespace tools
bool on_getbalance(const wallet_rpc::COMMAND_RPC_GET_BALANCE::request& req, wallet_rpc::COMMAND_RPC_GET_BALANCE::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_getaddress(const wallet_rpc::COMMAND_RPC_GET_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_GET_ADDRESS::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_getaddress_index(const wallet_rpc::COMMAND_RPC_GET_ADDRESS_INDEX::request& req, wallet_rpc::COMMAND_RPC_GET_ADDRESS_INDEX::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
+ bool on_set_subaddr_lookahead(const wallet_rpc::COMMAND_RPC_SET_SUBADDR_LOOKAHEAD::request& req, wallet_rpc::COMMAND_RPC_SET_SUBADDR_LOOKAHEAD::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_create_address(const wallet_rpc::COMMAND_RPC_CREATE_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_CREATE_ADDRESS::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_label_address(const wallet_rpc::COMMAND_RPC_LABEL_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_LABEL_ADDRESS::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_get_accounts(const wallet_rpc::COMMAND_RPC_GET_ACCOUNTS::request& req, wallet_rpc::COMMAND_RPC_GET_ACCOUNTS::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index d3503264b..4a11845d4 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -47,7 +47,7 @@
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define WALLET_RPC_VERSION_MAJOR 1
-#define WALLET_RPC_VERSION_MINOR 28
+#define WALLET_RPC_VERSION_MINOR 29
#define MAKE_WALLET_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define WALLET_RPC_VERSION MAKE_WALLET_RPC_VERSION(WALLET_RPC_VERSION_MAJOR, WALLET_RPC_VERSION_MINOR)
namespace tools
@@ -182,6 +182,27 @@ namespace wallet_rpc
typedef epee::misc_utils::struct_init<response_t> response;
};
+ struct COMMAND_RPC_SET_SUBADDR_LOOKAHEAD
+ {
+ struct request_t
+ {
+ uint32_t major_idx;
+ uint32_t minor_idx;
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(major_idx)
+ KV_SERIALIZE(minor_idx)
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+ struct response_t
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<response_t> response;
+ };
+
struct COMMAND_RPC_CREATE_ADDRESS
{
struct request_t
diff --git a/tests/functional_tests/wallet.py b/tests/functional_tests/wallet.py
index 8182cecb2..1cbe4ee68 100755
--- a/tests/functional_tests/wallet.py
+++ b/tests/functional_tests/wallet.py
@@ -47,6 +47,7 @@ class WalletTest():
self.check_keys()
self.create_subaddresses()
self.tags()
+ self.update_lookahead()
self.attributes()
self.open_close()
self.languages()
@@ -164,6 +165,20 @@ class WalletTest():
res = wallet.label_account(0, "main")
+ def update_lookahead(self):
+ print('Updating subaddress lookahead')
+ wallet = Wallet()
+ address_0_999 = '8BQKgTSSqJjP14AKnZUBwnXWj46MuNmLvHfPTpmry52DbfNjjHVvHUk4mczU8nj8yZ57zBhksTJ8kM5xKeJXw55kCMVqyG7' # this is the address for address 999 of the main account in the test wallet
+ try: # assert address_1_999 is not in the current pubkey table
+ wallet.get_address_index(address_0_999)
+ except Exception as e:
+ assert str(e) == "{'error': {'code': -2, 'message': \"Address doesn't belong to the wallet\"}, 'id': '0', 'jsonrpc': '2.0'}"
+ # update the lookahead and assert the high index address is now in the table
+ wallet.set_subaddress_lookahead(50, 1000)
+ r = wallet.get_address_index(address_0_999)
+ assert r['index']['major'] == 0
+ assert r['index']['minor'] == 999
+
def tags(self):
print('Testing tags')
wallet = Wallet()
diff --git a/utils/python-rpc/framework/wallet.py b/utils/python-rpc/framework/wallet.py
index 010f4dd08..d7cbde5da 100644
--- a/utils/python-rpc/framework/wallet.py
+++ b/utils/python-rpc/framework/wallet.py
@@ -333,6 +333,18 @@ class Wallet(object):
}
return self.rpc.send_json_rpc_request(generate_from_keys)
+ def set_subaddress_lookahead(self, major_idx: int, minor_idx: int):
+ lookahead = {
+ 'method': 'set_subaddress_lookahead',
+ 'jsonrpc': '2.0',
+ 'params' : {
+ 'major_idx': major_idx,
+ 'minor_idx': minor_idx
+ },
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(lookahead)
+
def open_wallet(self, filename, password='', autosave_current = True):
open_wallet = {
'method': 'open_wallet',