Libbitcoin Client
libbitcoin-clientライブラリは、[Bitcoin_Server | Bitcoin Server](bs)やLibbitcoinを実装している他のサービスと通信するために必要な低レベルのネットワークコールを抽象化していますクライアント - サーバープロトコル。いくつかの例外(fetch-stealthとwatch-address)を除いて、クライアントはObeliskと Bitcoin Serverの両方と互換性があります。
目次
例(Version3)[編集]
#include <cstddef> #include <iostream> #include <bitcoin / client.hpp> int main(int argc、char * argv []) { if(argc <2) { std :: cerr << "サーバアドレス必須" << std :: endl; 1を返します。 } // 3秒のタイムアウト、0回の再試行 bc :: client :: obelisk_clientクライアント(3、0); if(!client.connect({argv [1]})) { std :: cerr << "接続に失敗しました:" << argv [1] << std :: endl; 1を返します。 } const auto on_error = [](const bc :: code&ec) { std :: cerr << "フェッチに失敗しました:" << ec.message()<< std :: endl; }; const auto on_done = [](size_t height) { std :: cout << "height:" << height << std :: endl; }; client.blockchain_fetch_last_height(on_error、on_done); client.wait(); 0を返します。 }
例(Version2)[編集]
#include <cstddef> #include <iostream> #include <czmq ++ / czmqpp.hpp> #include <bitcoin / client.hpp> int main(int argc、char * argv []) { czmqpp ::コンテキストコンテキスト。 czmqpp :: socketソケット(コンテキスト、ZMQ_DEALER); if(argc <2 || socket.connect(argv [1])<0) { std :: cerr << "サーバアドレス必須" << std :: endl; 1を返します。 } 自動ストリーム= std :: make_shared <bc :: client :: socket_stream>(ソケット); 自動メッセージ= std :: static_pointer_cast <bc :: client :: message_stream>(ストリーム); 自動オベリスク=標準:: make_shared <bc :: client :: obelisk_codec>(メッセージ); const auto error_handler = [](const std :: error_code&ec) { std :: cerr << "エラー:" << ec.message()<< std :: endl; }; const auto handler = [](size_t height) { std :: cout << "height:" << height << std :: endl; }; obelisk-> fetch_last_height(エラーハンドラ、ハンドラ); while(obelisk-> outstanding_call_count()) { czmqpp :: pollerポーラー。 poller.add(ソケット); const auto delay = static_cast <int>(obelisk-> wakeup()。count()); if(!delay) ブレーク; poller.wait(遅延); if(poller.terminated()) ブレーク; if(!poller.expired()) stream-> signal_response(オベリスク); } 0を返します。 }
メッセージング[編集]
クライアント・サーバー・プロトコル(API)は、「高速非同期I / Oエンジン」である「http://zeromq.orgØMQ(別名ZMQ、ZeroMQおよびZero Message Queue)」上に構築されています。 <ref> [http:// zeromq]は、ソケット上に直接置かれ、 "inproc、IPC、TCP、TIPC、マルチキャストに渡ってメッセージを運びます。 .orgØMQ - Code Connected] APIはpub-subパターンをサポートしています。<ref> - メッセージを取得する (例えば、Bitcoinアドレスの監視)とルータのディーラーパターン<ref> [http://zguide.zeromq.org/php:chapter3#The-DEALER-to-ROUTER-CombinationØMQ - 高度なリクエスト - 返信 パターン] </ ref>(例えば、ステルストランザクションを要求する)。
認証と暗号化[編集]
このAPIには、CurveZMQ、「ZeroMQの認証と暗号化プロトコル」が組み込まれています。<ref> CurveZMQ - Security for ZeroMQ </ ref> ://rfc.zeromq.org/spec:26 CurveZMQ認証と暗号化Protoco] CurveZMQはCurveCPとNaClに基づいています]、高速で安全な楕円曲線暗号を提供する。[ref> "新しい暗号ライブラリのセキュリティへの影響" Daniel J. Bernstein et。 al。 </ ref>
秘密鍵証明書は公開鍵と秘密鍵のプロパティを持つZPL(ZeroMQ Property Language)エンコードファイルとして自己生成されます。キーはZ85 - (ZeroMQ Base-85 Encoding Algorithm)エンコードされた楕円曲線点です。キーは、Bitcoin Explorer(bx)<ref> Bitcoin Explorer cert-newコマンドで作成できます。</ ref>バージョン2)。
$ bx cert-new citizen4.private
$ cat citizen4.private #**** 2015-05-18 15:09:59 CZMQ ****で生成 #ZeroMQ CURVE **秘密**証明書 #このファイルを他のユーザーに提供したり、権限を変更したりしないでください。 メタデータ 曲線 公開鍵= "Mu ^ Lc6Y(ebQAzQRGl ^ XkZKXMpb +)<pnVDZcd:WSv" 秘密鍵= "dCS" l9 <(u#4L)4 $(6> CqJ)NX-kvo + I5 ^&WPHDX + "
クライアントアプリケーションは、1つまたは複数のサーバの公開鍵で設定できます。<ref> Bitcoin Explorer設定 </ ref> Bitcoinサーバーの構成設定で構成されているサーバーを安全に認証する< / ref>サーバーの公開鍵を持つクライアントは、サーバーとの安全なチャネルを作成することもできます。クライアントアプリケーションは、自己生成の秘密鍵で構成され、それによってそのクライアントの公開鍵のコピーを保持するサーバーに対して安全に認証されることがあります。
歴史[編集]
- libbitcoinクライアント - サーバープロトコル(API)は、サーバーの最初のバージョンの名前であるため、Obeliskプロトコルと呼ばれることがあります。 最初のバージョンでは、クライアントAPIはlibbitcoin-serverライブラリに含まれていたため、 Bitcoin Explorer(bx)などのクライアントアプリケーションとサーバーライブラリの間の依存関係が生じました。
- 2014年の夏、William Swansonはクライアントライブラリをlibbitcoin-clientとして再設計しました。 独立したライブラリの最初のリリースはBitcoin Explorer 2.0と同時にバージョン2.0として出荷されました。 これはオリジナルのサーバーアプリケーションであるObeliskのクライアントでした。 ObeliskがBitcoin Server(バージョン2.0)にアップグレードされたので、クライアント(バージョン2.1)は、クライアント/サーバーAPIのわずかな変更に対応しました。