背景图

Linux下如何使用比特币命令

今天由于要去对接usdt,发现usdt其实是颜色币或者称为比特币上的代币。这种币原来是基于omni协议做的。omni基于比特币的客户端做了一个和比特币客户端兼容的代币客户端,负责解析各种货币。具体的知识就不深入探究了。我本来是看到代币输出中出现了“Unable to decode output address ”,重点是这种输出上居然有钱,可以查看这笔代币的调用https://blockchain.info/tx/48013644ceee5b5605cc589ecee35ab03e7900aac3837cbf04cbb3355caad0c5 。网上也查了一下,其实就是OP_RETURN脚本导致的,其实就是为了附加信息而已。后来想看看原本的脚本输出,突然忘记命令怎么打了,悲剧了,所以还是记录一下吧!

omni浏览器
比特币浏览器
omni官网

bitcoin如何安装

不用安装,官网有二进制的压缩包,所以安装的人很少。鄙人不信这个邪偏要源码编译安装,各种坑(其实我是为了运维能够顺利部署,提前采坑而已)。我发现很少有人在CentOS上安装,于是安装的时候经常出问题,为了安装花了一周时间,哎,大家还是下载二进制版本吧!我搞以太坊的时候也搞了一周,主要是geth节点同步区块慢,而且p2p节点老丢,换成parity节点好一些,但是还是出问题。后来以太坊官网更新了geth节点,立马重新安装问题才解决。为了破节点,前前后后浪费了大半个月。

bitcoin命令介绍

不管是bitcoin还是bitcash都有两个节点一个服务端和一个客户端,其实服务端也可以直接执行命令返回。

首先先运行服务端:

1
./bitcoind

这个命令在哪我就不说了,最好做一下ln链接,这样你就可以直接使用这个命令了;当然如果想做一些配置的话,就写一个服务吧。要想知道服务启动的运行参数可以运行bitcoind --help命令,这样更加有利于你写服务脚本。

然后利用客户端执行一条命令:

1
./bitcoin-cli getinfo

结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@localhost ~]# bitcoin-cli getinfo
{
"version" : 90500,
"protocolversion" : 70002,
"walletversion" : 60000,
"balance" : 0.00000000,
"blocks" : 356480,
"timeoffset" : 0,
"connections" : 3,
"proxy" : "",
"difficulty" : 47643398017.80344391,
"testnet" : false,
"keypoololdest" : 1514465769,
"keypoolsize" : 101,
"paytxfee" : 0.00000000,
"relayfee" : 0.00001000,
"errors" : "URGENT: Alert key compromised, upgrade required"
}

以前我敲命令挺溜的,现在都忘记了,我们来看一下帮助文档吧!也可以使用bitcoind;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
[root@localhost ~]# bitcoin-cli help
addmultisigaddress nrequired ["key",...] ( "account" )
addnode "node" "add|remove|onetry"
backupwallet "destination"
createmultisig nrequired ["key",...]
createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...}
decoderawtransaction "hexstring"
decodescript "hex"
dumpprivkey "bitcoinaddress"
dumpwallet "filename"
encryptwallet "passphrase"
getaccount "bitcoinaddress"
getaccountaddress "account"
getaddednodeinfo dns ( "node" )
getaddressesbyaccount "account"
getbalance ( "account" minconf )
getbestblockhash
getblock "hash" ( verbose )
getblockchaininfo
getblockcount
getblockhash index
getblocktemplate ( "jsonrequestobject" )
getconnectioncount
getdifficulty
getgenerate
gethashespersec
getinfo
getmininginfo
getnettotals
getnetworkhashps ( blocks height )
getnetworkinfo
getnewaddress ( "account" )
getpeerinfo
getrawchangeaddress
getrawmempool ( verbose )
getrawtransaction "txid" ( verbose )
getreceivedbyaccount "account" ( minconf )
getreceivedbyaddress "bitcoinaddress" ( minconf )
gettransaction "txid"
gettxout "txid" n ( includemempool )
gettxoutsetinfo
getunconfirmedbalance
getwalletinfo
getwork ( "data" )
help ( "command" )
importprivkey "bitcoinprivkey" ( "label" rescan )
importwallet "filename"
keypoolrefill ( newsize )
listaccounts ( minconf )
listaddressgroupings
listlockunspent
listreceivedbyaccount ( minconf includeempty )
listreceivedbyaddress ( minconf includeempty )
listsinceblock ( "blockhash" target-confirmations )
listtransactions ( "account" count from )
listunspent ( minconf maxconf ["address",...] )
lockunspent unlock [{"txid":"txid","vout":n},...]
move "fromaccount" "toaccount" amount ( minconf "comment" )
ping
sendfrom "fromaccount" "tobitcoinaddress" amount ( minconf "comment" "comment-to" )
sendmany "fromaccount" {"address":amount,...} ( minconf "comment" )
sendrawtransaction "hexstring" ( allowhighfees )
sendtoaddress "bitcoinaddress" amount ( "comment" "comment-to" )
setaccount "bitcoinaddress" "account"
setgenerate generate ( genproclimit )
settxfee amount
signmessage "bitcoinaddress" "message"
signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )
stop
submitblock "hexdata" ( "jsonparametersobject" )
validateaddress "bitcoinaddress"
verifychain ( checklevel numblocks )
verifymessage "bitcoinaddress" "signature" "message"

