Created
November 8, 2023 12:34
-
-
Save plowsof/c9a8e3af3d173879c0fdcef28ace8538 to your computer and use it in GitHub Desktop.
scan_tx + custom-background-password issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from monerorpc.authproxy import AuthServiceProxy, JSONRPCException | |
import os | |
#./monero-wallet-rpc --disable-rpc-login --rpc-bind-port 18082 --stagenet --wallet-dir /home/human/monero/build/Linux/view_sync/release/bin --daemon-host node2.monerodevs.org:38089 --trusted | |
wallet_dir = "/home/human/monero/build/Linux/view_sync/release/bin" | |
daemon_address = "node2.monerodevs.org:38089" | |
rpc_url = "http://127.0.0.1:18082/json_rpc" | |
test_wallet = "stager" | |
rpc_connection = AuthServiceProxy(service_url=rpc_url) | |
original_balance = 0 | |
def get_txids_2(get_transfers): | |
txids = {} | |
for i in get_transfers["in"]: | |
txids[i["txid"]] = i["height"] | |
for i in get_transfers["out"]: | |
txids[i["txid"]] = i["height"] | |
return txids | |
def restore_wallet(fname,seed,height,txids,sync=False): | |
global wallet_dir, rpc_connection, original_balance | |
params = { | |
"filename": fname, | |
"seed": seed, | |
"password": "", | |
"restore_height": height | |
} | |
if os.path.isfile(f"{wallet_dir}{fname}"): | |
os.remove(f"{wallet_dir}{fname}") | |
os.remove(f"{wallet_dir}{fname}.keys") | |
make_new = rpc_connection.restore_deterministic_wallet(params) | |
if sync: | |
params = { | |
"background_sync_type":"custom-background-password", | |
"background_cache_password":"lol" | |
} | |
rpc_connection.setup_background_sync(params) | |
rpc_connection.start_background_sync() | |
for txid in txids: | |
rpc_connection.scan_tx({"txids":[txid[0]]}) | |
balance = rpc_connection.get_balance()["balance"] | |
if sync: | |
print(f"Balance before sync disabled: {balance}") | |
else: | |
original_balance = balance | |
print(f"Original balance: {balance}") | |
if sync: | |
rpc_connection.stop_background_sync({"wallet_password":""}) | |
seed = rpc_connection.query_key({"key_type":"mnemonic"})["key"] | |
print(seed) | |
balance = rpc_connection.get_balance()["balance"] | |
print(f"Balance after sync disabled: {balance}") | |
assert balance == original_balance | |
def main(gui=False): | |
global wallet_dir,rpc_url,test_wallet,daemon_address,rpc_connection | |
try: rpc_connection.close_wallet() | |
except: pass | |
rpc_connection.open_wallet({"filename": test_wallet,"password": ""}) | |
transfers = rpc_connection.get_transfers({"in": True,"out": True,}) | |
txids = get_txids_2(transfers) | |
sorted_txids = sorted(txids.items(), key=lambda x: int(x[1])) | |
seed = rpc_connection.query_key({"key_type":"mnemonic"})["key"] | |
height = rpc_connection.get_height()["height"] | |
try: | |
os.remove("restored_wallet") | |
os.remove("restored_wallet.keys") | |
os.remove("restored_wallet_sync") | |
os.remove("restored_wallet_sync.keys") | |
os.remove("restored_wallet_sync.background") | |
os.remove("restored_wallet_sync.background.keys") | |
except: pass | |
restore_wallet("restored_wallet",seed,height,sorted_txids) | |
rpc_connection.store() | |
restore_wallet("restored_wallet_sync",seed,height,sorted_txids,True) | |
rpc_connection.store() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment