我正在开发一个比特币客户端,我希望通过接收“警报”比特币消息来测试我的代码。但我不知道如何从比特币网络上的另一个节点请求此消息。通过阅读协议规范(如下),听起来这个消息只是为了响应某些恶意事件而发送,我可能不想尝试和模仿(我不想让自己被列入Testnet黑名单)。 p>
答案 0 :(得分:0)
您需要做的第一件事是分叉[bitcoin] [bitcoinrepo]存储库。在github上,你可以点击" Fork"或者您可以克隆存储库并在本地进行所有更改。无论哪种方式,您都需要自己的比特币源代码副本。
这是[here] [sendalert]找到的要点的修改版本。您需要将[this file] [modsendalert]放入[src目录] [bitcoinsrc]。
或者,您可以编辑实际的警报属性,例如评论文本,状态栏文本,实际现在忽略的警报等。您可以看到完整警报规范[此处] [警告规范]。
在[src / alert.cpp] [alertcpp]中,使这些函数返回true:
IsInEffect
AppliesToMe
CheckSignature
在[init.cpp] [initcpp]的顶部附近,您需要输入以下代码:
extern void ThreadSendAlert();
接近文件末尾:
return !fRequestShutdown;
这一行:
threadGroup.create_thread(boost::bind(ThreadSendAlert));
您还需要将sendalert.cpp添加到[Makefile.am] [makefile]中,方法是将sendalert.cpp添加到libbitcoin_server_a_SOURCES列表中。这可以在这一行之后完成:
txmempool.cpp \
并在以下后添加此行:
sendalert.cpp \
按照[unix] [buildinstructions]或[mac] [buildinstructionsmac]的说明进行操作。
你需要两台机器,虽然可能只使用一台使用不同的端口,但我还没有能够解决这个问题。您将需要每台机器的IP地址。假设您有机器A和B.您希望机器B接收警报。
从机器A开始,您需要运行:
./bitcoind -printtoconsole -sendalert -testnet -addnode=<ip of machine B>
从机器B开始,您需要运行:
./bitcoind -printtoconsole -sendalert -testnet -addnode=<ip of machine A>
确保它们相对紧密地开始(彼此在5秒内)。
启动后约1分钟,您应该在机器B的控制台中看到如下警告:
ThreadSendAlert:
hash=14c7c1217b54b953a81b08e0be16b9a56a9365240169d808424d5e7dd5690769
vchMsg=010000003271cd5400000000c2ffdb5400000000150400002a000000021004000012040000721101007311010002102f5361746f7368693a302e31302e302f0f2f5361746f7368693a302e392e332f88130000177465737420636f6d6d656e742031343232373530303032165445535420414c4552543a203134323337303430303210746573742072657365727665642e2e2e
vchSig=304402204cf39bec79eb10ad056f7a1ca48cfda3d612444a22eead543f345ae5f9c483df02204fc13370a17c639b796061ed39f294dd145363b3b953b9b4475da3b40bcd3f0e
ThreadSendAlert() : Sending alert
attempting relay
ThreadSendAlert() : Sent alert to x.x.x.x:18333
attempting relay
ThreadSendAlert() : Sent alert to x.x.x.x:18333
attempting relay
ThreadSendAlert() : Sent alert to x.x.x.x:18333
attempting relay
ThreadSendAlert() : Sent alert to x.x.x.x:18333
attempting relay
ThreadSendAlert() : Sent alert to x.x.x.x:18333
ThreadSendAlert() : Alert sent to 5 nodes