1 #include <system_error>
3 #include <bitcoin/bitcoin.hpp>
4 using namespace libbitcoin;
6 #include <boost/python.hpp>
7 namespace python = boost::python;
9 #include "/home/genjix/python-bitcoin/src/primitive.h"
11 typedef std::function<void (const std::error_code&)> finish_handler;
13 namespace ph = std::placeholders;
16 : public std::enable_shared_from_this<query_history>
19 query_history(async_service& service,
20 blockchain_ptr chain, transaction_pool_ptr txpool)
21 : strand_(service.get_service()), chain_(chain),
22 txpool_(txpool), stopped_(false)
26 void start(const std::string& address, finish_handler handle_finish)
28 address_.set_encoded(address);
29 handle_finish_ = handle_finish;
30 chain_->fetch_outputs(address_,
31 strand_.wrap(std::bind(&query_history::start_loading,
32 shared_from_this(), ph::_1, ph::_2)));
39 BITCOIN_ASSERT(stopped_ == false);
43 void start_loading(const std::error_code& ec,
44 const message::output_point_list& outpoints)
49 io_service::strand strand_;
51 blockchain_ptr chain_;
52 transaction_pool_ptr txpool_;
55 payment_address address_;
56 finish_handler handle_finish_;
59 typedef std::shared_ptr<query_history> query_history_ptr;
61 void keep_query_alive_proxy(const std::error_code& ec,
62 python::object handle_finish, query_history_ptr history)
64 pyfunction<const std::error_code&> f(handle_finish);
68 void payment_history(async_service_ptr service, blockchain_ptr chain,
69 transaction_pool_ptr txpool, const std::string& address,
70 python::object handle_finish)
72 query_history_ptr history =
73 std::make_shared<query_history>(*service, chain, txpool);
74 history->start(address,
75 std::bind(keep_query_alive_proxy, ph::_1,
76 handle_finish, history));
79 BOOST_PYTHON_MODULE(_history)
81 using namespace boost::python;
82 def("payment_history", payment_history);