当前位置: 首页 > 工具软件 > Burrow > 使用案例 >

hyperledger子项目burrow单机运行

沃皓轩
2023-12-01

Burrow私链搭建预研

1. 引言

1.1 目的

本文为Burrow私链搭建预研分析。

2.预研环境

  • Go语言版本:1.11以上

  • Goland安装mod

    • https://goproxy.cn 
      
  • 执行命令

    • go mod vendor
      
  • 安装命令

go get github.com/hyperledger/burrow
cd $GOPATH/src/github.com/hyperledger/burrow
export GO111MODULE=on
make build
#burrow 可执行文件默认在$HOME/go/bin下

3. 启动一个单节点

3.1 编译cmd文件

3.2 创建burrow.toml文件

# Read spec on stdin
burrow spec -p1 -f1 | burrow configure -s- > burrow.toml

3.3 创建创世文件

# This is a place we can store config files and burrow's working directory '.burrow'
mkdir chain_dir && cd chain_dir
burrow spec --participant-accounts=1 --full-accounts=1 > genesis-spec.json
burrow configure --genesis-spec=genesis-spec.json > burrow.toml

3.4 启动burrow

# To select our validator address by index in the GenesisDoc
# Or to select based on address directly (substituting the example address below with your validator's):
burrow start --address=9F50D730BD69A7258F5EA9DDD8A92B58FE763C7C
#地址需要在.key/data/下有账号才行

3.5 如果要重置节点,只需删除工作目录即可

rm -rf .burrow

4. 发送一笔交易

4.1 创建部署文件test.yaml,内容如下:

jobs:
- name: sendTxTest1
  send:
      destination: PUT_HERE_ONE_ACCOUNT_OF_YOUR_GENESIS
      amount: 42

4.2 将test.yaml发送至单节点,并替换签名地址$SIGNING_ADDRESS

SIGNING_ADDRESS=HERE_ONE_VALIDATOR_ADDRESS_OF_THE_GENESIS
burrow deploy --address BE584820DC904A55449D7EB0C97607B40224B96E test.yaml

4.3 输出结果如下:

*****Executing Job*****

Job Name                                    => defaultAddr


*****Executing Job*****

Job Name                                    => sendTxTest1


Transaction Hash                            => 41E0C13D1515F83E6FFDC5032C60682BE1F5B19A
Writing [test.output.json] to current directory

5. 部署合约

5.1 文件准备

  • 部署合约需要solidity合约和deploy.yaml文件,并且在同一目录下,并没有其他的yaml 和 sol文件。

5.2 deploy.yaml 示例如下:

jobs:

- name: deployStorageK
  deploy:
      contract: storage.sol

- name: setStorageBaseBool
  set:
      val: "true"

- name: setStorageBool
  call:
      destination: $deployStorageK
      function: setBool
      data:
        - $setStorageBaseBool

- name: queryStorageBool
  query-contract:
      destination: $deployStorageK
      function: getBool

- name: assertStorageBool
  assert:
      key: $queryStorageBool
      relation: eq
      val: $setStorageBaseBool

# tests string bools: #71
- name: setStorageBool2
  call:
      destination: $deployStorageK
      function: setBool2
      data:
        - true

- name: queryStorageBool2
  query-contract:
      destination: $deployStorageK
      function: getBool2

- name: assertStorageBool2
  assert:
      key: $queryStorageBool2
      relation: eq
      val: "true"

- name: setStorageBaseInt
  set:
      val: 50000

- name: setStorageInt
  call:
      destination: $deployStorageK
      function: setInt
      data:
        - $setStorageBaseInt

- name: queryStorageInt
  query-contract:
      destination: $deployStorageK
      function: getInt

- name: assertStorageInt
  assert:
      key: $queryStorageInt
      relation: eq
      val: $setStorageBaseInt

- name: setStorageBaseUint
  set:
      val: 9999999

- name: setStorageUint
  call:
      destination: $deployStorageK
      function: setUint
      data:
        - $setStorageBaseUint

- name: queryStorageUint
  query-contract:
      destination: $deployStorageK
      function: getUint

- name: assertStorageUint
  assert:
      key: $queryStorageUint
      relation: eq
      val: $setStorageBaseUint

- name: setStorageBaseAddress
  set:
      val: "1040E6521541DAB4E7EE57F21226DD17CE9F0FB7"

- name: setStorageAddress
  call:
      destination: $deployStorageK
      function: setAddress
      data:
        - $setStorageBaseAddress

