add script to inspect database

This commit is contained in:
Jethro Grassie 2019-05-07 01:12:30 -04:00
parent e407929555
commit 257560b0a7
No known key found for this signature in database
GPG key ID: DE8ED755616565BB
3 changed files with 55 additions and 9 deletions

2
.gitattributes vendored
View file

@ -1 +1 @@
monero/* linguist-vendored
tools/* linguist-vendored

View file

@ -82,9 +82,6 @@ PKG_INC := $(shell pkg-config \
LIBPATH := /opt/local/lib/ /usr/local/lib
# Which files to add to backups, apart from the source code
EXTRA_FILES = Makefile
C++ = g++
CC = gcc
XXD := $(shell command -v xxd 2> /dev/null)
@ -104,12 +101,13 @@ CDFILES := $(addprefix $(STORE)/,$(CSOURCE:.c=.d))
SDFILES := $(addprefix $(STORE)/,$(CSOURCE:.S=.d))
.PHONY: clean backup dirs debug release preflight
.PHONY: clean dirs debug release preflight
$(TARGET): preflight dirs $(OBJECTS) $(COBJECTS) $(SOBJECTS) $(HTMLOBJECTS)
@echo Linking $(OBJECTS)...
$(C++) -o $(STORE)/$(TARGET) $(OBJECTS) $(COBJECTS) $(SOBJECTS) $(HTMLOBJECTS) $(LDPARAM) $(MONERO_LIBS) $(foreach LIBRARY, $(LIBS),-l$(LIBRARY)) $(foreach LIB,$(LIBPATH),-L$(LIB)) $(PKG_LIBS) $(STATIC_LIBS)
@cp pool.conf $(STORE)/
@cp tools/* $(STORE)/
$(STORE)/%.o: %.cpp
@echo Creating object file for $*...
@ -149,10 +147,6 @@ clean:
@find ./build -type f -name '*.d' -delete
@find ./build -type f -name $(TARGET) -delete
backup:
@-if [ ! -e build/backup ]; then mkdir -p build/backup; fi;
@zip build/backup/backup_`date +%d-%m-%y_%H.%M`.zip $(SOURCE) $(HEADERS) $(EXTRA_FILES)
dirs:
@-if [ ! -e $(STORE) ]; then mkdir -p $(STORE); fi;
@-$(foreach DIR,$(DIRS), if [ ! -e $(STORE)/$(DIR) ]; then mkdir -p $(STORE)/$(DIR); fi; )

52
tools/inspect-data vendored Executable file
View file

@ -0,0 +1,52 @@
#!/usr/bin/env python
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)
group.add_argument('-b', '--balances', action='store_true', help='list miner balances')
group.add_argument('-p', '--payments', action='store_true', help='list payments made')
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()