2017-11-28,潘冬
在工作生活中,遇到很多人谈比特币,总是有人拿银行卡和bitcoin钱包做对比,我就感觉他们其实并没有真的理解比特币是什么。比特币的底层自然还是区块链+共识算法,但从不关心链的用户的角度来看的话,比特币钱包是什么呢?可以说,对用户来说,bitcoin钱包的本质就是一对密钥,这对秘钥更像是一个比特币网络上的身份证,而不是传统意义上的钱包。
比特币区块链的区块中存储的是交易记录,这些交易记录的收发人由一个钱包地址表示。钱包地址是这对密钥中公钥转换而来。只要持有钱包地址的公钥的对应私钥,就可以对交易签名,从而实现转账。可以从有效的钱包地址对随机的无效钱包地址转账,但由于无效的钱包地址没有对应私钥,这笔bitcoin将再也无法使用。钱包的管理就是对密钥的管理,转账操作的最底层就是使用私钥对交易进行签名。
bitcoin没有中心组织,本质上没有特定操作钱包的软件。只要能和节点们连通,收发特定格式的消息,调用私钥签名交易,就是能够使用的钱包。
bitcoin最广泛接受的钱包软件由bitcoin核心团队维护,是bitcoin core和bitcoind,它们分别是windows和linux平台上不同的实现。地址为:
https://github.com/bitcoin/bitcoin
开源社区github上关注度最高的其它bitcoin钱包有:
https://github.com/bcoin-org/bcoin,nodejs实现,提供rest接口
https://github.com/bitpay/copay,nodejs实现,提供安卓、ios、windows的gui客户端
由bitcoind提供的接口列表如下,可以在各种语言api和json-rpc中调用这些接口,具体的参数说明可以查看:https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)
== Blockchain ==
getbestblockhash
getblock “blockhash” ( verbosity )
getblockchaininfo
getblockcount
getblockhash height
getblockheader “hash” ( verbose )
getchaintips
getchaintxstats ( nblocks blockhash )
getdifficulty
getmempoolancestors txid (verbose)
getmempooldescendants txid (verbose)
getmempoolentry txid
getmempoolinfo
getrawmempool ( verbose )
gettxout “txid” n ( include_mempool )
gettxoutproof [“txid”,…] ( blockhash )
gettxoutsetinfo
preciousblock “blockhash”
pruneblockchain
verifychain ( checklevel nblocks )
verifytxoutproof “proof”
== Control ==
getinfo
getmemoryinfo (“mode”)
help ( “command” )
stop
uptime
== Generating ==
generate nblocks ( maxtries )
generatetoaddress nblocks address (maxtries)
== Mining ==
getblocktemplate ( TemplateRequest )
getmininginfo
getnetworkhashps ( nblocks height )
prioritisetransaction
submitblock “hexdata” ( “dummy” )
== Network ==
addnode “node” “add|remove|onetry”
clearbanned
disconnectnode “[address]” [nodeid]
getaddednodeinfo ( “node” )
getconnectioncount
getnettotals
getnetworkinfo
getpeerinfo
listbanned
ping
setban “subnet” “add|remove” (bantime) (absolute)
setnetworkactive true|false
== Rawtransactions ==
combinerawtransaction [“hexstring”,…]
createrawtransaction [{“txid”:”id”,”vout”:n},…] {“address”:amount,”data”:”hex”,…} ( locktime ) ( replaceable )
decoderawtransaction “hexstring”
decodescript “hexstring”
fundrawtransaction “hexstring” ( options )
getrawtransaction “txid” ( verbose )
sendrawtransaction “hexstring” ( allowhighfees )
signrawtransaction “hexstring” ( [{“txid”:”id”,”vout”:n,”scriptPubKey”:”hex”,”redeemScript”:”hex”},…] [“privatekey1”,…] sighashtype )
== Util ==
createmultisig nrequired [“key”,…]
estimatefee nblocks
estimatesmartfee conf_target (“estimate_mode”)
signmessagewithprivkey “privkey” “message”
validateaddress “address”
verifymessage “address” “signature” “message”
== Wallet ==
abandontransaction “txid”
abortrescan
addmultisigaddress nrequired [“key”,…] ( “account” )
addwitnessaddress “address”
backupwallet “destination”
bumpfee “txid” ( options )
dumpprivkey “address”
dumpwallet “filename”
encryptwallet “passphrase”
getaccount “address”
getaccountaddress “account”
getaddressesbyaccount “account”
getbalance ( “account” minconf include_watchonly )
getnewaddress ( “account” )
getrawchangeaddress
getreceivedbyaccount “account” ( minconf )
getreceivedbyaddress “address” ( minconf )
gettransaction “txid” ( include_watchonly )
getunconfirmedbalance
getwalletinfo
importaddress “address” ( “label” rescan p2sh )
importmulti “requests” ( “options” )
importprivkey “privkey” ( “label” ) ( rescan )
importprunedfunds
importpubkey “pubkey” ( “label” rescan )
importwallet “filename”
keypoolrefill ( newsize )
listaccounts ( minconf include_watchonly)
listaddressgroupings
listlockunspent
listreceivedbyaccount ( minconf include_empty include_watchonly)
listreceivedbyaddress ( minconf include_empty include_watchonly)
listsinceblock ( “blockhash” target_confirmations include_watchonly include_removed )
listtransactions ( “account” count skip include_watchonly)
listunspent ( minconf maxconf [“addresses”,…] [include_unsafe] [query_options])
listwallets
lockunspent unlock ([{“txid”:”txid”,”vout”:n},…])
move “fromaccount” “toaccount” amount ( minconf “comment” )
removeprunedfunds “txid”
sendfrom “fromaccount” “toaddress” amount ( minconf “comment” “comment_to” )
sendmany “fromaccount” {“address”:amount,…} ( minconf “comment” [“address”,…] replaceable conf_target “estimate_mode”)
sendtoaddress “address” amount ( “comment” “comment_to” subtractfeefromamount replaceable conf_target “estimate_mode”)
setaccount “address” “account”
settxfee amount
signmessage “address” “message”