- name: queryStorageAddress
  query-contract:
      destination: $deployStorageK
      function: getAddress

- name: assertStorageAddress
  assert:
      key: $queryStorageAddress
      relation: eq
      val: $setStorageBaseAddress

- name: setStorageBaseBytes
  set:
      val: marmatoshi

- name: setStorageBytes
  call:
      destination: $deployStorageK
      function: setBytes
      data:
        - $setStorageBaseBytes

- name: queryStorageBytes
  query-contract:
      destination: $deployStorageK
      function: getBytes

- name: assertStorageBytes
  assert:
      key: $queryStorageBytes
      relation: eq
      val: $setStorageBaseBytes

- name: setStorageBaseString
  set:
      val: nakaburrow

- name: setStorageString
  call:
      destination: $deployStorageK
      function: setString
      data:
        - $setStorageBaseString

- name: queryStorageString
  query-contract:
      destination: $deployStorageK
      function: getString

- name: assertStorageString
  assert:
      key: $queryStorageString
      relation: eq
      val: $setStorageBaseString

5.3 solidity合约示例如下:

pragma solidity >=0.0.0;

contract SimpleStorage {
  bool storedBool;
  bool storedBool2;
  int storedInt;
  uint storedUint;
  address storedAddress;
  bytes32 storedBytes;
  string storedString;

  function setBool(bool x) public {
    storedBool = x;
  }

  function getBool() view public returns (bool retBool) {
    return storedBool;
  }

  function setBool2(bool x) public {
    storedBool2 = x;
  }

  function getBool2() view public returns (bool retBool) {
    return storedBool2;
  }

  function setInt(int x) public {
    storedInt = x;
  }

  function getInt() view public returns (int retInt) {
    return storedInt;
  }

  function setUint(uint x) public {
    storedUint = x;
  }

  function getUint() view public returns (uint retUint) {
    return storedUint;
  }

  function setAddress(address x) public {
    storedAddress = x;
  }

  function getAddress() view public returns (address retAddress) {
    return storedAddress;
  }

  function setBytes(bytes32 x) public {
    storedBytes = x;
  }

  function getBytes() view public returns (bytes32 retBytes) {
    return storedBytes;
  }

  function setString(string memory x) public {
    storedString = x;
  }

  function getString() view public returns (string memory retString) {
    return storedString;
  }
}

4、因为需要编译合约,我们采取solc binary编译方式,以下是安装过程:

首先安装npm和node
一、第一种安装方法(推荐)
#安装nvm
[sudo] curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
#激活nvm
[sudo] source ~/.nvm/nvm.sh
#安装node
[sudo] nvm install node 
#切换到该版本
[sudo] nvm use node

二、第二种安装方法
#安装nodejs
[sudo] yum install nodejs
#建立软连接
[sudo] ln -s /usr/bin/nodejs /usr/bin/node
#安装npm
[sudo] yum install npm

#安装remix
[sudo] npm install remix-ide -g
[sudo] remix-ide

4、将合约部署至单节点

burrow deploy --address F71831847564B7008AD30DD56336D9C42787CF63 deploy.yaml

6. 添加验证者

6.1 删除旧数据,创建新文件

 rm -rf .burrow* .keys*
 burrow spec -f2 | burrow configure -s- --pool

6.2 启动节点

burrow start --config=burrow000.toml
burrow start --config=burrow001.toml

6.3 删除节点

rm  -rf .burrow00*

6.3 查看状态

curl -s 127.0.0.1:26758/consensus

6.4 向Burrow网络发送交易

  • 步骤内容和 4. 一样,可参考

7. 绑定验证器

7.1 先创建两个账户,预先绑定一个验证节点

burrow spec -v1 -r1 | burrow configure -s- --pool

7.2 启动两个节点

burrow start --config burrow000.toml & 
burrow start --config burrow001.toml &

7.3 提前查询一下链上的验证节点

curl -s " localhost:26758 / validators ”

7.4 绑定第二个节点并出块

burrow tx --config burrow001.toml formulate bond --amount 10000 | burrow tx commit

7.5 发送交易

burrow tx --config burrow001.toml formulate bond --source 8A468CC3A28A6E84ED52E433DA21D6E9ED7C1577 --amount 10000

7.6 再次查询链上验证节点

curl -s "localhost:26759/validators"

7.7 解绑验证节点

burrow tx formulate unbond | burrow tx commit
 类似资料: