区块链学习笔记

Setup bitshares testnet

2018-06-08  本文已影响0人  杨小伟的世界

We have already learned how to build bitshare from source and connect to bitshare network, it is time to setup our own bitshare testnet.

Exciting!

Let's rock~

Create Genesis

Genesis contains the initial state of the network, eg. chain id.

programs/witness_node/witness_node --create-genesis-json yw-genesis.json

Create Data Dir

programs/witness_node/witness_node --data-dir data/yw-blockprod --genesis-json yw-genesis.json --seed-nodes "[]"

It is weird that have to execute this command twice. May investigate this later.

If succeed, you would see the following lines.

1428023ms th_a       main.cpp:266                  main                 ] Started BitShares node on a chain with 0 blocks.
1428023ms th_a       main.cpp:267                  main                 ] Chain ID is 0f951eed245d6b972cb78056191d7524572d0bd10d2cbe9572b33e25fdff57dc

Prepare block production

Open configure file data/yw-blockprod/config.ini, and set as following

p2p-endpoint = 10.7.0.121:11010
rpc-endpoint = 10.7.0.121:11011

genesis-json = yw-genesis.json

private-key = ["GPH6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV","5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"]

witness-id = "1.6.1"

Start block production

programs/witness_node/witness_node --data-dir data/yw-blockprod --enable-stale-production --seed-nodes "[]"

If succeed, you would see the following lines.

1807829ms th_a       main.cpp:266                  main                 ] Started BitShares node on a chain with 0 blocks.
1807829ms th_a       main.cpp:267                  main                 ] Chain ID is 0f951eed245d6b972cb78056191d7524572d0bd10d2cbe9572b33e25fdff57dc
1810002ms th_a       witness.cpp:181               block_production_loo ] Generated block #1 with timestamp 2018-06-08T01:30:10 at time 2018-06-08T01:30:10
1880001ms th_a       witness.cpp:181               block_production_loo ] Generated block #2 with timestamp 2018-06-08T01:31:20 at time 2018-06-08T01:31:20

Interact with network

Retrieve Chain-ID

Now we could interact with the network with rpc.

curl --data '{"jsonrpc": "2.0", "method": "get_chain_properties", "params": [], "id": 1}' http://127.0.0.1:11011/rpc && echo

This will return the chain id of the network.

{"id":1,"jsonrpc":"2.0","result":{"id":"2.11.0","chain_id":"0f951eed245d6b972cb78056191d7524572d0bd10d2cbe9572b33e25fdff57dc","immutable_parameters":{"min_committee_member_count":11,"min_witness_count":11,"num_special_accounts":0,"num_special_assets":0}}}

Create a wallet and access to stake

programs/cli_wallet/cli_wallet --wallet-file yw-wallet.json --chain-id 0f951eed245d6b972cb78056191d7524572d0bd10d2cbe9572b33e25fdff57dc --server-rpc-endpoint ws://127.0.0.1:11011 -u '' -p ''
set_password supersecret
unlock supersecret
import_key nathan "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
import_balance nathan ["5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"] true
unlocked >>> list_account_balances nathan
list_account_balances nathan
10000000000 BTS

Open another account and transfer asset

unlocked >>> upgrade_account nathan true
unlocked >>> suggest_brain_key           
suggest_brain_key 
{
  "brain_priv_key": "REABUSE REFRACT BROODY FIGARO INTRANT BEGRIME MNEME TANE REDDING RESPADE MOMENTA WINK FANION SUET SLOB BAIGNET",
  "wif_priv_key": "5HrNKMLqUCyf89gS9g8hwhDNjSRYV1PRcQm1tH1wHndguijrqt9",
  "pub_key": "BTS6Pz8gEvrEusTmrKcNJyqaGnMAF9gsgWYZ6qqwnqBhvm1hsBHR8"
}
unlocked >>> create_account_with_brain_key "REABUSE REFRACT BROODY FIGARO INTRANT BEGRIME MNEME TANE REDDING RESPADE MOMENTA WINK FANION SUET SLOB BAIGNET" alpha nathan nathan true
unlocked >>> list_account_balances nathan
list_account_balances nathan
9999987999.85938 BTS
unlocked >>> transfer nathan alpha 20000 BTS "here is some cash" true
unlocked >>> list_account_balances alpha                              
list_account_balances alpha
20000 BTS

Connect another node to network

Import the genesis file from previous node. And run:

programs/witness_node/witness_node --data-dir data/yw-blockprod --genesis-json yw-genesis.json --seed-nodes "[]" -s 10.7.0.121:11010 --rpc-endpoint 127.0.0.1:8090

