From 4565e5be9d30d3d28f9319f613cd5311081fc4d7 Mon Sep 17 00:00:00 2001 From: genjix Date: Sun, 22 Apr 2012 20:50:32 +0100 Subject: [PATCH] BUGFIX: confirmations & payment_history fixes. --- backends/libbitcoin/Makefile | 4 ++++ backends/libbitcoin/__init__.py | 13 ++++++------- backends/libbitcoin/h1.py | 2 +- backends/libbitcoin/history.cpp | 10 +++++++--- backends/libbitcoin/history1/__init__.py | 10 ++++++++-- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/backends/libbitcoin/Makefile b/backends/libbitcoin/Makefile index 96cc1cf..73c284f 100644 --- a/backends/libbitcoin/Makefile +++ b/backends/libbitcoin/Makefile @@ -1,5 +1,9 @@ CC = g++ -fPIC -Wall -ansi `pkg-config --cflags libbitcoin` -I/usr/include/python2.7 +trace_tx: + $(CC) -c trace_tx.cpp -o trace_tx.o + $(CC) -shared -Wl,-soname,trace_tx.so trace_tx.o -lpython2.7 -lboost_python `pkg-config --libs libbitcoin` -lboost_thread -o trace_tx.so + membuf: $(CC) -c membuf.cpp -o membuf.o $(CC) -shared -Wl,-soname,membuf.so membuf.o -lpython2.7 -lboost_python `pkg-config --libs libbitcoin` -lboost_thread -o membuf.so diff --git a/backends/libbitcoin/__init__.py b/backends/libbitcoin/__init__.py index 8e51169..f1664c9 100644 --- a/backends/libbitcoin/__init__.py +++ b/backends/libbitcoin/__init__.py @@ -89,7 +89,7 @@ class MonitorAddress: self.cache.clear(affected_addrs) self.notify(affected_addrs) - def tx_confirmed(self, tx_desc): + def tx_confirmed(self, tx): tx_hash, previous_outputs, addrs = self.unpack(tx) with self.lock: affected_addrs = self.affected[tx_hash] @@ -109,16 +109,14 @@ class MonitorAddress: del self.monitor_output[prevout] def notify(self, affected_addrs): - templ_response = {"id": None, - "method": "blockchain.address.subscribe", - "params": []} service = self.backend.mempool_service chain = self.backend.blockchain txpool = self.backend.transaction_pool memory_buff = self.backend.memory_buffer for address in affected_addrs: - response = templ_response.copy() - response["params"].append(address) + response = {"id": None, + "method": "blockchain.address.subscribe", + "params": [str(address)]} history.payment_history(service, chain, txpool, memory_buff, address, bind(self.send_notify, _1, _2, response)) @@ -139,6 +137,7 @@ class MonitorAddress: if ec: print "Error: Monitor.send_notify()", ec return + assert len(response["params"]) == 1 response["params"].append(self.mempool_n(result)) self.processor.push_response(response) @@ -351,7 +350,7 @@ class BlockchainProcessor(Processor): self.broadcast_transaction(request) def broadcast_transaction(self, request): - raw_tx = bitcoin.data_chunk(str(request["params"])) + raw_tx = bitcoin.data_chunk(str(request["params"][0])) exporter = bitcoin.satoshi_exporter() try: tx = exporter.load_transaction(raw_tx) diff --git a/backends/libbitcoin/h1.py b/backends/libbitcoin/h1.py index c45dca9..71026ba 100644 --- a/backends/libbitcoin/h1.py +++ b/backends/libbitcoin/h1.py @@ -25,7 +25,7 @@ def stored(ec): mbuff = membuf.memory_buffer(a.internal_ptr, chain.internal_ptr, txpool.internal_ptr) mbuff.receive(tx, stored) -address = "1GULoCDnGjhfSWzHs6zDzBxbKt9DR7uRbt" +address = "1AA6mgxqSrvJTxRrYrikSnLaAGupVzvx4f" raw_input() history.payment_history(a, chain, txpool, mbuff, address, finish) raw_input() diff --git a/backends/libbitcoin/history.cpp b/backends/libbitcoin/history.cpp index 76dc713..1379be4 100644 --- a/backends/libbitcoin/history.cpp +++ b/backends/libbitcoin/history.cpp @@ -542,10 +542,14 @@ void keep_query_alive_proxy(const std::error_code& ec, write_info(json, entry->loaded_input); } } - for (info_unit_ptr info: membuf_result) - { + // A bit of super glue + if (!statement.empty() && !membuf_result.empty()) json += ","; - write_info(json, info); + for (auto it = membuf_result.begin(); it != membuf_result.end(); ++it) + { + if (it != membuf_result.begin()) + json += ","; + write_info(json, *it); } json += "]"; pyfunction f(handle_finish); diff --git a/backends/libbitcoin/history1/__init__.py b/backends/libbitcoin/history1/__init__.py index 25cd9e6..3bce9ab 100644 --- a/backends/libbitcoin/history1/__init__.py +++ b/backends/libbitcoin/history1/__init__.py @@ -3,10 +3,16 @@ from bitcoin import bind, _1, _2 import json def wrap_finish(handle_finish, ec, result_json): - handle_finish(ec, json.loads(result_json)) + try: + result = json.loads(result_json) + except ValueError: + print result_json + raise + else: + handle_finish(ec, result) def payment_history(service, chain, txpool, membuf, address, finish): _history.payment_history(service.internal_ptr, chain.internal_ptr, txpool.internal_ptr, membuf.internal_ptr, - address, bind(wrap_finish, finish, _1, _2)) + str(address), bind(wrap_finish, finish, _1, _2)) -- 1.7.1