From 257560b0a748b1a561e81332fafb00ca63366f4b Mon Sep 17 00:00:00 2001 From: Jethro Grassie Date: Tue, 7 May 2019 01:12:30 -0400 Subject: [PATCH] add script to inspect database --- .gitattributes | 2 +- Makefile | 10 ++------- tools/inspect-data | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 9 deletions(-) create mode 100755 tools/inspect-data diff --git a/.gitattributes b/.gitattributes index beab703..6217f81 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -monero/* linguist-vendored +tools/* linguist-vendored diff --git a/Makefile b/Makefile index 234db42..2ed9cb6 100644 --- a/Makefile +++ b/Makefile @@ -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; ) diff --git a/tools/inspect-data b/tools/inspect-data new file mode 100755 index 0000000..da8ff89 --- /dev/null +++ b/tools/inspect-data @@ -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() +