Edit me

[TOC]

源码编译

首先下载源码:

$ go get github.com/ontio/ontology

然后使用glide下载依赖库,

获取
$ go get github.com/Masterminds/glide
进入目录
$ cd github.com/Masterminds/glide
编译
$ make build
$ go build -o glide -ldflags "-X main.version=v0.11.0" glide.go

glide可以根据版本自动下载对应的库:

pct@Chandler:~/go/src/github.com/ontio/ontology$ glide install
[INFO]    Lock file (glide.lock) does not exist. Performing update.
[INFO]    Downloading dependencies. Please wait...
[INFO]    --> Fetching github.com/dnaproject/gopass
[INFO]    --> Fetching github.com/bitly/go-simplejson
[INFO]    --> Fetching github.com/gorilla/websocket
[INFO]    --> Fetching github.com/itchyny/base58-go
[INFO]    --> Fetching github.com/syndtr/goleveldb
[INFO]    --> Fetching github.com/pborman/uuid
[INFO]    --> Fetching github.com/urfave/cli
[INFO]    --> Fetching github.com/orcaman/concurrent-map
[INFO]    --> Fetching github.com/whyrusleeping/tar-utils
[INFO]    --> Fetching golang.org/x/crypto
[INFO]    --> Fetching github.com/Workiva/go-datastructures
[INFO]    --> Fetching golang.org/x/text
[INFO]    --> Fetching github.com/AsynkronIT/goconsole
[INFO]    --> Fetching golang.org/x/sys
[INFO]    --> Fetching golang.org/x/net
[INFO]    --> Fetching google.golang.org/grpc
[INFO]    --> Fetching github.com/hashicorp/golang-lru
[INFO]    --> Fetching google.golang.org/genproto
[INFO]    --> Setting version for github.com/pborman/uuid to v1.1.
[INFO]    --> Setting version for github.com/gorilla/websocket to v1.2.0.
[INFO]    --> Setting version for github.com/bitly/go-simplejson to v0.5.0.
[INFO]    --> Setting version for github.com/urfave/cli to v1.20.0.
[INFO]    Resolving imports
[INFO]    --> Fetching github.com/golang/crypto
[INFO]    --> Fetching github.com/valyala/bytebufferpool
[INFO]    --> Fetching github.com/golang/snappy
[INFO]    --> Fetching github.com/stretchr/testify
[INFO]    --> Fetching github.com/davecgh/go-spew
[INFO]    --> Fetching github.com/pmezard/go-difflib
[INFO]    Downloading dependencies. Please wait...
[INFO]    Setting references for remaining imports
[INFO]    Exporting resolved dependencies...
[INFO]    --> Exporting github.com/bitly/go-simplejson
[INFO]    --> Exporting github.com/gorilla/websocket
[INFO]    --> Exporting github.com/dnaproject/gopass
[INFO]    --> Exporting github.com/itchyny/base58-go
[INFO]    --> Exporting github.com/pborman/uuid
[INFO]    --> Exporting github.com/syndtr/goleveldb
[INFO]    --> Exporting github.com/urfave/cli
[INFO]    --> Exporting github.com/orcaman/concurrent-map
[INFO]    --> Exporting github.com/whyrusleeping/tar-utils
[INFO]    --> Exporting golang.org/x/text
[INFO]    --> Exporting golang.org/x/crypto
[INFO]    --> Exporting github.com/Workiva/go-datastructures
[INFO]    --> Exporting github.com/AsynkronIT/goconsole
[INFO]    --> Exporting golang.org/x/sys
[INFO]    --> Exporting golang.org/x/net
[INFO]    --> Exporting google.golang.org/genproto
[INFO]    --> Exporting google.golang.org/grpc
[INFO]    --> Exporting github.com/hashicorp/golang-lru
[INFO]    --> Exporting github.com/golang/crypto
[INFO]    --> Exporting github.com/valyala/bytebufferpool
[INFO]    --> Exporting github.com/golang/snappy
[INFO]    --> Exporting github.com/stretchr/testify
[INFO]    --> Exporting github.com/davecgh/go-spew
[INFO]    --> Exporting github.com/pmezard/go-difflib
[INFO]    Replacing existing vendor dependencies
[INFO]    Project relies on 21 dependencies.

用到了21个外部库,还是蛮多的。最后编译:

pct@Chandler:~/go/src/github.com/ontio/ontology$ make
go build -ldflags "-X github.com/ontio/ontology/common/config.Version=1c40" -o ontology main.go
go build -ldflags "-X main.Version=1c40" nodectl.go

生成了两个可执行文件nodectl 及 ontology,根据Makefile的说明,编译出ontology的为: /home/pct/go/src/github.com/ontio/ontology/main.go 编译出nodectl的为: /home/pct/go/src/github.com/ontio/ontology/nodectl.go 后面dlv调试的时候需要用到。

