Skip to content

Commit 6bf90a5

Browse files
author
Qi Xiao
committed
Fix bin/cql -web and -dsn flag interference
1 parent 9ab6bc0 commit 6bf90a5

5 files changed

Lines changed: 16 additions & 20 deletions

File tree

cmd/cql-observer/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ func main() {
7777
}
7878
kms.InitBP()
7979

80+
if err = initNode(); err != nil {
81+
return
82+
}
83+
8084
service, httpServer, err := observer.StartObserver(listenAddr, version)
8185
if err != nil {
8286
log.WithError(err).Fatal("start observer failed")
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 The CovenantSQL Authors.
2+
* Copyright 2019 The CovenantSQL Authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package observer
17+
package main
1818

1919
import (
2020
"fmt"

cmd/cql/main.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,14 @@ func main() {
292292

293293
configFile = utils.HomeDirExpand(configFile)
294294

295-
if explorerAddr != "" {
296-
var err error
297-
conf.GConf, err = conf.LoadConfig(configFile)
298-
if err != nil {
299-
log.WithField("config", configFile).WithError(err).Fatal("load config failed")
300-
}
295+
// init covenantsql driver
296+
if err = client.Init(configFile, []byte(password)); err != nil {
297+
cLog.WithError(err).Error("init covenantsql client failed")
298+
os.Exit(-1)
299+
return
300+
}
301301

302+
if explorerAddr != "" {
302303
service, httpServer, err = observer.StartObserver(explorerAddr, version)
303304
if err != nil {
304305
log.WithError(err).Fatal("start explorer failed")
@@ -312,13 +313,6 @@ func main() {
312313
_ = observer.StopObserver(service, httpServer)
313314
log.Info("explorer stopped")
314315
}()
315-
} else {
316-
// init covenantsql driver
317-
if err = client.Init(configFile, []byte(password)); err != nil {
318-
cLog.WithError(err).Error("init covenantsql client failed")
319-
os.Exit(-1)
320-
return
321-
}
322316
}
323317

324318
// TODO(leventeliu): discover more specific confirmation duration from config. We don't have

sqlchain/observer/observer.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ func stopService(service *Service) (err error) {
6363

6464
// StartObserver starts the observer service and http API server.
6565
func StartObserver(listenAddr string, version string) (service *Service, httpServer *http.Server, err error) {
66-
// init node
67-
if err = initNode(); err != nil {
68-
log.WithError(err).Fatal("init node failed")
69-
}
70-
7166
// start service
7267
if service, err = startService(); err != nil {
7368
log.WithError(err).Fatal("start observation failed")

sqlchain/observer/service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ func (s *Service) addBlock(dbID proto.DatabaseID, count int32, b *types.Block) (
309309
if err != nil {
310310
return
311311
}
312+
if b == nil {
313+
return
314+
}
312315

313316
h := int32(b.Timestamp().Sub(instance.GenesisBlock.Timestamp()) / conf.GConf.SQLChainPeriod)
314317
key := utils.ConcatAll(int32ToBytes(h), b.BlockHash().AsBytes(), int32ToBytes(count))

0 commit comments

Comments
 (0)