Last active
November 7, 2023 05:39
-
-
Save plowsof/dee4c3f114c7ab843c54b1744be6deb8 to your computer and use it in GitHub Desktop.
restore wallet with scan_tx , repeat with background sync active then compare after background sync is stopped
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: | |
rpc_connection.setup_background_sync({"background_sync_type":"reuse-wallet-password"}) | |
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":""}) | |
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") | |
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() | |
''' | |
Original balance: 14588721690000 | |
Balance before sync disabled: 46487645850000 | |
Balance after sync disabled: 14588721690000 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment