美文网首页
bitcoin: walletnotify的用法

bitcoin: walletnotify的用法

作者: 已不再更新_转移到qiita | 来源:发表于2018-01-12 18:23 被阅读912次

-walletnotify=<cmd> Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)

walletnotify

# bitcoin.conf
regtest=1
rpcuser=shooter
rpcpassword=shooter
#walletnotify=curl http://localhost:8000/notify/?tx=%s
walletnotify=/trans.sh %s

推荐 walletnotify=/trans.sh %s,降低耦合度。

trans.sh

#!/bin/sh

curl -X GET "http://localhost:8000/notify/?tx=$1"  # http GET method

然后开启个http服务, 设定好访问地址, 以django为例:

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    tx = request.GET.get('tx', 'Null') # http GET method
    return HttpResponse("This wallet tx is " + tx)

获取到跟本地钱包地址有关的tx后,就可以知道 到帐金额一系列的信息。

还有个类似的 配置: blocknotify
-blocknotify=<cmd> Execute command when the best block changes (%s in cmd is replaced by block hash)


参考:
https://www.bilibili.com/video/av18079636
https://bitcoin.stackexchange.com/a/24483
https://en.bitcoin.it/wiki/Running_Bitcoin
https://github.com/bitcoin/bitcoin/pull/1974

相关文章

网友评论

      本文标题:bitcoin: walletnotify的用法

      本文链接:https://www.haomeiwen.com/subject/tmmfoxtx.html