After doing so, you would see

3151450ms th_a       main.cpp:266                  main                 ] Started BitShares node on a chain with 360 blocks.
3151450ms th_a       main.cpp:267                  main                 ] Chain ID is 0f951eed245d6b972cb78056191d7524572d0bd10d2cbe9572b33e25fdff57dc
3194899ms th_a       application.cpp:512           handle_block         ] Got block: #367 time: 2018-06-08T06:53:15 latency: -100 ms from: init0  irreversible: 0 (-367)
3250024ms th_a       application.cpp:512           handle_block         ] Got block: #368 time: 2018-06-08T06:54:10 latency: 24 ms from: init0  irreversible: 0 (-368)
3304869ms th_a       application.cpp:512           handle_block         ] Got block: #369 time: 2018-06-08T06:55:05 latency: -130 ms from: init0  irreversible: 0 (-369)

Notice the chain id is the same as above.

Now let's connect a wallet to this node and import nathan's account.

programs/cli_wallet/cli_wallet  --wallet-file yw-wallet.json --chain-id 0f951eed245d6b972cb78056191d7524572d0bd10d2cbe9572b33e25fdff57dc -s ws://127.0.0.1:8090
new >>> set_password supersecret
set_password supersecret
null
locked >>> unlock supersecret
unlock supersecret
null
unlocked >>> import_key nathan 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
import_key nathan 5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3
735430ms th_a       wallet.cpp:773                save_wallet_file     ] saving wallet to file yw-wallet.json
735444ms th_a       wallet.cpp:464                copy_wallet_file     ] backing up wallet yw-wallet.json to after-import-key-9407629b.wallet
true
unlocked >>> list_my_accounts 
list_my_accounts 
[{
    "id": "1.2.17",
    "membership_expiration_date": "1969-12-31T23:59:59",
    "id": "1.2.17",                                                                                                                                                                                      [0/65]
    "membership_expiration_date": "1969-12-31T23:59:59",
    "registrar": "1.2.17",
    "referrer": "1.2.17",
    "lifetime_referrer": "1.2.17",
    "network_fee_percentage": 2000,
    "lifetime_referrer_fee_percentage": 8000,
    "referrer_rewards_percentage": 0,
    "name": "nathan",
...

Become a witness

unlocked >>> create_witness nathan "http://10.7.0.122:8091" true
create_witness nathan "http://10.7.0.122:8091" true
{
  "ref_block_num": 404,
  "ref_block_prefix": 2229792516,
  "expiration": "2018-06-08T07:26:35",
  "operations": [[
      20,{
        "fee": {
          "amount": 500000000,
          "asset_id": "1.3.0"
        },
        "witness_account": "1.2.17",
        "url": "http://10.7.0.122:8091",
        "block_signing_key": "BTS6TvwmSY4c5zBT9cMEb8jKAQtBrCZyT5ggjsPvCKZewjZeJnL11"
      }
    ]
  ],
  "extensions": [],
  "signatures": [
    "1f2661c3d924d42d93e1b5f16be72de38a7383716c1d0e7fa7823bf62488574e580eb2ae716fe8f63191ed6434d1f135a7d82913099b43a0ef89f4952b94b7540a"
  ]
}

unlocked >>> vote_for_witness nathan nathan true true
vote_for_witness nathan nathan true true
{
  "ref_block_num": 405,
  "ref_block_prefix": 53595724,
  "expiration": "2018-06-08T07:27:30",
  "operations": [[
      6,{
        "fee": {
          "amount": 2005664,
          "asset_id": "1.3.0"
        },
        "account": "1.2.17",
        "new_options": {
          "memo_key": "BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
          "voting_account": "1.2.5",
          "num_witness": 0,
          "num_committee": 0,
          "votes": [
            "1:22"
          ],
          "extensions": []
        },
        "extensions": {}
      }
    ]
  ],
  "extensions": [],
  "signatures": [
    "2048343bbf60f1552b1b998329fbddaffdd978345630830ef0028fe851a4aac2b905e5961b660c2ac2d18f695c76e6fdaebcff9d0fa221e1614ab0bc21dd0c67b7"
  ]
}

unlocked >>> get_witness nathan
get_witness nathan
{
  "id": "1.6.12",
  "witness_account": "1.2.17",
  "last_aslot": 0,
  "signing_key": "BTS6TvwmSY4c5zBT9cMEb8jKAQtBrCZyT5ggjsPvCKZewjZeJnL11",
  "vote_id": "1:22",
  "total_votes": 0,
  "url": "http://10.7.0.122:8091",
  "total_missed": 0,
  "last_confirmed_block_num": 0
}

unlocked >>> dump_private_keys 
dump_private_keys 
[[
    "BTS6TvwmSY4c5zBT9cMEb8jKAQtBrCZyT5ggjsPvCKZewjZeJnL11",
    "5Jux91EswkCZC5JuQ3Zi3GLZRKwwCPpnChQroSUc4o2RufAjaUY"
  ],[
    "...",
    "..."
  ]
]

Adjust the config.ini and restart the node

The config.ini

p2p-endpoint = 10.7.0.122:8090
rpc-endpoint = 10.7.0.122:8091

genesis-json = yw-genesis.json

private-key = ["BTS6TvwmSY4c5zBT9cMEb8jKAQtBrCZyT5ggjsPvCKZewjZeJnL11","5Jux91EswkCZC5JuQ3Zi3GLZRKwwCPpnChQroSUc4o2RufAjaUY"]

witness-id = "1.6.12"
programs/witness_node/witness_node --data-dir data/yw-blockprod --seed-nodes "[]" -s 10.7.0.121:11010

Now, wait until next maintenance interval~

After you see the log below, that means the witness is producing block!

350002ms th_a       witness.cpp:181               block_production_loo ] Generated block #1542 with timestamp 2018-06-09T00:05:50 at time 2018-06-09T00:05:50
390074ms th_a       application.cpp:512           handle_block         ] Got block: #1543 time: 2018-06-09T00:06:30 latency: 74 ms from: init0  irreversible: 0 (-1543)

