From c5c7e28076b2be1be3aa45702c502278819a4fe8 Mon Sep 17 00:00:00 2001 From: Sergi Delgado Date: Fri, 15 Jun 2018 12:44:46 +0200 Subject: [PATCH] Last updates pre-release --- README.md | 6 +++--- bitcoin_tools/analysis/status/README.md | 2 ++ bitcoin_tools/analysis/status/data_dump.py | 21 +++++++++++++++++++++ bitcoin_tools/analysis/status/utils.py | 15 +++++---------- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index de341cf..ab40666 100644 --- a/README.md +++ b/README.md @@ -113,14 +113,14 @@ from bitcoin_tools.analysis.status.utils import parse_ldb # Set the version of the Bitcoin Core you are using (which defines the chainstate format) # and the IO files. -version = 0.15 + f_utxos = "decoded_utxos.txt" f_parsed_utxos = "parsed_utxos.txt" # Parse all the data in the chainstate. -parse_ldb(f_utxos, version=version) +parse_ldb(f_utxos) # Parses transactions and utxos from the dumped data. -utxo_dump(f_utxos, f_parsed_utxos, version=version) +utxo_dump(f_utxos, f_parsed_utxos) # Data is stored in f_utxos and f_parsed_utxos files respectively ``` diff --git a/bitcoin_tools/analysis/status/README.md b/bitcoin_tools/analysis/status/README.md index f3d543c..377aa10 100644 --- a/bitcoin_tools/analysis/status/README.md +++ b/bitcoin_tools/analysis/status/README.md @@ -1,5 +1,7 @@ # STATUS +### THIS VERSION ONLY WORKS WITH BITCOIN CORE'S LEVELDB 0.14-, FOR 0.15+ REFER TO THE MASTER BRANCH. + **STATUS** (**ST**atistical **A**nalysis **T**ool for **U**txo **S**et) is an open source tool that provides an easy way to access, decode and analyze data from the Bitcoin's `utxo set`. The accompanying working paper further explains its design, application, and presents results of a recently performed analysis: [https://eprint.iacr.org/2017/1095.pdf](https://eprint.iacr.org/2017/1095.pdf) diff --git a/bitcoin_tools/analysis/status/data_dump.py b/bitcoin_tools/analysis/status/data_dump.py index ea2c6a2..d94f506 100644 --- a/bitcoin_tools/analysis/status/data_dump.py +++ b/bitcoin_tools/analysis/status/data_dump.py @@ -7,6 +7,16 @@ def transaction_dump(fin_name, fout_name): + """ + Reads from a parsed utxo file and dumps additional metadata related to transactions. + :param fin_name: Name of the parsed utxo file. + :type fin_name: str + :param fout_name: Name of the file where the final data will be stored. + :type fout_name: str + :return: None + :rtype: None + """ + # Transaction dump # Input file @@ -34,6 +44,17 @@ def transaction_dump(fin_name, fout_name): def utxo_dump(fin_name, fout_name, coin, count_p2sh=False, non_std_only=False, ordered_dict=False): + """ + Reads from a parsed utxo file and dumps additional metadata related to utxos. + :param fin_name: Name of the parsed utxo file. + :type fin_name: str + :param fout_name: Name of the file where the final data will be stored. + :type fout_name: str + :param coin: Currency that will be analysed + :return: None + :rtype: None + """ + # UTXO dump # Input file diff --git a/bitcoin_tools/analysis/status/utils.py b/bitcoin_tools/analysis/status/utils.py index d95e744..75f6b77 100644 --- a/bitcoin_tools/analysis/status/utils.py +++ b/bitcoin_tools/analysis/status/utils.py @@ -566,7 +566,6 @@ def check_multisig_type(script): """ if len(OutputScript.deserialize(script).split()) > 2: - # TODO: should we be more restrictive? m = OutputScript.deserialize(script).split()[0] n = OutputScript.deserialize(script).split()[-2] op_multisig = OutputScript.deserialize(script).split()[-1] @@ -820,15 +819,13 @@ def get_est_input_size(out, height, p2pkh_pksize, p2sh_scriptsize, nonstd_script return fixed_size + var_size -def get_utxo(tx_id, index, fin_name=CFG.chainstate_path): +def get_tx(tx_id, fin_name=CFG.chainstate_path): """ Gets a UTXO from the chainstate identified by a given transaction id and index. If the requested UTXO does not exist, return None. :param tx_id: Transaction ID that identifies the UTXO you are looking for. :type tx_id: str - :param index: Index that identifies the specific output. - :type index: int :param fin_name: Name of the LevelDB folder (chainstate by default) :type fin_name: str :return: A outpoint:coin pair representing the requested UTXO @@ -849,16 +846,14 @@ def get_utxo(tx_id, index, fin_name=CFG.chainstate_path): if o_key is not None: o_key = hexlify(o_key)[2:] - coin = db.get(outpoint) + tx = db.get(outpoint) - if coin is not None and o_key is not None: - coin = deobfuscate_value(o_key, hexlify(coin)) + if tx is not None and o_key is not None: + tx = deobfuscate_value(o_key, hexlify(tx)) db.close() - # ToDO: Add code to return a single output for 0.8 - 0.14 - - return coin + return tx def deobfuscate_value(obfuscation_key, value):