-
-
Notifications
You must be signed in to change notification settings - Fork 12.7k
/
Copy pathlibbitcoin-client.rb
111 lines (100 loc) · 4.55 KB
/
libbitcoin-client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
class LibbitcoinClient < Formula
desc "Bitcoin Client Query Library"
homepage "https://github.com/libbitcoin/libbitcoin-client"
url "https://github.com/libbitcoin/libbitcoin-client/archive/refs/tags/v3.8.0.tar.gz"
sha256 "cfd9685becf620eec502ad53774025105dda7947811454e0c9fea30b27833840"
license "AGPL-3.0-or-later"
revision 2
bottle do
sha256 cellar: :any, arm64_sequoia: "cb3c6f9dfbbc5aa63e4eed52279f6fe51adb275a0116661eac8e250297c0d205"
sha256 cellar: :any, arm64_sonoma: "7aab15e9fbacb91b793be00809efb2634813fb719f171d698d8acdc9b73bab9d"
sha256 cellar: :any, arm64_ventura: "82d9f59cee3f405fe35961470c6404a1a44d026935414bdce4baff5401c2b2e9"
sha256 cellar: :any, arm64_monterey: "30cfca391b2f95c09305b27b952c23151e59e9a85c767ec314ac125dee9985ab"
sha256 cellar: :any, sonoma: "20713787a1372dedb7546febdf4bca454d8249068bc6a189a6644b513e9d90f0"
sha256 cellar: :any, ventura: "8a2ce6e56369b086d124c1247f7bb7656cbe8f67676663b5c6d6f133313d941a"
sha256 cellar: :any, monterey: "787b413db3f35739c3f8a5acc11533eeb7225d4f4f85f61218fe50fe0d3b3311"
sha256 cellar: :any_skip_relocation, x86_64_linux: "1f069aba8a3b4a0d5b25866f9122b9958456610c93bb1bb26f984736e4a1f24a"
end
# About 2 years since request for release with support for recent `boost`.
# Ref: https://github.com/libbitcoin/libbitcoin-system/issues/1234
disable! date: "2024-12-14", because: "uses deprecated `boost@1.76`"
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "libtool" => :build
depends_on "pkgconf" => :build
# https://github.com/libbitcoin/libbitcoin-system/issues/1234
depends_on "boost@1.76"
depends_on "libbitcoin-protocol"
depends_on "libsodium"
depends_on "zeromq"
def install
ENV.cxx11
ENV.prepend_path "PKG_CONFIG_PATH", Formula["libbitcoin"].opt_libexec/"lib/pkgconfig"
system "./autogen.sh"
system "./configure", "--disable-dependency-tracking",
"--disable-silent-rules",
"--prefix=#{prefix}",
"--with-boost-libdir=#{Formula["boost@1.76"].opt_lib}"
system "make", "install"
end
test do
boost = Formula["boost@1.76"]
(testpath/"test.cpp").write <<~CPP
#include <bitcoin/client.hpp>
class stream_fixture
: public libbitcoin::client::stream
{
public:
libbitcoin::data_stack out;
virtual int32_t refresh() override
{
return 0;
}
virtual bool read(stream& stream) override
{
return false;
}
virtual bool write(const libbitcoin::data_stack& data) override
{
out = data;
return true;
}
};
static std::string to_string(libbitcoin::data_slice data)
{
return std::string(data.begin(), data.end()) + "\0";
}
static void remove_optional_delimiter(libbitcoin::data_stack& stack)
{
if (!stack.empty() && stack.front().empty())
stack.erase(stack.begin());
}
static const uint32_t test_height = 0x12345678;
static const char address_satoshi[] = "1PeChFbhxDD9NLbU21DfD55aQBC4ZTR3tE";
#define PROXY_TEST_SETUP \
static const uint32_t retries = 0; \
static const uint32_t timeout_ms = 2000; \
static const auto on_error = [](const libbitcoin::code&) {}; \
static const auto on_unknown = [](const std::string&) {}; \
stream_fixture capture; \
libbitcoin::client::proxy proxy(capture, on_unknown, timeout_ms, retries)
#define HANDLE_ROUTING_FRAMES(stack) \
remove_optional_delimiter(stack);
int main() {
PROXY_TEST_SETUP;
const auto on_reply = [](const libbitcoin::chain::history::list&) {};
proxy.blockchain_fetch_history3(on_error, on_reply, libbitcoin::wallet::payment_address(address_satoshi), test_height);
HANDLE_ROUTING_FRAMES(capture.out);
assert(capture.out.size() == 3u);
assert(to_string(capture.out[0]) == "blockchain.fetch_history3");
assert(libbitcoin::encode_base16(capture.out[2]) == "f85beb6356d0813ddb0dbb14230a249fe931a13578563412");
}
CPP
system ENV.cxx, "-std=c++11", "test.cpp", "-o", "test",
"-I#{boost.include}",
"-L#{Formula["libbitcoin"].opt_lib}", "-lbitcoin-system",
"-L#{lib}", "-lbitcoin-client",
"-L#{boost.lib}", "-lboost_system"
system "./test"
end
end