Libbitcoin Network

提供: tezos-wiki
移動先: 案内検索

libbitcoin-networkライブラリは、 Bitcoin P2Pネットワークプロトコルの部分実装です。 ブロックチェーンへのアクセスを必要とするすべてのサブプロトコルが除外されます。 libbitcoin-nodeライブラリはこのP2Pネットワーク機能を拡張し、フルノードを実装するために libbitcoin-blockchainを組み込みます。 libbitcoin-explorerライブラリは、P2PネットワークにトランザクションをポストするためにP2Pネットワーク機能を使用します。

[編集]

#include <future>
#include <bitcoin/network.hpp>

// Send a transaction to a single P2P node.
int main(int argc, char* argv[])
{
    // Decode a base16-encoded Bitcoin transaction. 
    bc::data_chunk decoded;
    if (argc < 1 || !bc::decode_base16(decoded, argv[0]))
        return -1;

    // Parse the decoded transaction.
    const auto tx = bc::chain::transaction::factory_from_data(decoded);

    // Configure the P2P network session for best performance.
    auto settings = bc::network::settings(bc::config::settings::mainnet);
    settings.outbound_connections = 0;
    settings.manual_attempt_limit = 3;

    // Start a network session.
    bc::network::p2p network(settings);

    // Declare completion signal.
    std::promise<bc::code> complete;

    const auto send_handler = [&complete](const bc::code& ec)
    {
        complete.set_value(ec);
    };

    const auto connect_handler = [&complete, &tx, &send_handler](
        const bc::code& ec, bc::network::channel::ptr node)
    {
        if (ec)
            complete.set_value(ec);
        else
            node->send(tx, send_handler);
    };

    // Connect to the one specified host with retry.
    network.connect("localhost", 8333, connect_handler);

    // Wait for completion and return result.
    return complete.get_future().get() ? -1 : 0;
}

歴史[編集]

  • P2Pプロトコルはもともと libbitcoinライブラリに含まれていました。
  • 2016年初頭までに[Eric_Voskuil | Eric Voskuil]はバージョン3の再設計を完了し、信頼性、性能、可読性を向上させました。 名前空間は、独自のリポジトリに分岐され、依存リポジトリと統合されました。

依存関係[編集]

関連項目[編集]

参考文献[編集]