townforge/utils/python-rpc/framework/daemon_util.py

104 lines
4.6 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.
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
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
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
res = daemon.cc_get_last_update_events()
state['events'] = res
state['events']['top_hash'] = 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)
state['item_counts'] = res.counts if 'counts' in res else 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
return state