diff --git a/blockscipy/blocksci/__init__.py b/blockscipy/blocksci/__init__.py index da347b57..dcafe35a 100644 --- a/blockscipy/blocksci/__init__.py +++ b/blockscipy/blocksci/__init__.py @@ -22,6 +22,7 @@ from multiprocess import Pool import dateparser from dateutil.relativedelta import relativedelta +import numpy as np import pandas as pd from ._blocksci import * @@ -636,6 +637,15 @@ def setup_range_and_proxy_methods(blocksci_range): setup_range_and_proxy_methods(cluster.TaggedAddressRange) +# Fix timestamp difference between normal Pybind11 datetime conversion and numpy arrays +def new_time(block: Block): + return np.datetime64(block.timestamp, "s").astype("datetime64[ns]") +Block.time = property(new_time) +def new_tx_time(tx: Tx): + return np.datetime64(tx.block_timestamp, "s").astype("datetime64[ns]") +Tx.block_time = property(new_tx_time) + + def txes_including_output_of_type(txes, typ): return txes.where(lambda tx: tx.outputs.any(lambda o: o.address_type == typ)) diff --git a/blockscipy/src/chain/tx/tx_proxy_py.cpp b/blockscipy/src/chain/tx/tx_proxy_py.cpp index fe6964fe..f44867ab 100644 --- a/blockscipy/src/chain/tx/tx_proxy_py.cpp +++ b/blockscipy/src/chain/tx/tx_proxy_py.cpp @@ -40,6 +40,9 @@ struct AddTransactionMethods { func(property_tag, "block_time", +[](const Transaction &tx) -> std::chrono::system_clock::time_point { return tx.block().getTime(); }, "The time that the block containing this transaction arrived"); + func(property_tag, "block_timestamp", +[](const Transaction &tx) -> int64_t { + return tx.block().timestamp(); + }, "Block timestamp"); func(property_tag, "observed_in_mempool", &Transaction::observedInMempool, "Returns whether this transaction was seen in the mempool by the recorder"); func(property_tag, "time_seen", &Transaction::getTimeSeen, "If recorded by the mempool recorder, the time that this transaction was first seen by your node"); func(property_tag, "block", &Transaction::block, "The block that this transaction was in"); diff --git a/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[bch].out b/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[bch].out index 5b699ab0..8addba4b 100644 --- a/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[bch].out +++ b/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[bch].out @@ -18,7 +18,7 @@ Block(tx_count=5, height=113, header_hash=121d93886d8ec313c13465d4cb9421fbf63dee Block(tx_count=2, height=111, header_hash=7ca20a203a5ba00f52478e578efe069278d664108cabb59cf95a4a3548db2385, version=536870912, timestamp=1535761200, bits=545259519, nonce=3) 5000020000 597 -2018-09-01 00:30:00+00:00 +2018-09-01T00:30:00.000000000 None 1535761800 597 diff --git a/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[btc].out b/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[btc].out index 274c3fb4..60cff0e2 100644 --- a/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[btc].out +++ b/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[btc].out @@ -18,7 +18,7 @@ Block(tx_count=5, height=113, header_hash=6b967b3001ea5e7e5e5175cd4c98e5c5419b5f Block(tx_count=2, height=111, header_hash=79a894fe764ef96801a1e01eeb66b495293e856fe3a73223de9570a19c0471d3, version=536870912, timestamp=1535761200, bits=545259519, nonce=0) 5000020000 671 -2018-09-01 00:30:00+00:00 +2018-09-01T00:30:00.000000000 None 1535761800 671 diff --git a/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[ltc].out b/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[ltc].out index c8c994a2..45de8bf6 100644 --- a/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[ltc].out +++ b/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2pkh_tx[ltc].out @@ -18,7 +18,7 @@ Block(tx_count=5, height=113, header_hash=73e77949a7f1289aa18a4bc099db4c377f7f81 Block(tx_count=2, height=111, header_hash=571b48850f70f7ecd76f5e652550553d358a1109211aa007089a5966419d05f3, version=536870912, timestamp=1535761200, bits=545259519, nonce=1) 5000020000 671 -2018-09-01 00:30:00+00:00 +2018-09-01T00:30:00.000000000 None 1535761800 671 diff --git a/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2wsh_tx[btc].out b/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2wsh_tx[btc].out index 2997a28b..15857885 100644 --- a/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2wsh_tx[btc].out +++ b/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2wsh_tx[btc].out @@ -18,7 +18,7 @@ Block(tx_count=2, height=123, header_hash=18ab42dda7c21ecdbef3bb8af1537b42612efc Block(tx_count=3, height=121, header_hash=6b4c87d26c48371ebb9a5561e226bb722c9263fc6c9c9f072ef67a8c3d0e5104, version=536870912, timestamp=1535767200, bits=545259519, nonce=0) 5000040000 1116 -2018-09-01 02:10:00+00:00 +2018-09-01T02:10:00.000000000 None 1535767800 1116 diff --git a/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2wsh_tx[ltc].out b/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2wsh_tx[ltc].out index 0998a393..853a0acb 100644 --- a/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2wsh_tx[ltc].out +++ b/test/blockscipy/_regtest_outputs/test_chain.test_block_with_p2wsh_tx[ltc].out @@ -18,7 +18,7 @@ Block(tx_count=2, height=123, header_hash=65baade5135cc19665148a2cea1ee9f658ea93 Block(tx_count=3, height=121, header_hash=aee604c197849f16df2d4a34db8c952eef11333b805cbe7e4e00967b830b1bd1, version=536870912, timestamp=1535767200, bits=545259519, nonce=3) 5000040000 1116 -2018-09-01 02:10:00+00:00 +2018-09-01T02:10:00.000000000 None 1535767800 1116 diff --git a/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[bch].out b/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[bch].out index 8de9151b..ebdf83e7 100644 --- a/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[bch].out +++ b/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[bch].out @@ -18,7 +18,7 @@ Block(tx_count=1, height=91, header_hash=67b3b6f61bf2329baaed0f69ace5069d55c7e19 Block(tx_count=1, height=89, header_hash=3c1433c6f2f64e78c3eb4545edcf74d9822c90b5e1e260ce1e639ad6cc245705, version=536870912, timestamp=1535760616, bits=545259519, nonce=0) 5000000000 181 -2018-09-01 00:10:16+00:00 +2018-09-01T00:10:16.000000000 None 1535760616 181 diff --git a/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[btc].out b/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[btc].out index a7ebb689..395673f8 100644 --- a/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[btc].out +++ b/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[btc].out @@ -18,7 +18,7 @@ Block(tx_count=1, height=91, header_hash=3a6d1c5585aabd0ae5af4727ae07347356ee8d2 Block(tx_count=1, height=89, header_hash=417608d639ec9058168ab5c58aea347e9d65b5d76473ac680f1c0558b580960a, version=536870912, timestamp=1535760616, bits=545259519, nonce=5) 5000000000 253 -2018-09-01 00:10:16+00:00 +2018-09-01T00:10:16.000000000 None 1535760616 253 diff --git a/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[ltc].out b/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[ltc].out index 01d0e0d0..d8772d4b 100644 --- a/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[ltc].out +++ b/test/blockscipy/_regtest_outputs/test_chain.test_empty_block[ltc].out @@ -18,7 +18,7 @@ Block(tx_count=1, height=91, header_hash=5b27431d906155fdb0469d2c5415bac6e914805 Block(tx_count=1, height=89, header_hash=c1334fa426b3c10387d73358fe205fab54d25d642b61882c8456797f2f39cd3f, version=536870912, timestamp=1535760616, bits=545259519, nonce=3) 5000000000 253 -2018-09-01 00:10:16+00:00 +2018-09-01T00:10:16.000000000 None 1535760616 253 diff --git a/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[bch].out b/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[bch].out index b5166f59..8cb96966 100644 --- a/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[bch].out +++ b/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[bch].out @@ -1,6 +1,6 @@ 226 111 -2018-09-01 00:20:00+00:00 +2018-09-01T00:20:00.000000000 10000 44 89530a3ac8a65f8cab0ad2a038ea1a3a850a0f82167c84b0caa873ea1ffce1a1 diff --git a/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[btc].out b/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[btc].out index 6d3577b9..6e659f04 100644 --- a/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[btc].out +++ b/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[btc].out @@ -1,6 +1,6 @@ 225 111 -2018-09-01 00:20:00+00:00 +2018-09-01T00:20:00.000000000 10000 44 9a27d8c02ed0ae0f62072963bae34ce845e7ba6b971d9bc76f58e14bec91c3e3 diff --git a/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[ltc].out b/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[ltc].out index 6d3577b9..6e659f04 100644 --- a/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[ltc].out +++ b/test/blockscipy/_regtest_outputs/test_transactions.test_p2pkh_transaction_regression[ltc].out @@ -1,6 +1,6 @@ 225 111 -2018-09-01 00:20:00+00:00 +2018-09-01T00:20:00.000000000 10000 44 9a27d8c02ed0ae0f62072963bae34ce845e7ba6b971d9bc76f58e14bec91c3e3 diff --git a/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[bch].out b/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[bch].out index 43659bf1..f8be8197 100644 --- a/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[bch].out +++ b/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[bch].out @@ -1,6 +1,6 @@ 224 115 -2018-09-01 01:00:00+00:00 +2018-09-01T01:00:00.000000000 10000 44 778af7567b200ab75f8e7b74614d6d0e86cfe26a36e6a3d33693c51cbd4bed07 diff --git a/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[btc].out b/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[btc].out index 872e4a09..3d7dd67a 100644 --- a/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[btc].out +++ b/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[btc].out @@ -1,6 +1,6 @@ 224 115 -2018-09-01 01:00:00+00:00 +2018-09-01T01:00:00.000000000 10000 44 1b448e0add367565e4aa6d3431adf5bf3e5200b5b8cc6c23d0cd5a46f9d086a9 diff --git a/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[ltc].out b/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[ltc].out index 872e4a09..3d7dd67a 100644 --- a/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[ltc].out +++ b/test/blockscipy/_regtest_outputs/test_transactions.test_p2sh_transaction_regression[ltc].out @@ -1,6 +1,6 @@ 224 115 -2018-09-01 01:00:00+00:00 +2018-09-01T01:00:00.000000000 10000 44 1b448e0add367565e4aa6d3431adf5bf3e5200b5b8cc6c23d0cd5a46f9d086a9 diff --git a/test/blockscipy/_regtest_outputs/test_transactions.test_p2wpkh_transaction_regression[btc].out b/test/blockscipy/_regtest_outputs/test_transactions.test_p2wpkh_transaction_regression[btc].out index 6fc87e64..646de4dd 100644 --- a/test/blockscipy/_regtest_outputs/test_transactions.test_p2wpkh_transaction_regression[btc].out +++ b/test/blockscipy/_regtest_outputs/test_transactions.test_p2wpkh_transaction_regression[btc].out @@ -1,6 +1,6 @@ 222 119 -2018-09-01 01:40:00+00:00 +2018-09-01T01:40:00.000000000 10000 45 56a552806a9608554c976cd87b0f622b0b0bebfe89f21010efb2298bc0d0483a diff --git a/test/blockscipy/_regtest_outputs/test_transactions.test_p2wpkh_transaction_regression[ltc].out b/test/blockscipy/_regtest_outputs/test_transactions.test_p2wpkh_transaction_regression[ltc].out index 6fc87e64..646de4dd 100644 --- a/test/blockscipy/_regtest_outputs/test_transactions.test_p2wpkh_transaction_regression[ltc].out +++ b/test/blockscipy/_regtest_outputs/test_transactions.test_p2wpkh_transaction_regression[ltc].out @@ -1,6 +1,6 @@ 222 119 -2018-09-01 01:40:00+00:00 +2018-09-01T01:40:00.000000000 10000 45 56a552806a9608554c976cd87b0f622b0b0bebfe89f21010efb2298bc0d0483a diff --git a/test/blockscipy/_regtest_outputs/test_transactions.test_p2wsh_transaction_regression[btc].out b/test/blockscipy/_regtest_outputs/test_transactions.test_p2wsh_transaction_regression[btc].out index 5e23f172..0c0d3b90 100644 --- a/test/blockscipy/_regtest_outputs/test_transactions.test_p2wsh_transaction_regression[btc].out +++ b/test/blockscipy/_regtest_outputs/test_transactions.test_p2wsh_transaction_regression[btc].out @@ -1,6 +1,6 @@ 235 121 -2018-09-01 02:00:00+00:00 +2018-09-01T02:00:00.000000000 10000 42 ce707ce4ef0a3c960d130db272a4c971530fc42e6f0842cf8ac0d71c8ae09cf7 diff --git a/test/blockscipy/_regtest_outputs/test_transactions.test_p2wsh_transaction_regression[ltc].out b/test/blockscipy/_regtest_outputs/test_transactions.test_p2wsh_transaction_regression[ltc].out index 5e23f172..0c0d3b90 100644 --- a/test/blockscipy/_regtest_outputs/test_transactions.test_p2wsh_transaction_regression[ltc].out +++ b/test/blockscipy/_regtest_outputs/test_transactions.test_p2wsh_transaction_regression[ltc].out @@ -1,6 +1,6 @@ 235 121 -2018-09-01 02:00:00+00:00 +2018-09-01T02:00:00.000000000 10000 42 ce707ce4ef0a3c960d130db272a4c971530fc42e6f0842cf8ac0d71c8ae09cf7