测试运行

创建钱包

新建一个目录,然后将下面三个文件拷贝到目录中:

pct@Chandler:~/go/src/github.com/ontio/ontology/bulid$ ls
config.json  nodectl  ontology

然后运行命令创建钱包:

pct@Chandler:~/go/src/github.com/ontio/ontology/bulid$ ./nodectl wallet --create --name wallet.dat --password passwordtest
Wallet File: 'wallet.dat'
public key: 120203c2c5d70b63cd267eb950407dab02ed8e45191aa5d8ff104231c61552ce534b33
hex address: 016c20de206fe7464df36867499d342e8064d1cf
base58 address: TA6jD9FRLAGjQ569p47CMczVKbVTnxvsDj

这里没有生成私钥,可能是通过密码来管理私钥。 当前目录下会生成一些新的文件:

pct@Chandler:~/go/src/github.com/ontio/ontology/bulid$ tree
.
├── ActorLog
│   ├── 2018-04-16_11.05.19_LOG.log
│   └── 2018-04-16_11.05.37_LOG.log
├── config.json
├── Log
│   └── 2018-04-16_11.05.19_LOG.log
├── nodectl
├── ontology
└── wallet.dat

2 directories, 7 files

上面创建的钱包使用了默认的passwordtest作为密码,可以通过下面命令修改你自己想要的密码:

pct@Chandler:~/go/src/github.com/ontio/ontology/bulid$ ./nodectl wallet --changepassword 
Password:
Wallet File: 'wallet.dat'
# input new password #
Password:
Re-enter Password:
password changed

然后通过下面指令获取钱包信息:

pct@Chandler:~/go/src/github.com/ontio/ontology/bulid$ ./nodectl wallet --list account
Password:
Wallet File: 'wallet.dat'
public key:    120203c2c5d70b63cd267eb950407dab02ed8e45191aa5d8ff104231c61552ce534b33
hex address:  016c20de206fe7464df36867499d342e8064d1cf
base58 address:       TA6jD9FRLAGjQ569p47CMczVKbVTnxvsDj

这个账户就是我们上面创建的账户。

运行节点

先单机运行,看下运行的log情况,首先配置config文件:

{
  "Configuration": {
    "Magic": 7630401,
    "Version": 23,
    "SeedList": [
      "127.0.0.1:20338"
    ],
    "Bookkeepers": [
       "120203c2c5d70b63cd267eb950407dab02ed8e45191aa5d8ff104231c61552ce534b33"  //上面创建的钱包公钥
     ],
    "HttpRestPort": 20334,
    "HttpWsPort":20335,
    "HttpJsonPort": 20336,
    "HttpLocalPort": 20337,
    "NodePort": 20338,
    "NodeConsensusPort": 20389,
    "PrintLevel": 0, //打印出debug信息
    "IsTLS": false,
    "MaxTransactionInBlock": 50000,
    "MultiCoreNum": 4,
    "ConsensusType":"solo"
  }
}

启动:

pct@Chandler:~/go/src/github.com/ontio/ontology/bulid$ ./ontology 
2018/04/16 11:24:54.325269 [DEBUG] GID 1, main.init.0 main.go:66 The Core number is  4
2018/04/16 11:24:54.325327 [TRACE] GID 1, main() main.go:76 Node version:  1c40
2018/04/16 11:24:54.325339 [INFO ] GID 1, 0. Open the account
Password:
2018/04/16 11:24:58.275680 [DEBUG] GID 1, main.main main.go:93 The Node's PublicKey  &{0 0xc420190720}
2018/04/16 11:24:58.275874 [INFO ] GID 1, 1. Loading the Ledger
2018/04/16 11:24:59.001758 [INFO ] GID 1, InitCurrentBlock currentBlockHash 0000000000000000000000000000000000000000000000000000000000000000 currentBlockHeight 0

现在主体已经运行成功,然后看看客户端的互动操作。

nodectl

客户端只支持几个简单命令:

COMMANDS:
     test      run test routine
     transfer  user ont transfer
     wallet    user wallet operation
     help, h   Shows a list of commands or help for one command

nodectl test执行失败。 wallet我们上面测试过了,现在测试一下transfer转账命令:

pct@Chandler:~/go/src/github.com/ontio/ontology/bulid$ ./nodectl transfer --contract ff00000000000000000000000000000000000001 --value 10 --from 016c20de206fe7464df36867499d342e8064d1cf --to 016c20de206fe7464df36867499d342e8064d1cf --password pct
37bc7fbd8d0b9d73331176d8636ac1742736ab263a181d19ccd9e4b627c870ef