Create an asset

This could be done in cli_wallet.

Following example creates an UIA, for creating MPA please refer to MPA

unlocked >>> create_asset nathan UNEST 5 { "max_supply": "1000000000000000", "market_fee_percent": 0, "max_market_fee": "1000000000000000", "issuer_permissions": 79, "flags": 0, "core_exchange_rate": { "base": { "amount": 10000, "asset_id": "1.3.0" }, "quote": { "amount": 50000, "asset_id": "1.3.1" } }, "whitelist_authorities": [], "blacklist_authorities": [], "whitelist_markets": [], "blacklist_markets": [], "description": "", "extensions": [] } null true

Dump the option in a pretty mode

{
  "max_supply": "1000000000000000",
  "market_fee_percent": 0,
  "max_market_fee": "1000000000000000",
  "issuer_permissions": 79,
  "flags": 0,
  "core_exchange_rate": {
    "base": {
      "amount": 10,
      "asset_id": "1.3.0"
    },
    "quote": {
      "amount": 5,
      "asset_id": "1.3.1"
    }
  },
  "whitelist_authorities": [],
  "blacklist_authorities": [],
  "whitelist_markets": [],
  "blacklist_markets": [],
  "description": "",
  "extensions": []
}

Afte doing so we could list this asset in cli_walet.

unlocked >>> list_assets "UNEST" 1    
list_assets "UNEST" 1
[{
    "id": "1.3.1",
    "symbol": "UNEST",
    "precision": 5,
    "issuer": "1.2.17",
    "options": {
      "max_supply": "1000000000000000",
      "market_fee_percent": 0,
      "max_market_fee": "1000000000000000",
      "issuer_permissions": 79,
      "flags": 0,
      "core_exchange_rate": {
        "base": {
          "amount": 10000,
          "asset_id": "1.3.0"
        },
        "quote": {
          "amount": 50000,
          "asset_id": "1.3.1"
        }
      },
      "whitelist_authorities": [],
      "blacklist_authorities": [],
      "whitelist_markets": [],
      "blacklist_markets": [],
      "description": "",
      "extensions": []
    },
    "dynamic_asset_data_id": "2.3.1",
    "bitasset_data_id": "2.4.0"
  }
]

Till now, you still don't have the asset, next step is issue it.

unlocked >>> issue_asset nathan 50000 UNEST "unest test coin" true

After this, you could see this asset in your account.

unlocked >>> list_account_balances nathan
list_account_balances nathan
9999662958.71486 BTS                          
50000 UNEST

Now you could transfer money to others.

unlocked >>> transfer nathan weiyang 10000  UNEST "here is the money" true
unlocked >>> list_account_balances weiyang                               
list_account_balances weiyang
10000 UNEST

unlocked >>> list_account_balances nathan                                
list_account_balances nathan
9999660937.51761 BTS
40000 UNEST

Reference

private test net
How to become an active witness
Become an active witness
PUBLIC TESTNET HOWTO
PRIVATE TESTNET HOWTO

上一篇 下一篇

猜你喜欢

热点阅读