借鉴bitcoin RPC API手册、bitcoincore及bitcoin zkcp版本
1、listtransactions
The listtransactions
RPC returns the most recent transactions that affect the wallet.
listtransactions
调用返回最近发生的与钱包有关的交易清单。该调用需要节点 启用钱包功能。
参数
Account:钱包账户名
Count:要提取的交易数量,默认值:10
Skip:要跳过的交易数量,默认值:0
IncludeWatchOnly:是否包含watch-only地址,默认值:false
返回值
listtransactions
调用返回指定数量的交易数组,成员结构如下:
account:账户名
address:地址
category:交易类别
amount:金额
label:交易备注
vout:输出序号
fee:交易费
confirmations:确认数量
trusted:是否可用,仅对未确认交易有效
generated:是否币基交易
blockhash:区块哈希
blockindex:区块序号
blocktime:区块时间戳
txid:交易id
walletconflicts:冲突交易
数组time:交易打包时间戳
timereceived:收到交易的时间戳
comment:备注
to:目标备注
otheraccount:对端账户
bip125-replaceable:是否可替换交易
abandoned:是否废弃交易
输出结果示例:
[
{
"involvesWatchonly" : true,
"account" : "",
"address" : "1GeDA9rRpqaCdsdkTzGtbajt6jPvn3pg2N",
"category" : "send",
"amount" : -3.45902877,
"vout" : 0,
"fee" : -0.00032890,
"confirmations" : 29710,
"blockhash" : "0000000000000000008b9cb38cd3105e75af94b3af79d0a59cbe4edb618fb814",
"blockindex" : 1705,
"blocktime" : 1463173519,
"txid" : "9b32d4315ac4c5e0d3a5fb947b9a198d3641698badc820643a7df23081f99695e",
"walletconflicts" : [
],
"time" : 1418695703,
"timereceived" : 1418925580,
"bip125-replaceable" : "no",
"abandoned": false
}
]
2、importpreimage
Imports a preimage for use in HTLC(Hashed Time Lock Contract) transactions. Only remains in memory.
【Hash(散列),把任意长度的输入(又叫做预映射,pre-image),通过散列算法,变换成固定长度的输出,该输出就是散列值。】
3、getnewaddress
Returns a new Bitcoin address for receiving payments.
getnewaddress
调用返回一个用于接收支付的新的比特币地址,如果调用时指定了 账户,那么该地址接收到的支付将计入该账户。getnewaddress调用需要节点启用钱包支持。
参数
Account:新地址所属账户,可选,默认值:""
AddressType:地址类型,可以是legacy、p2sh-segwit和bech32,可以 使用-addresstype设置默认地址类型
返回值
getnewaddress
调用返回一个新的地址。
输出结果示例:
mft61jjkmiEJwJ7Zw3r1h344D6aL1xwhma
4、createrawtransaction
createrawtransaction
调用创建一个未签名的序列化交易,该交易可以将一个UTXO 转让给指定的P2PKH地址或P2SH地址。该交易不会存储在钱包里,也不会发送到网络 中。
参数
Inputs:交易输入数组,每个成员对象的结构如下:
txid:UTXO的交易id
vout:UTXO的输出序号
Sequence:序列号,可选
Outputs:交易输出对象,键为地址,值为金额
Locktime:声明该交易生效的最早时间,可选
返回值
createrawtransaction
调用返回生成的未签名交易的序列化字符串。
5、signrawtransaction
signrawtransaction
调用使用钱包中的私钥对指定的序列化交易字符串进行签名。
6、sendrawtransaction
sendrawtransaction
调用验证指定交易并将其广播到P2P网络中。
参数
Transaction:要签名的交易字符串
Dependencies:依赖的UTXO详情数组,成员结构如下:
txid:UTXO所在的交易ID
vout:UTXO在输出中的序号
scriptPubKey:输出的公钥脚本
redeemScript:如果公钥脚本对应于脚本哈希,则本字段指向完整的赎回脚本PrivateKeys:用于签名的私钥数组
SigHashType:签名哈希类型,可以是:
ALL
NONE
SINGLEALL | ANYONECANPAY
NONE | ANYONECANPAY
SINGLE | ANYONECANPAY
返回值
signrawtransaction
调用返回签名后的交易信息,结构如下:
hex: 签名后的交易序列字符串,16进制表示
complete:交易是否具备完整签名,false表示还需要更多的签名
7、sendtoaddress
sendtoaddress
调用向指定的地址发送指定数量的比特币。该调用 需要节点启用钱包功能。
参数
ToAddress:接收地址
Amount:发送的比特币数量
Comment:备注文本
CommentTo:备注接收人
AutoFeeSubtract:是否自动扣除手续费,默认值:false
返回值
sendtoaddress
调用返回交易ID。
8、createhtlc
This adds support for timelocked contracts which can be used to atomically
swap hash preimages over the blockchain. It is very similar to the script
used by the lightning network.
9、importaddress
importaddress
调用将指定的地址或公钥脚本添加到钱包中,而不包含 其对应的私钥。你可以监听影响该地址或公钥脚本的交易,但由于没有私钥 就不能消费与其相关的UTXO。
参数
AddressOrScript:要添加的地址或公钥脚本
label:(string, optional, default="") An optional label
Rescan:是否重新扫描整个区块链,一次完整的扫描可能需要几分钟时间
p2sh:(boolean, optional, default=false) Add the P2SH version of the script as well
Note: This call can take over an hour to complete if rescan is true, during that time, other rpc calls
may report that the imported address exists but related transactions are still missing, leading to temporarily incorrect/bogus balances and unspent outputs until rescan completes.
If you have the full public key, you should call importpubkey instead of this.
Note: If you import a non-standard raw script in hex form, outputs sending to it will be treated
as change, and not show up in many RPCs.
返回值成功时
importaddress
调用返回null。
10、getinfo
The ·getinfo· RPC prints various information about the node and the network.
{
"result": null,
"error": {
"code": -32601,
"message": "getinfo\n\nThis call was removed in version 0.16.0. Use the appropriate fields from:\n- getblockchaininfo: blocks, difficulty, chain\n- getnetworkinfo: version, protocolversion, timeoffset, connections, proxy, relayfee, warnings\n- getwalletinfo: balance, keypoololdest, keypoolsize, paytxfee, unlocked_until, walletversion\n\nbitcoin-cli has the option -getinfo to collect and format these in the old format."
},
"id": null
}
11、validateaddress
validateaddress
调用返回指定比特币地址的相关信息。
参数
Address:地址
返回值
validateaddress调用返回关于指定地址的信息,其结构如下:
isvalid:是否有效
address:地址
scriptPubKey:公钥脚本
ismine:是否属于节点钱包
iswatchonly:是否watch-only地址
isscript:是否P2SH地址
script:P2SH地址的赎回脚本类型,可以是:
pubkey:P2PK脚本
pubkeyhash:P2PKH脚本
multisig:多重签名脚本
nonstandard:非标脚本
hex:P2SH地址对应的赎回脚本,仅对P2SH地址有效
addresses:P2SH脚本使用的地址数组
sigrequired:P2SH脚本需要的签名数量
pubkey:地址对应的公钥
iscompressed:公钥是否压缩格式
account:关联的钱包账户
hdkeypath:层级确定性密钥路径
hdmasterkeyid:层级确定性主密钥id
输出结果示例:
{
"isvalid": true,
"address": "17fshh33qUze2yifiJ2sXgijSMzJ2KNEwu",
"scriptPubKey": "76a914492ae280d70af33acf0ae7cd329b961e65e9cbd888ac",
"ismine": true,
"iswatchonly": false,
"isscript": false,
"pubkey": "0312eeb9ae5f14c3cf43cece11134af860c2ef7d775060e3a578ceec888acada31",
"iscompressed": true,
"account": "Test"
}