2017-06-29 01:18:28 -07:00
|
|
|
<!--- shelldown script template, see github.com/rigelrozanski/shelldown
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
testTutorial_BasecoinTool() {
|
|
|
|
|
|
|
|
rm -rf ~/.basecoin
|
|
|
|
rm -rf ~/.basecli
|
|
|
|
rm -rf example-data
|
|
|
|
KEYPASS=qwertyuiop
|
|
|
|
|
|
|
|
(echo $KEYPASS; echo $KEYPASS) | #shelldown[0][0] >/dev/null ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
#shelldown[0][1] >/dev/null ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
#shelldown[1][0] ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
#shelldown[1][1] ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
|
|
|
|
#shelldown[1][2] >>/dev/null 2>&1 &
|
|
|
|
sleep 5 ; PID_SERVER=$! ; disown ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
kill -9 $PID_SERVER >/dev/null 2>&1 ; sleep 1
|
|
|
|
|
|
|
|
#shelldown[2][0] ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
#shelldown[2][1] >>/dev/null 2>&1 &
|
|
|
|
sleep 5 ; PID_SERVER=$! ; disown ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
kill -9 $PID_SERVER >/dev/null 2>&1 ; sleep 1
|
|
|
|
|
|
|
|
#shelldown[3][-1] >/dev/null ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
|
|
|
|
#shelldown[4][-1] >>/dev/null 2>&1 &
|
|
|
|
sleep 5 ; PID_SERVER=$! ; disown ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
#shelldown[5][-1] >>/dev/null 2>&1 &
|
|
|
|
sleep 5 ; PID_SERVER2=$! ; disown ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
kill -9 $PID_SERVER $PID_SERVER2 >/dev/null 2>&1 ; sleep 1
|
|
|
|
|
|
|
|
#shelldown[4][-1] >>/dev/null 2>&1 &
|
|
|
|
sleep 5 ; PID_SERVER=$! ; disown ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
#shelldown[6][0] ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
#shelldown[6][1] >>/dev/null 2>&1 &
|
|
|
|
sleep 5 ; PID_SERVER2=$! ; disown ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
kill -9 $PID_SERVER $PID_SERVER2 >/dev/null 2>&1 ; sleep 1
|
|
|
|
|
|
|
|
#shelldown[7][-1] >/dev/null ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
#shelldown[8][-1] >/dev/null ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
(echo $KEYPASS; echo $KEYPASS) | #shelldown[9][-1] >/dev/null ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
#shelldown[10][-1] >/dev/null ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
#shelldown[11][-1] >/dev/null ; assertTrue "Expected true for line $LINENO" $?
|
|
|
|
|
|
|
|
#cleanup
|
|
|
|
rm -rf example-data
|
|
|
|
}
|
|
|
|
|
|
|
|
# load and run these tests with shunit2!
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
|
|
|
|
. $DIR/shunit2
|
|
|
|
-->
|
|
|
|
|
2017-03-13 17:20:07 -07:00
|
|
|
# The Basecoin Tool
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
In previous tutorials we learned the [basics of the Basecoin
|
|
|
|
CLI](/docs/guide/basecoin-basics.md) and [how to implement a
|
|
|
|
plugin](/docs/guide/basecoin-plugins.md). In this tutorial, we provide more
|
|
|
|
details on using the Basecoin tool.
|
2017-03-13 17:20:07 -07:00
|
|
|
|
2017-06-20 21:38:54 -07:00
|
|
|
# Generate a Key
|
|
|
|
|
|
|
|
Generate a key using the `basecli` tool:
|
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[0]
|
2017-06-20 21:38:54 -07:00
|
|
|
basecli keys new mykey
|
|
|
|
ME=$(basecli keys get mykey | awk '{print $2}')
|
|
|
|
```
|
|
|
|
|
2017-03-14 11:29:12 -07:00
|
|
|
# Data Directory
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
By default, `basecoin` works out of `~/.basecoin`. To change this, set the
|
|
|
|
`BCHOME` environment variable:
|
2017-03-14 11:29:12 -07:00
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[1]
|
2017-03-14 11:29:12 -07:00
|
|
|
export BCHOME=~/.my_basecoin_data
|
2017-06-20 21:38:54 -07:00
|
|
|
basecoin init $ME
|
2017-03-14 11:29:12 -07:00
|
|
|
basecoin start
|
|
|
|
```
|
|
|
|
|
2017-05-23 06:00:02 -07:00
|
|
|
or
|
2017-03-14 11:29:12 -07:00
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[2]
|
2017-06-20 21:38:54 -07:00
|
|
|
BCHOME=~/.my_basecoin_data basecoin init $ME
|
2017-03-14 11:29:12 -07:00
|
|
|
BCHOME=~/.my_basecoin_data basecoin start
|
|
|
|
```
|
|
|
|
|
2017-03-13 17:20:07 -07:00
|
|
|
# ABCI Server
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
So far we have run Basecoin and Tendermint in a single process. However, since
|
|
|
|
we use ABCI, we can actually run them in different processes. First,
|
|
|
|
initialize them:
|
2017-03-13 17:20:07 -07:00
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[3]
|
2017-06-20 21:38:54 -07:00
|
|
|
basecoin init $ME
|
2017-03-13 17:20:07 -07:00
|
|
|
```
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
This will create a single `genesis.json` file in `~/.basecoin` with the
|
|
|
|
information for both Basecoin and Tendermint.
|
2017-03-14 11:29:12 -07:00
|
|
|
|
2017-05-23 06:00:02 -07:00
|
|
|
Now, In one window, run
|
2017-03-13 17:20:07 -07:00
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[4]
|
2017-03-13 22:47:10 -07:00
|
|
|
basecoin start --without-tendermint
|
2017-03-13 17:20:07 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
and in another,
|
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[5]
|
2017-03-14 11:29:12 -07:00
|
|
|
TMROOT=~/.basecoin tendermint node
|
2017-03-13 17:20:07 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
You should see Tendermint start making blocks!
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
Alternatively, you could ignore the Tendermint details in
|
|
|
|
`~/.basecoin/genesis.json` and use a separate directory by running:
|
2017-03-14 11:29:12 -07:00
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[6]
|
2017-03-14 11:29:12 -07:00
|
|
|
tendermint init
|
|
|
|
tendermint node
|
|
|
|
```
|
|
|
|
|
|
|
|
For more details on using `tendermint`, see [the guide](https://tendermint.com/docs/guides/using-tendermint).
|
2017-03-13 17:20:07 -07:00
|
|
|
|
|
|
|
# Keys and Genesis
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
In previous tutorials we used `basecoin init` to initialize `~/.basecoin` with
|
|
|
|
the default configuration. This command creates files both for Tendermint and
|
|
|
|
for Basecoin, and a single `genesis.json` file for both of them. For more
|
|
|
|
information on these files, see the [guide to using
|
|
|
|
Tendermint](https://tendermint.com/docs/guides/using-tendermint).
|
2017-03-13 17:20:07 -07:00
|
|
|
|
|
|
|
Now let's make our own custom Basecoin data.
|
|
|
|
|
|
|
|
First, create a new directory:
|
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[7]
|
2017-03-13 17:20:07 -07:00
|
|
|
mkdir example-data
|
|
|
|
```
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
We can tell `basecoin` to use this directory by exporting the `BCHOME`
|
|
|
|
environment variable:
|
2017-03-13 17:20:07 -07:00
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[8]
|
2017-03-13 22:50:10 -07:00
|
|
|
export BCHOME=$(pwd)/example-data
|
2017-03-13 17:20:07 -07:00
|
|
|
```
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
If you're going to be using multiple terminal windows, make sure to add this
|
|
|
|
variable to your shell startup scripts (eg. `~/.bashrc`).
|
2017-03-13 17:20:07 -07:00
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
Now, let's create a new key:
|
2017-03-13 17:20:07 -07:00
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[9]
|
2017-06-18 16:01:54 -07:00
|
|
|
basecli keys new foobar
|
2017-03-13 17:20:07 -07:00
|
|
|
```
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
The key's info can be retrieved with
|
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[10]
|
2017-06-18 16:01:54 -07:00
|
|
|
basecli keys get foobar -o=json
|
|
|
|
```
|
|
|
|
|
|
|
|
You should get output which looks similar to the following:
|
2017-03-13 17:20:07 -07:00
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
2017-06-18 16:01:54 -07:00
|
|
|
"name": "foobar",
|
|
|
|
"address": "404C5003A703C7DA888C96A2E901FCE65A6869D9",
|
|
|
|
"pubkey": {
|
|
|
|
"type": "ed25519",
|
|
|
|
"data": "8786B7812AB3B27892D8E14505EEFDBB609699E936F6A4871B1983F210736EEA"
|
|
|
|
}
|
2017-03-13 17:20:07 -07:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
Yours will look different - each key is randomly derived. Now we can make a
|
|
|
|
`genesis.json` file and add an account with our public key:
|
2017-03-13 17:20:07 -07:00
|
|
|
|
|
|
|
```json
|
2017-03-14 11:29:12 -07:00
|
|
|
{
|
2017-06-18 16:01:54 -07:00
|
|
|
"app_hash": "",
|
2017-03-14 11:29:12 -07:00
|
|
|
"chain_id": "example-chain",
|
2017-06-18 16:01:54 -07:00
|
|
|
"genesis_time": "0001-01-01T00:00:00.000Z",
|
|
|
|
"validators": [
|
|
|
|
{
|
|
|
|
"amount": 10,
|
|
|
|
"name": "",
|
2017-03-14 11:29:12 -07:00
|
|
|
"pub_key": {
|
|
|
|
"type": "ed25519",
|
2017-06-18 16:01:54 -07:00
|
|
|
"data": "7B90EA87E7DC0C7145C8C48C08992BE271C7234134343E8A8E8008E617DE7B30"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"app_options": {
|
|
|
|
"accounts": [
|
|
|
|
{
|
|
|
|
"pub_key": {
|
|
|
|
"type": "ed25519",
|
|
|
|
"data": "8786B7812AB3B27892D8E14505EEFDBB609699E936F6A4871B1983F210736EEA"
|
|
|
|
},
|
|
|
|
"coins": [
|
|
|
|
{
|
|
|
|
"denom": "gold",
|
|
|
|
"amount": 1000000000
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
2017-03-13 17:20:07 -07:00
|
|
|
}
|
2017-03-14 11:29:12 -07:00
|
|
|
}
|
2017-03-13 17:20:07 -07:00
|
|
|
```
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
Here we've granted ourselves `1000000000` units of the `gold` token. Note that
|
|
|
|
we've also set the `chain-id` to be `example-chain`. All transactions must
|
|
|
|
therefore include the `--chain-id example-chain` in order to make sure they are
|
|
|
|
valid for this chain. Previously, we didn't need this flag because we were
|
|
|
|
using the default chain ID ("test_chain_id"). Now that we're using a custom
|
|
|
|
chain, we need to specify the chain explicitly on the command line.
|
2017-03-13 17:20:07 -07:00
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
Note we have also left out the details of the Tendermint genesis. These are
|
|
|
|
documented in the [Tendermint
|
|
|
|
guide](https://tendermint.com/docs/guides/using-tendermint).
|
2017-03-14 11:29:12 -07:00
|
|
|
|
2017-03-13 17:20:07 -07:00
|
|
|
|
|
|
|
# Reset
|
|
|
|
|
|
|
|
You can reset all blockchain data by running:
|
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[11]
|
2017-03-13 17:20:07 -07:00
|
|
|
basecoin unsafe_reset_all
|
|
|
|
```
|
2017-04-26 21:51:44 -07:00
|
|
|
|
2017-06-20 21:38:54 -07:00
|
|
|
Similarly, you can reset client data by running:
|
2017-06-18 16:01:54 -07:00
|
|
|
|
2017-06-29 01:18:28 -07:00
|
|
|
```shelldown[12]
|
2017-06-18 16:01:54 -07:00
|
|
|
basecli reset_all
|
|
|
|
```
|
2017-04-26 21:51:44 -07:00
|
|
|
|
|
|
|
# Genesis
|
|
|
|
|
2017-06-18 16:01:54 -07:00
|
|
|
Any required plugin initialization should be constructed using `SetOption` on
|
|
|
|
genesis. When starting a new chain for the first time, `SetOption` will be
|
|
|
|
called for each item the genesis file. Within genesis.json file entries are
|
|
|
|
made in the format: `"<plugin>/<key>", "<value>"`, where `<plugin>` is the
|
|
|
|
plugin name, and `<key>` and `<value>` are the strings passed into the plugin
|
|
|
|
SetOption function. This function is intended to be used to set plugin
|
|
|
|
specific information such as the plugin state.
|
2017-04-26 21:51:44 -07:00
|
|
|
|