win10下btcd的安装和简单配置

btcd

btcd github地址

1. 安装

1) 安装go的包管理工具glide

glide github地址

$ go get -u github.com/Masterminds/glide

出现的问题

[ERROR] Unable to export dependencies to vendor directory: Error moving files: exit status 1. output: Access is denied. 0 dir(s) moved

解决方法

修改%GOPATH%/src/github.com/Masterminds/glide/path/winbug.go中的CustomRename函数的75行

修改前:

cmd := exec.Command("cmd.exe", "/c", "move", o, n)

修改后:

cmd := exec.Command("cmd.exe", "/c", "xcopy /s/y", o, n+"\\")

修改完成后需要重新编译生成glide.exe

go  install github.com/Masterminds/glide

2) 安装btcd

git clone https://github.com/btcsuite/btcd %GOPATH%\src\github.com\btcsuite\btcd
cd %GOPATH%\src\github.com\btcsuite\btcd
glide install
go install . ./cmd/...

附: linux下对应操作:

$ git clone https://github.com/btcsuite/btcd $GOPATH/src/github.com/btcsuite/btcd
$ cd $GOPATH/src/github.com/btcsuite/btcd
$ glide install
$ go install . ./cmd/...

遇到的问题

由于墙的原因,go get可能无法安装需要的golang.org/x/crypto等包

解决方法

可参考go get golang.org/x 包失败解决方法

有条件的话,建议使用代理下载,方便很多,避免安装过程中手动解决依赖问题

安装成功的话会在%GOPATH%/bin 目录下生成以下可执行程序:

addblock  btcctl  btcd  findcheckpoint  gencerts  glide

3)安装btcwallet [可选]

git clone https://github.com/btcsuite/btcwallet %GOPATH%\src\github.com\btcsuite\btcwallet
cd %GOPATH%\src\github.com\btcsuite\btcwallet
glide install
go install . ./cmd/...

附: linux下对应操作:

$ git clone https://github.com/btcsuite/btcwallet $GOPATH/src/github.com/btcsuite/btcwallet
$ cd $GOPATH/src/github.com/btcsuite/btcwallet
$ glide install
$ go install . ./cmd/...

安装btcwallet之后

$ ls ~/go/bin/
addblock btcctl btcd btcwallet dropwtxmgr findcheckpoint gencerts glide sweepaccount

2. 配置

配置btcd.conf

在%GOPATH%/bin下创建sample-btcd.conf

完整版参考: sample-btcd.conf

内容如下:

[Application Options]
rpcuser=+9AqUHnIIJIAmYt7Et+jpwxOci8=
rpcpass=7sMYDaq4K8hRxUsCsTs1tJoaw/Q=
#rpclimituser=mylimituser
#rpclimitpass=Limitedp4ssw0rd
#configfile=H:/btcd/btcd.conf # 貌似修改无效,为了使用方便,直接放在默认位置(C:\Users\你的用户名\AppData\Local\Btcd\btcd.conf)好了
datadir=H:/btcd/data
logdir=H:/btcd/logs
rpccert=H:/btcd/rpc.cert
rpckey=H:/btcd/rpc.key
debuglevel=debug
#maxpeers=50

其中#开头的都是注释内容

默认配置文件路径:

win10下btcd的安装和简单配置

win10下btcd的安装和简单配置

#切换中%GOPATH%目录
E:\>cd %GOPATH%\bin
E:\>F:
# 执行btcd.exe,第一次初始化的时候会加载相同目录下的sample-btcd.conf文件,之后使用如果不用-C指定配置文件则加载默认配置C:\Users\你的用户名\AppData\Local\Btcd\btcd.conf
F:\Go\bin>btcd.exe

配置btcct.conf

在%GOPATH%\bin目录下创建btcctl.conf

内容如下:

[Application Options]
rpcuser=+9AqUHnIIJIAmYt7Et+jpwxOci8=
rpcpass=7sMYDaq4K8hRxUsCsTs1tJoaw/Q=
rpccert=H:/btcd/rpc.cert

注意

这里的rpcuserrpcpass 是btcd随机生成

,在C:\Users\你的用户名\AppData\Local\Btcd\btcd.conf中

测试访问

F:\Go\bin>btcctl ping
open C:\Users\hupeng\AppData\Local\Btcd\rpc.cert: The system cannot find the file specified.

和btcd.exe相同,如果不指定-C,会加载默认配置

,默认配置文件在C:\Users\你的用户名\AppData\Local\Btcctl\btcctl.conf

查看默认配置文件,内容如下:

[Application Options]
rpcuser=+9AqUHnIIJIAmYt7Et+jpwxOci8=
rpcpass=7sMYDaq4K8hRxUsCsTs1tJoaw/Q=

发现缺少rpccert,加入:

rpccert=H:/btcd/rpc.cert

再次尝试

F:\Go\bin>btcctl.exe ping
# 打开新的cmd命令终端
C:\Users\hupeng>btcctl.exe getblockcount
141953
C:\Users\hupeng>btcctl.exe getblockhash 0
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f

访问网站(如:https://blockexplorer.com)验证hash。发现hash相同,至此环境搭建完毕

默认端口

Name Port
Default Bitcoin peer-to-peer port TCP 8333
Default RPC port TCP 8334

其他

By default, the rpc server now uses certs to protect the connection by default.

You can also check out https://github.com/conformal/btcd/tree/master/util/btcctl for an example of making an rpc connection using the cert btcd generates on initial startup.

When running btcd, if no configuration file is found, the sample-btcd.conf file is copied to the default path,

with the rpcuser and rpcpass lines populated with random base64 encoded values.

When running btcctl, if no configuration file is found, it attempts to read the btcd.conf file at its default path,

and create a basic btcctl.conf file by copying the rpcuser and rpcpass.

参考:

上一篇:Python学习笔记_week3_函数


下一篇:全国大学API接口分享