Libbitcoin Client: Difference between revisions
larger stub |
Add content. |
||
Line 1: | Line 1: | ||
The [https://github.com/libbitcoin/libbitcoin-client libbitcoin-client] library. | The [https://github.com/libbitcoin/libbitcoin-client libbitcoin-client] library provides an abstraction over the low level networking calls required to communicate with [[Libbitcoin_Server|libbitcoin-server (BS)]]. The the server application is not currently divided into library and executable so there is no analog to libbitcoin-client on the server. | ||
==Example== | ==Example== | ||
int main() | #include <iostream> | ||
#include <czmq++/czmqpp.hpp> | |||
#include <bitcoin/client.hpp> | |||
int main(int argc, char* argv[]) | |||
{ | { | ||
czmqpp::context context; | |||
czmqpp::socket socket(context, ZMQ_DEALER); | |||
if (argc < 2 || socket.connect(argv[1]) < 0) | |||
{ | |||
std::cerr << "server argument required" << std::endl; | |||
return 1; | |||
} | |||
auto stream = std::make_shared<bc::client::socket_stream>(socket); | |||
auto message = std::static_pointer_cast<bc::client::message_stream>(stream); | |||
auto obelisk = std::make_shared<bc::client::obelisk_codec>(message); | |||
const auto error_handler = [](const std::error_code& code) | |||
{ | |||
std::cout << "error: " << code.message() << std::endl; | |||
}; | |||
const auto handler = [](size_t height) | |||
{ | |||
std::cout << "height: " << height << std::endl; | |||
}; | |||
obelisk->fetch_last_height(error_handler, handler); | |||
while (obelisk->outstanding_call_count()) | |||
{ | |||
czmqpp::poller poller; | |||
poller.add(socket); | |||
const auto delay = static_cast<int>(obelisk->wakeup().count()); | |||
if (!delay) | |||
break; | |||
poller.wait(delay); | |||
if (poller.terminated()) | |||
break; | |||
if (!poller.expired()) | |||
stream->signal_response(obelisk); | |||
} | |||
return 0; | return 0; | ||
} | } | ||
==History== | |||
The libbitcoin client-server protocol (API) is sometimes referred to as the Obelisk protocol, as this was the name of the first version of the server. In the first version the client API was contained within the libbitcoin-server library, which led to a dependency between client applications such as [[Libbitcoin_Explorer|Bitcoin Explorer (BX)]], and the server library. | |||
In the summer of 2014 William Swanson redesigned the client library as libbitcoin-client. The first release of the independent library shipped as version 2.0 coincident with Bitcoin Explorer 2.0. This was a client to Obelisk, the original server application. As Obelisk was upgraded to Bitcoin Server (version 2.0) the client (version 2.1) was adapted to minor corresponding changes in the client-server API. With few exceptions (fetch-stealth and watch-address), the client is compatible with both Obelisk and Bitcoin Server. | |||
==Dependencies== | ==Dependencies== |
Revision as of 04:06, 18 May 2015
The libbitcoin-client library provides an abstraction over the low level networking calls required to communicate with libbitcoin-server (BS). The the server application is not currently divided into library and executable so there is no analog to libbitcoin-client on the server.
Example
#include <iostream> #include <czmq++/czmqpp.hpp> #include <bitcoin/client.hpp> int main(int argc, char* argv[]) { czmqpp::context context; czmqpp::socket socket(context, ZMQ_DEALER); if (argc < 2 || socket.connect(argv[1]) < 0) { std::cerr << "server argument required" << std::endl; return 1; } auto stream = std::make_shared<bc::client::socket_stream>(socket); auto message = std::static_pointer_cast<bc::client::message_stream>(stream); auto obelisk = std::make_shared<bc::client::obelisk_codec>(message); const auto error_handler = [](const std::error_code& code) { std::cout << "error: " << code.message() << std::endl; }; const auto handler = [](size_t height) { std::cout << "height: " << height << std::endl; }; obelisk->fetch_last_height(error_handler, handler); while (obelisk->outstanding_call_count()) { czmqpp::poller poller; poller.add(socket); const auto delay = static_cast<int>(obelisk->wakeup().count()); if (!delay) break; poller.wait(delay); if (poller.terminated()) break; if (!poller.expired()) stream->signal_response(obelisk); } return 0; }
History
The libbitcoin client-server protocol (API) is sometimes referred to as the Obelisk protocol, as this was the name of the first version of the server. In the first version the client API was contained within the libbitcoin-server library, which led to a dependency between client applications such as Bitcoin Explorer (BX), and the server library.
In the summer of 2014 William Swanson redesigned the client library as libbitcoin-client. The first release of the independent library shipped as version 2.0 coincident with Bitcoin Explorer 2.0. This was a client to Obelisk, the original server application. As Obelisk was upgraded to Bitcoin Server (version 2.0) the client (version 2.1) was adapted to minor corresponding changes in the client-server API. With few exceptions (fetch-stealth and watch-address), the client is compatible with both Obelisk and Bitcoin Server.