此时节点端就会收到这个转账请求:

2018/04/16 11:49:40.302188 [DEBUG] GID 2935, github.com/ontio/ontology/txnpool/proc.(*TxActor).Receive txnpool_actor.go:96 txpool-tx actor Receives tx from http sender
2018/04/16 11:49:40.302270 [DEBUG] GID 2937, github.com/ontio/ontology/validator/statefull.(*validator).Receive statefull_validator.go:66 statefull-validator: receive tx 37bc7fbd8d0b9d73331176d8636ac1742736ab263a181d19ccd9e4b627c870ef
2018/04/16 11:49:40.302303 [DEBUG] GID 2936, github.com/ontio/ontology/validator/stateless.(*validator).Receive stateless_validator.go:68 stateless-validator receive tx 37bc7fbd8d0b9d73331176d8636ac1742736ab263a181d19ccd9e4b627c870ef
2018/04/16 11:49:40.302332 [DEBUG] GID 2938, github.com/ontio/ontology/txnpool/proc.(*VerifyRspActor).Receive txnpool_actor.go:242 txpool-verify actor:: Receives verify rsp message
2018/04/16 11:49:40.302455 [DEBUG] GID 2965, github.com/ontio/ontology/txnpool/proc.(*VerifyRspActor).Receive txnpool_actor.go:242 txpool-verify actor:: Receives verify rsp message
2018/04/16 11:49:40.302503 [DEBUG] GID 2966, github.com/ontio/ontology/net/node.(*node).Xmit node.go:325
2018/04/16 11:49:40.302548 [DEBUG] GID 2966, github.com/ontio/ontology/net/node.(*node).Xmit node.go:331 TX transaction message
2018/04/16 11:49:40.302580 [DEBUG] GID 2966, github.com/ontio/ontology/net/message.NewTxn transaction.go:113
2018/04/16 11:49:40.302622 [DEBUG] GID 2966, github.com/ontio/ontology/net/message.NewTxn transaction.go:134 The message payload length is 209
2018/04/16 11:49:41.055140 [DEBUG] GID 2967, github.com/ontio/ontology/consensus/solo.(*SoloService).makeBlock solo.go:167
2018/04/16 11:49:41.055284 [INFO ] GID 2967, current block Height 246, incrValidateHeight 237
2018/04/16 11:49:41.055392 [DEBUG] GID 2968, github.com/ontio/ontology/txnpool/proc.(*TxPoolActor).Receive txnpool_actor.go:173 txpool actor Receives getting tx pool req from nonhost/future$ne
2018/04/16 11:49:41.055483 [DEBUG] GID 2967, github.com/ontio/ontology/consensus/solo.(*SoloService).createBookkeepingTransaction solo.go:249
2018/04/16 11:49:41.704559 [INFO ] GID 2967, solo actor receives block complete event. block height= 247
2018/04/16 11:49:41.704623 [DEBUG] GID 2954, github.com/ontio/ontology/txnpool/proc.(*TxPoolActor).Receive txnpool_actor.go:200 txpool actor Receives block complete event from nonhost/DefPublisherActor
2018/04/16 11:49:41.704766 [DEBUG] GID 2954, github.com/ontio/ontology/txnpool/common.(*TXPool).CleanTransactionList transaction_pool.go:101 [cleanTransactionList],transaction 1 Requested,1 cleaned, Remains 0 in TxPool

后面可以根据这个log进行账单代码的追踪。 如果我们发起一笔无效交易也是可以通过的,钱包这边并不会检测账单的合法性,节点那边应该会检测,后面再去看下代码。

pct@Chandler:~/go/src/github.com/ontio/ontology/bulid$ ./nodectl transfer --contract ff00000000000000000000000000000000000001 --value 10 --from 016c20de206fe7464df36867499d342e8064d1c1 --to 016c20de206fe7464df36867499d342e8064d1c2 --password pct
055c0251a8236fe216d7574f04dfbf109118783086b26d553bdeea6c63428a66

节点端对非法交易是有校验的:

2018/04/16 14:29:15.602054 [DEBUG] GID 131, github.com/ontio/ontology/txnpool/proc.(*TxPoolActor).Receive txnpool_actor.go:173 txpool actor Receives getting tx pool req from  nonhost/future$s
2018/04/16 14:29:15.602182 [DEBUG] GID 130, github.com/ontio/ontology/consensus/solo.(*SoloService).createBookkeepingTransaction solo.go:249
HandleInvokeTransaction tx 696a0c76d15ec5744840f41f39916fe96c7147a42ef1d7f0f98ddde48faf97f0 error [Invoke] Native serivce function execute error!: [Sender] Authentication failed!
Tags: