2019-05-07 05:12:30 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2019-05-11 03:44:28 +00:00
|
|
|
'''
|
|
|
|
Copyright (c) 2014-2019, 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.
|
|
|
|
|
|
|
|
Parts of the project are originally copyright (c) 2012-2013 The Cryptonote
|
|
|
|
developers.
|
|
|
|
'''
|
|
|
|
|
2019-05-07 05:12:30 +00:00
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
import lmdb
|
|
|
|
import struct
|
|
|
|
from ctypes import *
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
def print_balance(path):
|
|
|
|
env = lmdb.open(path, readonly=True, max_dbs=1, create=False)
|
|
|
|
balance = env.open_db('balance'.encode())
|
|
|
|
with env.begin(db=balance) as txn:
|
|
|
|
with txn.cursor() as curs:
|
|
|
|
for key, value in curs:
|
|
|
|
address = key.decode('utf-8').rstrip('\0')
|
|
|
|
address = '{}...{}'.format(address[:8], address[-8:])
|
|
|
|
amount = c_longlong.from_buffer_copy(value).value
|
|
|
|
amount = '{0:.6f}'.format(amount/1e12)
|
|
|
|
print('{}\t{}'.format(address, amount))
|
|
|
|
env.close()
|
|
|
|
|
|
|
|
def print_payements(path):
|
|
|
|
env = lmdb.open(path, readonly=True, max_dbs=1, create=False)
|
|
|
|
payments = env.open_db('payments'.encode())
|
|
|
|
with env.begin(db=payments) as txn:
|
|
|
|
with txn.cursor() as curs:
|
|
|
|
for key, value in curs:
|
|
|
|
address = key.decode('utf-8').rstrip('\0')
|
|
|
|
address = '{}...{}'.format(address[:8], address[-8:])
|
|
|
|
amount, ts, addr = struct.unpack("Q Q 128s", value)
|
|
|
|
amount = '{0:.6f}'.format(amount/1e12)
|
|
|
|
dt = datetime.fromtimestamp(ts)
|
|
|
|
print('{}\t{}\t{}'.format(address, amount,
|
|
|
|
dt.strftime('%Y-%m-%d %H:%M:%S')))
|
|
|
|
env.close()
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
group = parser.add_mutually_exclusive_group(required=True)
|
2019-05-11 03:44:28 +00:00
|
|
|
group.add_argument('-b', '--balances', action='store_true',
|
|
|
|
help='list miner balances')
|
|
|
|
group.add_argument('-p', '--payments', action='store_true',
|
|
|
|
help='list payments made')
|
2019-05-07 05:12:30 +00:00
|
|
|
parser.add_argument('database', help='path to database')
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.balances:
|
|
|
|
print_balance(args.database)
|
|
|
|
elif args.payments:
|
|
|
|
print_payements(args.database)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|