0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

bitcoin: walletnotify的用法

Posted at

-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

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?