summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmir Taaki <genjix@riseup.net>2013-10-09 01:10:16 (GMT)
committer Amir Taaki <genjix@riseup.net>2013-10-09 01:10:16 (GMT)
commit7df309566495ca2ac05d1f34339f7088552db01e (patch)
tree71457aa73921f698c0588f4f11255e77cbe1c6e3
parent93fec48485f5cdfa3ba336caf532964f20160eec (diff)
sx fetch-transaction-index TXHASH0.2
-rw-r--r--src/Makefile.am6
-rw-r--r--src/fetch-transaction-index.cpp46
-rwxr-xr-xsrc/sx.py11
3 files changed, 62 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 4b09bd1..e6f2c01 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -26,7 +26,8 @@ sx: sx.py Makefile
if HAVE_OBELISK
corebin_PROGRAMS += \
sx-history sx-balance sx-fetch-block-header sx-fetch-transaction \
- sx-fetch-last-height sx-validtx sx-ob-broadcast-tx sx-wallet
+ sx-fetch-last-height sx-validtx sx-ob-broadcast-tx sx-wallet \
+ sx-fetch-transaction-index
AM_CPPFLAGS += -DSYSCONFDIR=\"${sysconfdir}\"
endif
@@ -130,6 +131,9 @@ sx_fetch_last_height_LDADD = ${libbitcoin_LIBS} ${libobelisk_LIBS}
sx_fetch_transaction_SOURCES = fetch-transaction.cpp config.cpp
sx_fetch_transaction_LDADD = ${libbitcoin_LIBS} ${libobelisk_LIBS}
+sx_fetch_transaction_index_SOURCES = fetch-transaction-index.cpp config.cpp
+sx_fetch_transaction_index_LDADD = ${libbitcoin_LIBS} ${libobelisk_LIBS}
+
sx_fetch_block_header_SOURCES = fetch-block-header.cpp config.cpp
sx_fetch_block_header_LDADD = ${libbitcoin_LIBS} ${libobelisk_LIBS}
diff --git a/src/fetch-transaction-index.cpp b/src/fetch-transaction-index.cpp
new file mode 100644
index 0000000..95ad5f1
--- /dev/null
+++ b/src/fetch-transaction-index.cpp
@@ -0,0 +1,46 @@
+#include <bitcoin/bitcoin.hpp>
+#include <obelisk/obelisk.hpp>
+#include "config.hpp"
+#include "util.hpp"
+
+using namespace bc;
+
+bool stopped = false;
+
+void index_fetched(const std::error_code& ec,
+ size_t block_height, size_t index)
+{
+ if (ec)
+ {
+ std::cerr << "fetch-transaction: " << ec.message() << std::endl;
+ stopped = true;
+ return;
+ }
+ std::cout << "Height: " << block_height << std::endl;
+ std::cout << "Index: " << index << std::endl;
+ stopped = true;
+}
+
+int main(int argc, char** argv)
+{
+ std::string tx_hash_str;
+ if (argc == 2)
+ tx_hash_str = argv[1];
+ else
+ tx_hash_str = read_stdin();
+ hash_digest tx_hash = decode_hex_digest<hash_digest>(tx_hash_str);
+ config_map_type config;
+ load_config(config);
+ threadpool pool(1);
+ obelisk::fullnode_interface fullnode(pool, config["service"]);
+ fullnode.blockchain.fetch_transaction_index(tx_hash, index_fetched);
+ while (!stopped)
+ {
+ fullnode.update();
+ sleep(0.1);
+ }
+ pool.stop();
+ pool.join();
+ return 0;
+}
+
diff --git a/src/sx.py b/src/sx.py
index d517ba8..4c8082e 100755
--- a/src/sx.py
+++ b/src/sx.py
@@ -326,6 +326,17 @@ the load balancer backend.\
"""
),
+"fetch-transaction-index": (
+"Fetch block height and index in block of transaction.",
+
+"""\
+Usage: sx fetch-transaction-index HASH
+
+The fetch-transaction-index tool uses a network connection to make requests
+against the load balancer backend.\
+"""
+),
+
"balance": (
"Show balance of a Bitcoin address.",