以太坊节点

这里就不做更多的介绍了。因为以太坊的命令使用相对简单。只要使用geth help命令查看一下即可。下面是我写的以太坊启动脚本。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# source function library
. /etc/rc.d/init.d/functions

USER=root
ENV="sudo -u $USER -H "
PROG=geth
GETH_CMD=/data/block/go-ethereum/build/bin/geth
GETH_DIR=/data/chain/eth
LOG_PATH=$GETH_DIR/geth.log
NODE_105="enode://f630e5e22c12a81ae14b7b7779c215b31790da44c87d5f8d781bb59d33aa572c4c13ff33dbdbf2512cdd914b82e9239fc4a6004a26405bd9aed40457f31ade97@192.168.3.105:30303"
# NODE_LIST="--nodiscover --light --bootnodes $NODE_105"
NODE_LIST="--nodiscover --syncmode light --bootnodes $NODE_105"
# MINER="--mine --minerthreads 1"
MINER="--verbosity 5"
API_OPTS="--rpc --rpcaddr 0.0.0.0 --rpcapi admin,db,eth,debug,miner,net,shh,txpool,personal,web3 --rpccorsdomain \"*\" --ws --vmdebug --debug"
RUN_TAGS="$API_OPTS $MINER --datadir $GETH_DIR $NODE_LIST"

LOCK_FILE=/var/lock/subsys/$PROG
PID_FILE=/var/run/${PROG}.pid
GETH_CON=`ps -ef | grep geth |grep datadir |wc -l`

start() {
[ `id -u` -ne 0 ] && echo "The user permission denied the service..." && exit 0
[ -x $started ] || exit 5
# echo -n $"Starting $prog:"
echo $"Starting $prog:"
echo "command: $ENV $GETH_CMD $RUN_TAGS"
$ENV $GETH_CMD $RUN_TAGS >>$LOG_PATH 2>&1 &
shift
echo $! > $PID_FILE
success || failure
retval=$?
echo
if [ $retval -eq 0 ]; then
touch $LOCK_FILE || retval=4
fi
return $retval
}

stop() {
[ `id -u` -ne 0 ] && echo "The user permission denied the service..." && exit 0
if [ $GETH_CON -gt 0 ]; then
#cat $PID_FILE | xargs kill -kill
kill `cat $PID_FILE`
GETH_PID=`ps -aux |grep geth |grep datadir |awk '{print $2}'`
while [ -n "$GETH_PID" ]; do
kill -kill $GETH_PID
GETH_PID=`ps -aux |grep geth |grep datadir |awk '{print $2}'`
done
echo -n $"Stopping $prog: "
success || failure
retval=$?
echo
[ $retval -eq 0 ] && rm -rf $LOCK_FILE && rm -rf $PID_FILE
return $retval
else
echo -e "The apps server is not running... " >>/dev/null 2>&1
fi
}

restart() {
stop
start
}

reload() {
restart
}

rh_status() {
status -p ${PID_FILE} $PROG
}

rh_status_q() {
rh_status >/dev/null 2>&1
}

case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
$1
;;
restart)
$1
;;
status)
rh_status
;;
*)

echo $"Usage: $0 {start|stop|status|restart|status}"
exit 2
esac

0%