本測試嘗試用cosmos-sdk的最新版本在本地構(gòu)建一個兩個節(jié)點(fincoin和fabcoin)的區(qū)塊鏈(finfab-chain)沼瘫,并發(fā)行兩種通證,一個稱為FinCoin, 另外一個稱為FabCoin初烘。之后,進行一次FabCoin的交易师逸,從一個賬戶轉(zhuǎn)100個通證到另外一個賬戶津滞。
This test is an attempt to use the latest cosmos-sdk source to run a blockchain called (finfab-chain) with two nodes, fincoin node and fabcoin node. Then issue two tokens, FinCoin token and FabCoin token and transfer 100 FabCoin from one account to the other account.
系統(tǒng)準備 (system)
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.4 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
$ go version
go version go1.9.3 linux/amd64
$ echo $GOPATH
/opt/projects/go
下載源代碼并編譯 (download source and compile)
$ go get github.com/cosmos/cosmos-sdk
$ cd $GOPATH/src/github.com/cosmos/cosmos-sdk
$ make get_tools
cd tools && make get_tools
make[1]: Entering directory '/opt/projects/github.com/cosmos/cosmos-sdk/tools'
Dep is already installed. Run 'make update_tools' to update.
make[1]: Leaving directory '/opt/projects/github.com/cosmos/cosmos-sdk/tools'
$ make update_tools
cd tools && make update_tools
make[1]: Entering directory '/opt/projects/github.com/cosmos/cosmos-sdk/tools'
Updating dep
go get -u -v github.com/golang/dep/cmd/dep
github.com/golang/dep (download)
make[1]: Leaving directory '/opt/projects/github.com/cosmos/cosmos-sdk/tools'
$ make get_vendor_deps
--> Running dep ensure
Gopkg.lock was already in sync with imports and Gopkg.toml
(1/49) Wrote github.com/mattn/go-isatty@v0.0.3
(2/49) Wrote github.com/pkg/errors@v0.8.0
(3/49) Wrote github.com/pelletier/go-toml@v1.1.0
(4/49) Wrote gopkg.in/yaml.v2@v2.2.1
(5/49) Wrote github.com/gorilla/context@v1.1.1
(6/49) Wrote github.com/davecgh/go-spew@v1.1.0
(7/49) Wrote github.com/rcrowley/go-metrics@master
(8/49) Wrote github.com/mitchellh/mapstructure@master
(9/49) Wrote github.com/ebuchman/fail-test@master
(10/49) Wrote github.com/pmezard/go-difflib@v1.0.0
(11/49) Wrote github.com/fsnotify/fsnotify@v1.4.7
(12/49) Wrote github.com/bgentry/speakeasy@v0.1.0
(13/49) Wrote github.com/golang/snappy@master
(14/49) Wrote github.com/hashicorp/hcl@master
(15/49) Wrote github.com/gorilla/mux@v1.6.2
(16/49) Wrote github.com/go-logfmt/logfmt@v0.3.0
(17/49) Wrote github.com/go-kit/kit@v0.6.0
(18/49) Wrote github.com/spf13/afero@v1.1.0
(19/49) Wrote github.com/go-stack/stack@v1.7.0
(20/49) Wrote github.com/golang/protobuf@v1.0.0
(21/49) Wrote github.com/gorilla/websocket@v1.2.0
(22/49) Wrote github.com/spf13/cast@v1.2.0
(23/49) Wrote github.com/tendermint/go-crypto@v0.6.2
(24/49) Wrote github.com/tendermint/go-wire@v0.7.3
(25/49) Wrote github.com/spf13/cobra@v0.0.3
(26/49) Wrote github.com/tendermint/iavl@v0.7.0
(27/49) Wrote github.com/spf13/jwalterweatherman@master
(28/49) Wrote github.com/btcsuite/btcd@master
(29/49) Wrote github.com/tendermint/tmlibs@v0.8.3-rc0
(30/49) Wrote github.com/spf13/pflag@v1.0.1
(31/49) Wrote github.com/jmhodges/levigo@master
(32/49) Wrote github.com/howeyc/crc16@master
(33/49) Wrote github.com/syndtr/goleveldb@master
(34/49) Wrote github.com/inconshreveable/mousetrap@v1.0
(35/49) Wrote github.com/tendermint/abci@v0.10.3
(36/49) Wrote github.com/spf13/viper@v1.0.2
(37/49) Wrote golang.org/x/crypto@master
(38/49) Wrote github.com/kr/logfmt@master
(39/49) Wrote github.com/tendermint/tendermint@v0.19.5-rc1
(40/49) Wrote github.com/tendermint/ed25519@master
(41/49) Wrote github.com/stretchr/testify@v1.2.1
(42/49) Wrote github.com/magiconair/properties@v1.8.0
(43/49) Wrote github.com/tendermint/go-amino@0.9.9
(44/49) Wrote github.com/gogo/protobuf@v1.0.0
(45/49) Wrote google.golang.org/genproto@7fd901a49ba6a7f87732eb344f6e3c5b19d1b200
(46/49) Wrote google.golang.org/grpc@v1.7.5
(47/49) Wrote golang.org/x/net@master
(48/49) Wrote golang.org/x/text@v0.3.0
(49/49) Wrote golang.org/x/sys@master
$ make install
go install -ldflags "-X github.com/cosmos/cosmos-sdk/version.GitCommit=187be1a5" ./cmd/gaia/cmd/gaiad
go install -ldflags "-X github.com/cosmos/cosmos-sdk/version.GitCommit=187be1a5" ./cmd/gaia/cmd/gaiacli
Cosmos gaia
版本確認 (cosmos gaia
version check)
$ gaiad version
0.17.2-187be1a5
$ gaiacli version
0.17.2-187be1a5
創(chuàng)世紀設(shè)定 (genesis configuration)
$ gaiad init gen-tx --name=fincoin --home=/opt/data/cosmos/fincoin
{
"app_message": {
"secret": "inner space weird carry near high moral slot hero drum smart satoshi boat vital assault abandon"
},
"gen_tx_file": {
"node_id": "c519ca2cc2257eb62a95a61c45268ade1ee35d59",
"ip": "172.x.x.x",
"validator": {
"pub_key": {
"type": "AC26791624DE60",
"value": "hNwHCN3J/FSa5nCJDgikkSh3znhv9ZrRZUU+kkvw1Uc="
},
"power": 100,
"name": ""
},
"app_gen_tx": {
"name": "fincoin",
"address": "3A8E0270F2D5D6128DC4C77B5656C0ADB5379C11",
"pub_key": {
"type": "AC26791624DE60",
"value": "hNwHCN3J/FSa5nCJDgikkSh3znhv9ZrRZUU+kkvw1Uc="
}
}
}
}
$ gaiad init gen-tx --name=fabcoin --home=/opt/data/cosmos/fabcoin
{
"app_message": {
"secret": "mushroom practice juice burst expire scorpion frozen clay catalog erosion draft bulk blush rug arrive abandon"
},
"gen_tx_file": {
"node_id": "fc93204300fedd2076d9ec82bf7be589b30ec923",
"ip": "172.x.x.x",
"validator": {
"pub_key": {
"type": "AC26791624DE60",
"value": "R3l0Y86zKYhaKnqliVu/sQInGUiYB/8AXNbp1hAsE7k="
},
"power": 100,
"name": ""
},
"app_gen_tx": {
"name": "fabcoin",
"address": "FB983823EC3A541193E61DBF1DAF8CFF4C90F02E",
"pub_key": {
"type": "AC26791624DE60",
"value": "R3l0Y86zKYhaKnqliVu/sQInGUiYB/8AXNbp1hAsE7k="
}
}
}
}
$ gaiacli keys list
NAME: ADDRESS: PUBKEY:
fabcoin FB983823EC3A541193E61DBF1DAF8CFF4C90F02E 1624DE6220C6EEE1CCD437A5214499631559379D64023B1C83EA56DCE03EA64076303CEDDD
fincoin 3A8E0270F2D5D6128DC4C77B5656C0ADB5379C11 1624DE6220E82D7F4126AC9881C9C06A3EB33A293926DC15F4EE1B59EAD9339546F8ACB237
更改設(shè)定文件 (modify config files)
因為我們要在本地跑兩個節(jié)點,所以缺省的設(shè)定會有端口沖突锌唾,因此需要更改其中一個節(jié)點的設(shè)定锄码。
Because we will be running two nodes on the local machine, in order to avoid port conflicts, we will change the port settings for one node.
- 端口設(shè)定更改 (change ports)
$ cd /opt/data/cosmos/fabcoin/config
$ cp config.toml config.toml.orig
$ cat config.toml.orig | sed -e 's/466/467/g' > config.toml
$ diff config.toml config.toml.orig
8c8
< proxy_app = "tcp://127.0.0.1:46758"
---
> proxy_app = "tcp://127.0.0.1:46658"
54c54
< laddr = "tcp://0.0.0.0:46757"
---
> laddr = "tcp://0.0.0.0:46657"
67c67
< laddr = "tcp://0.0.0.0:46756"
---
> laddr = "tcp://0.0.0.0:46656"
- 更改fabcoin節(jié)點的名稱(編輯
/opt/data/cosmos/fabcoin/config/config.toml
文件) (change default node name in file /opt/data/cosmos/fabcoin/config/config.toml)
# A custom human readable name for this node
moniker = "fabnode"
- 更改fincoin節(jié)點的名稱(編輯
/opt/data/cosmos/fincoin/config/config.toml
文件) (change default node name in file /opt/data/cosmos/fincoin/config/config.toml)
# A custom human readable name for this node
moniker = "finnode"
在finfab-chain
區(qū)塊鏈上初始創(chuàng)世紀交易 (initiate genesis transactions on the finfab-chain
blockchain)
$ cd /opt/data/cosmos
$ cp -a fabcoin/config/gentx/. fincoin/config/gentx/
$ cp -a fincoin/config/gentx/. fabcoin/config/gentx/
$ gaiad init --gen-txs --home=/opt/data/cosmos/fabcoin --chain-id=finfab-chain
{
"chain_id": "finfab-chain",
"node_id": "fc93204300fedd2076d9ec82bf7be589b30ec923",
"app_message": null
}
$ gaiad init --gen-txs --home=/opt/data/cosmos/fincoin --chain-id=finfab-chain
{
"chain_id": "finfab-chain",
"node_id": "c519ca2cc2257eb62a95a61c45268ade1ee35d59",
"app_message": null
}
運行節(jié)點 (run the blockchain nodes)
可以用兩種方式跑節(jié)點,一種直接從IDE里啟動晌涕,再者就是從命令行滋捶。
There are two ways we can run the nodes, either from the IDE or from the command line.
-
IDE (GoLand) 啟動 (run from GoLand IDE)
命令行 (run from command line)
$ gaiad start --home=/opt/data/cosmos/fabcoin
$ gaiad start --home=/opt/data/cosmos/fincoin
賬戶確認 (verify accounts)
fabcoin賬戶擁有1000個fabcoinToken
,fincoin賬戶擁有1000個fincoinToken
余黎。
fabcoin account has 1000
fabcoinToken
重窟,fincoin account has 1000fincoinToken
。
$ gaiacli validatorset
{"block_height":17,"validators":[{"address":"6084207D042C1B35C631A279F2B3AA9DE404CD83","pub_key":{"type":"AC26791624DE60","value":"hNwHCN3J/FSa5nCJDgikkSh3znhv9ZrRZUU+kkvw1Uc="},"voting_power":100,"accum":-100},{"address":"D7F2FD3FC1535920EC695125613F08C53C569C7A","pub_key":{"type":"AC26791624DE60","value":"R3l0Y86zKYhaKnqliVu/sQInGUiYB/8AXNbp1hAsE7k="},"voting_power":100,"accum":100}]}
$ gaiacli keys list
NAME: ADDRESS: PUBKEY:
fabcoin FB983823EC3A541193E61DBF1DAF8CFF4C90F02E 1624DE6220C6EEE1CCD437A5214499631559379D64023B1C83EA56DCE03EA64076303CEDDD
fincoin 3A8E0270F2D5D6128DC4C77B5656C0ADB5379C11 1624DE6220E82D7F4126AC9881C9C06A3EB33A293926DC15F4EE1B59EAD9339546F8ACB237
$ gaiacli account FB983823EC3A541193E61DBF1DAF8CFF4C90F02E
{
"type": "6C54F73C9F2E08",
"value": {
"address": "FB983823EC3A541193E61DBF1DAF8CFF4C90F02E",
"coins": [
{
"denom": "fabcoinToken",
"amount": 1000
},
{
"denom": "steak",
"amount": 50
}
],
"public_key": null,
"sequence": 0
}
}
$ gaiacli account 3A8E0270F2D5D6128DC4C77B5656C0ADB5379C11
{
"type": "6C54F73C9F2E08",
"value": {
"address": "3A8E0270F2D5D6128DC4C77B5656C0ADB5379C11",
"coins": [
{
"denom": "fincoinToken",
"amount": 1000
},
{
"denom": "steak",
"amount": 50
}
],
"public_key": null,
"sequence": 0
}
}
通證交易 (token transfer)
- 從fabcoin轉(zhuǎn)100個通證給fincoin (默認的賬戶密碼是
1234567890
) (100 tokens transferred from fabcoin account to fincoin account, default password is1234567890
)
$ gaiacli send --amount=100fabcoinToken --to=3A8E0270F2D5D6128DC4C77B5656C0ADB5379C11 --name=fabcoin --chain-id=finfab-chain
Defaulting to next sequence number: 0
Password to sign with 'fabcoin':
Committed at block 339. Hash: 2F169D62F07FCF2EBDF33AA95599178BFC43D83C
- 交易確認 (transaction confirmation)
$ gaiacli account FB983823EC3A541193E61DBF1DAF8CFF4C90F02E
{
"type": "6C54F73C9F2E08",
"value": {
"address": "FB983823EC3A541193E61DBF1DAF8CFF4C90F02E",
"coins": [
{
"denom": "fabcoinToken",
"amount": 900
},
{
"denom": "steak",
"amount": 50
}
],
"public_key": {
"type": "AC26791624DE60",
"value": "xu7hzNQ3pSFEmWMVWTedZAI7HIPqVtzgPqZAdjA87d0="
},
"sequence": 1
}
}
$ gaiacli account 3A8E0270F2D5D6128DC4C77B5656C0ADB5379C11
{
"type": "6C54F73C9F2E08",
"value": {
"address": "3A8E0270F2D5D6128DC4C77B5656C0ADB5379C11",
"coins": [
{
"denom": "fabcoinToken",
"amount": 100
},
{
"denom": "fincoinToken",
"amount": 1000
},
{
"denom": "steak",
"amount": 50
}
],
"public_key": null,
"sequence": 0
}
}
fabcoin賬戶擁有900個fabcoinToken
惧财,fincoin賬戶擁有100個fabcoinToken
和1000個fincoinToken
巡扇。
Now fabcoin account has 900
fabcoinToken
,fincoin account has 100fabcoinToken
and 1000fincoinToken
垮衷。
參考 (Reference)
http://cosmos-sdk.readthedocs.io/en/develop/index.html
https://github.com/cosmos/testnets