hyperledger子项目burrow单机运行

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1444. Elephpotamus Time limit: 0.5 second Memory limit: 64 MB Harry Potter is taking an examination in Care for Magical Creatures. His task is to feed a dwarf elephpotamus. Harry remembers that elephpotamuses are very straightforward and imperturbable. In fact, they are so straightforward that always move along a straight line and they are so imperturbable that only move when attracted by something really tasty. In addition, if an elephpotamus stumbles into a chain of its own footprints, it falls into a stupor and refuses to go anywhere. According to Hagrid, elephpotamuses usually get back home moving along their footprints. This is why they never cross them, otherwise they may get lost. When an elephpotamus sees its footprints, it tries to remember in detail all its movements since leaving home (this is also the reason why they move along straight lines only, this way it is easier to memorize). Basing on this information, the animal calculates in which direction its burrow is situated, then turns and goes straight to it. It takes some (rather large) time for an elephpotamus to perform these calculations. And what some ignoramuses recognize as a stupor is in fact a demonstration of outstanding calculating abilities of this wonderful, though a bit slow-witted creature. Elephpotamuses' favorite dainty is elephant pumpkins, and some of such pumpkins grow on the lawn where Harry is to take his exam. At the start of the exam, Hagrid will drag the elephpotamus to one of the pumpkins. Having fed the animal with a pumpkin, Harry can direct it to any of the remaining pumpkins. In order to pass the exam, Harry must lead the elephpotamus so that it eats as many pumpkins as possible before it comes across its footprints. Input The first input line contains the number of pumpkins on the lawn N (3 ≤ N ≤ 30000). The pumpkins are numbered from 1 to N, the number one being assigned to the pumpkin to which the animal is brought at the start of the trial. In the next N lines, the coordinates of the pumpkins are given in the order corresponding to their numbers. All the coordinates are integers in the range from −1000 to 1000. It is guaranteed that there are no two pumpkins at the same location and there is no straight line passing through all the pumpkins. Output In the first line write the maximal number K of pumpkins that can be fed to the elephpotamus. In the next K lines, output the order in which the animal will eat them, giving one number in a line. The first number in this sequence must always be 1.写一段Java完成此目的
最新发布
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值