forked from townforge/townforge
159 lines
6.9 KiB
Python
159 lines
6.9 KiB
Python
# Copyright (c) 2018 The Monero Project
|
|
#
|
|
# All rights reserved.
|
|
#
|
|
# Redistribution and use in source and binary forms, with or without modification, are
|
|
# permitted provided that the following conditions are met:
|
|
#
|
|
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
# conditions and the following disclaimer.
|
|
#
|
|
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
# of conditions and the following disclaimer in the documentation and/or other
|
|
# materials provided with the distribution.
|
|
#
|
|
# 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
# used to endorse or promote products derived from this software without specific
|
|
# prior written permission.
|
|
#
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
import os
|
|
import subprocess
|
|
from .daemon import Daemon
|
|
|
|
def get_daemon_state(daemon):
|
|
state = {}
|
|
res = daemon.get_info()
|
|
state['info.height'] = res.height
|
|
state['info.diff'] = res.difficulty
|
|
state['info.block_size_median'] = res.block_size_median
|
|
res = daemon.cc_get_cities()
|
|
state['cities'] = res
|
|
num_cities = len(res.cities)
|
|
for i in range(num_cities):
|
|
try:
|
|
res = daemon.cc_get_city(i)
|
|
state['city_' + str(i)] = res
|
|
res = daemon.cc_get_special_events(i, False)
|
|
state['city_' + str(i) + '_special_events'] = res
|
|
res = daemon.cc_get_special_events(i, True)
|
|
state['city_' + str(i) + '_special_events_all'] = res
|
|
except:
|
|
pass
|
|
try:
|
|
res = daemon.cc_get_shares(i)
|
|
state['city_' + str(i) + '_shares'] = res
|
|
except:
|
|
pass
|
|
try:
|
|
res = daemon.cc_get_vistas(i)
|
|
state['city_' + str(i) + '_vistas'] = res
|
|
except:
|
|
pass
|
|
res = daemon.cc_get_accounts()
|
|
state['accounts'] = res.accounts
|
|
accounts = [x.id for x in res.accounts]
|
|
for i in accounts:
|
|
res = daemon.cc_get_account(i)
|
|
state['account_' + str(i)] = res
|
|
if 'ancestors' in res:
|
|
res = daemon.cc_get_ancestors(ids = res.ancestors)
|
|
state['account_' + str(i) + '_ancestors'] = res
|
|
res = daemon.cc_get_flags()
|
|
state['flags'] = res.flags if 'flags' in res else None
|
|
flags = [x.id for x in res.flags] if 'flags' in res else []
|
|
for i in flags:
|
|
res = daemon.cc_get_flag(i)
|
|
state['flag_' + str(i)] = res
|
|
if 'items_' in res:
|
|
res2 = daemon.cc_get_role_bonus([{'item': x.type, 'amount': x.amount} for x in res.items_], res.role, res.x1 - res.x0 + 1, res.y1 - res.y0 + 1)
|
|
assert res2.role_bonus == res.role_bonus, str(res2) + "\n" + str(res)
|
|
else:
|
|
assert res.role_bonus == 0
|
|
res = daemon.cc_get_last_update_events()
|
|
state['events'] = res
|
|
state['events']['block_hash'] = None
|
|
state['events']['top_hash'] = None
|
|
state['events']['timestamp'] = None
|
|
# do not include orders, those include txpool state so not conensus
|
|
res = daemon.cc_get_discoveries()
|
|
state['discoveries'] = res
|
|
res = daemon.cc_get_custom_items()
|
|
state['custom_items'] = res
|
|
first_custom_item_id = res.items_[0].id
|
|
try:
|
|
res = daemon.cc_get_badge([])
|
|
state['event_badges'] = res
|
|
except:
|
|
pass
|
|
res = daemon.cc_get_attributes()
|
|
state['attributes'] = res
|
|
res = daemon.cc_get_bonuses(accounts)
|
|
state['bonuses'] = res.bonuses
|
|
res = daemon.cc_get_badge_totals()
|
|
state['badge_totals'] = res.entries
|
|
ids = [x for x in range(first_custom_item_id)]
|
|
res = daemon.cc_get_item_count(ids)
|
|
if 'counts' in res:
|
|
state['item_counts'] = []
|
|
for i in range(len(res.counts)):
|
|
if res.counts[i]:
|
|
state['item_counts'] += [i, res.counts[i]]
|
|
else:
|
|
state['item_counts'] = None
|
|
res = daemon.cc_get_used_nonces()
|
|
state['used_nonces'] = res.nonces if 'nonces' in res else None
|
|
res = daemon.cc_get_scripts()
|
|
state['scripts'] = res.scripts if 'scripts' in res else None
|
|
res = daemon.cc_get_script_variables()
|
|
state['script_variables'] = res.script_variables if 'script_variables' in res else None
|
|
res = daemon.cc_get_foreclosures()
|
|
state['foreclosures'] = res.foreclosures if 'foreclosures' in res else None
|
|
res = daemon.cc_get_blobs()
|
|
state['blobs'] = {}
|
|
for h in res.hashes if 'hashes' in res else []:
|
|
res2 = daemon.cc_get_blob(h)
|
|
state['blobs'][h] = res2.blob
|
|
for i in range(num_cities):
|
|
state['whispers_' + str(i)] = daemon.cc_get_whispers(i)
|
|
state['far_fish'] = daemon.cc_get_far_fish_population()
|
|
for i in range(num_cities):
|
|
state['places_' + str(i)] = daemon.cc_get_places(i)
|
|
state['user_textures'] = daemon.cc_get_user_textures(0, False)
|
|
state['merchant_ship_available_items'] = daemon.cc_get_merchant_ship_available_items()
|
|
state['merchant_ships'] = daemon.cc_get_merchant_ships()
|
|
state['epochs'] = daemon.cc_get_epochs()
|
|
state['coru_games'] = daemon.cc_get_coru_games(active_only = False)
|
|
state['coru_tournaments'] = daemon.cc_get_coru_tournaments(active_only = False)
|
|
state['trustee_balances'] = daemon.cc_get_trustee_balances()
|
|
state['lightsources'] = daemon.cc_get_lightsources()
|
|
return state
|
|
|
|
def backup_daemon_blockchain(daemon, tag = "backup"):
|
|
mdb_copy = os.environ["MDB_COPY"]
|
|
chaindir = os.environ["CC_DATADIR_" + str(daemon.idx)]
|
|
source = chaindir + "/fake/lmdb"
|
|
destination = chaindir + "/fake-" + tag + "/lmdb"
|
|
try:
|
|
os.makedirs(destination)
|
|
except:
|
|
pass
|
|
try:
|
|
os.unlink(destination + '/data.mdb')
|
|
os.unlink(destination + '/lock.mdb')
|
|
except:
|
|
pass
|
|
command_line = [mdb_copy, source, destination]
|
|
print("Backing up " + str(chaindir) + " to " + str(destination))
|
|
p = subprocess.Popen(command_line)
|
|
p.wait()
|