wavesplatform/gowaves
GitHub: wavesplatform/gowaves
Waves 区块链节点的 Go 语言实现,配套节点运行、钱包管理、区块链导入及客户端开发库等全套工具。
Stars: 254 | Forks: 71
# gowaves
Waves Node 的 Go 语言实现,以及用于 Waves 区块链的库和工具。
[](https://github.com/wavesplatform/gowaves/actions/workflows/go.yml)
[](https://goreportcard.com/report/github.com/wavesplatform/gowaves)
[](https://codecov.io/gh/wavesplatform/gowaves)
[](https://godoc.org/github.com/wavesplatform/gowaves)
## Waves Node
您可以在 Linux、macOS 或 Windows 上运行 Waves Node。请从 [发布页面](https://github.com/wavesplatform/gowaves/releases) 下载相应的二进制文件。
您可以通过网络同步节点,也可以导入已下载的区块链文件。
### 如何从文件导入区块链
区块链文件可在 [MainNet](http://blockchain.wavesnodes.com)、[TestNet](http://blockchain-testnet.wavesnodes.com) [StageNet](http://blockchain-stagenet.wavesnodes.com/) 下载页面获取。
可以按照以下步骤进行导入:
1. 下载区块链文件
2. 从 [Releases](https://github.com/wavesplatform/gowaves/releases) 下载 `importer` 工具
3. 运行命令,将区块链文件路径和节点的 state 目录作为参数传入。
第三个参数是要导入的区块数量,它应该比期望的高度少一。
```
./importer -blockchain-path [path to blockchain file] -data-path [path to node state directory] -blocks-number [height - 1]
```
导入可能需要几个小时,之后您就可以按照下一节的说明运行节点了。
请注意,Go Node 拥有其自身的 state 存储结构,与 Scala Node 不兼容。
### 如何运行节点
按照以下步骤运行节点:
1. 从 [Releases](https://github.com/wavesplatform/gowaves/releases) 下载合适的节点二进制文件
2. 运行命令,如有需要,请传入节点 state 目录的路径。
```
./node -state-path [path to node state directory]
```
默认情况下,节点会作为 MainNet 节点运行。要运行 TestNet 节点,请将 `testnet` 作为区块链类型传入。您还可以输入以逗号分隔的对等节点地址列表(可选):
```
./node -state-path [path to node state directory] -blockchain-type testnet
```
阅读更多关于[将节点作为 Linux 服务运行](https://github.com/wavesplatform/gowaves/tree/master/cmd/node#readme)的信息。
### 如何设置区块生成
Go Node 有两个参数,允许从钱包文件中加载私钥。
```
-wallet-path [path to wallet file]
-wallet-password [password string]
```
例如:
```
./node -state-path ~/gowaves-testnet/ -blockchain-type testnet -wallet-path ~/testnet.wallet -wallet-password 'some super secret password'
```
一旦提供了这些参数,节点就会尝试加载并使用私钥来生成区块。
#### 如何创建钱包文件
要创建钱包文件,请使用 `wallet` 工具。请从 [Releases](https://github.com/wavesplatform/gowaves/releases) 页面下载合适版本的 `wallet` 工具。
以下命令将创建钱包文件并向其中添加一个新的 seed:
```
./wallet -new
```
该工具会要求输入密码以加密新的钱包文件。如果钱包文件不存在,则会创建该文件。
默认情况下,新的钱包文件名为 `.waves` 并存储在用户的主目录中。可以使用 `-wallet` 选项设置不同的钱包文件位置。
此外,也可以导入现有的 seed phrase。请使用 `-seed-phrase` 选项来执行此操作。
```
./wallet -seed-phrase "words of seed phrase..."
```
如果您有来自 Scala 节点配置文件的 Base58 编码的 seed phrase。可以使用 `-seed-phrase-base58` 选项将其导入。
此外,还可以使用 `Settings | Security | Encoded Seed Phrase` 菜单选项从 Waves.Exchange 钱包导出此 Base58 编码的 seed phrase。
```
./wallet -seed-phrase-base58
```
最后一个导入选项 `-account-seed-base58` 允许导入 Base58 编码的账户 seed。
```
./wallet -account-seed-base58
```
要列出钱包中存储的 seed,请运行以下命令并输入密码。
```
./wallet -show
```
### 客户端库示例
从 BASE58 字符串创建发送者的公钥:
```
sender, err := crypto.NewPublicKeyFromBase58("")
if err != nil {
panic(err)
}
```
从 BASE58 字符串创建发送者的私钥:
```
sk, err := crypto.NewSecretKeyFromBase58("")
if err != nil {
panic(err)
}
```
创建脚本的地址:
```
a, err := proto.NewAddressFromString("