Merge pull request #54 from roylee17/lint

Lint
This commit is contained in:
Jae Kwon 2017-01-23 20:23:14 -08:00 committed by GitHub
commit a33b75fe8b
21 changed files with 160 additions and 162 deletions

View File

@ -5,11 +5,11 @@ import (
"sync"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
type Client interface {
Service
common.Service
SetResponseCallback(Callback)
Error() error

View File

@ -1,6 +1,7 @@
package abcicli
import (
"fmt"
"net"
"sync"
"time"
@ -9,13 +10,13 @@ import (
grpc "google.golang.org/grpc"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
// A stripped copy of the remoteClient that makes
// synchronous calls using grpc
type grpcClient struct {
BaseService
common.BaseService
mustConnect bool
client types.ABCIApplicationClient
@ -31,13 +32,13 @@ func NewGRPCClient(addr string, mustConnect bool) (*grpcClient, error) {
addr: addr,
mustConnect: mustConnect,
}
cli.BaseService = *NewBaseService(nil, "grpcClient", cli)
cli.BaseService = *common.NewBaseService(nil, "grpcClient", cli)
_, err := cli.Start() // Just start it, it's confusing for callers to remember to start.
return cli, err
}
func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) {
return Connect(addr)
return common.Connect(addr)
}
func (cli *grpcClient) OnStart() error {
@ -49,11 +50,10 @@ RETRY_LOOP:
if err != nil {
if cli.mustConnect {
return err
} else {
log.Warn(Fmt("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr))
time.Sleep(time.Second * 3)
continue RETRY_LOOP
}
log.Warn(fmt.Sprintf("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr))
time.Sleep(time.Second * 3)
continue RETRY_LOOP
}
client := types.NewABCIApplicationClient(conn)
@ -93,7 +93,7 @@ func (cli *grpcClient) StopForError(err error) {
}
cli.mtx.Unlock()
log.Warn(Fmt("Stopping abci.grpcClient for error: %v", err.Error()))
log.Warn(fmt.Sprintf("Stopping abci.grpcClient for error: %v", err.Error()))
cli.Stop()
}
@ -267,11 +267,10 @@ func (cli *grpcClient) InfoSync() (resInfo types.ResponseInfo, err error) {
if err = cli.Error(); err != nil {
return resInfo, err
}
if resInfo_ := reqres.Response.GetInfo(); resInfo_ != nil {
return *resInfo_, nil
} else {
return resInfo, nil
if info := reqres.Response.GetInfo(); info != nil {
return *info, nil
}
return resInfo, nil
}
func (cli *grpcClient) SetOptionSync(key string, value string) (res types.Result) {
@ -334,9 +333,8 @@ func (cli *grpcClient) EndBlockSync(height uint64) (resEndBlock types.ResponseEn
if err := cli.Error(); err != nil {
return resEndBlock, err
}
if resEndBlock_ := reqres.Response.GetEndBlock(); resEndBlock_ != nil {
return *resEndBlock_, nil
} else {
return resEndBlock, nil
if blk := reqres.Response.GetEndBlock(); blk != nil {
return *blk, nil
}
return resEndBlock, nil
}

View File

@ -4,11 +4,11 @@ import (
"sync"
types "github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
type localClient struct {
BaseService
common.BaseService
mtx *sync.Mutex
types.Application
Callback
@ -22,7 +22,7 @@ func NewLocalClient(mtx *sync.Mutex, app types.Application) *localClient {
mtx: mtx,
Application: app,
}
cli.BaseService = *NewBaseService(log, "localClient", cli)
cli.BaseService = *common.NewBaseService(log, "localClient", cli)
return cli
}

View File

@ -11,7 +11,7 @@ import (
"time"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
const (
@ -27,10 +27,10 @@ const flushThrottleMS = 20 // Don't wait longer than...
// the application in general is not meant to be interfaced
// with concurrent callers.
type socketClient struct {
BaseService
common.BaseService
reqQueue chan *ReqRes
flushTimer *ThrottleTimer
flushTimer *common.ThrottleTimer
mustConnect bool
mtx sync.Mutex
@ -45,14 +45,14 @@ type socketClient struct {
func NewSocketClient(addr string, mustConnect bool) (*socketClient, error) {
cli := &socketClient{
reqQueue: make(chan *ReqRes, reqQueueSize),
flushTimer: NewThrottleTimer("socketClient", flushThrottleMS),
flushTimer: common.NewThrottleTimer("socketClient", flushThrottleMS),
mustConnect: mustConnect,
addr: addr,
reqSent: list.New(),
resCb: nil,
}
cli.BaseService = *NewBaseService(nil, "socketClient", cli)
cli.BaseService = *common.NewBaseService(nil, "socketClient", cli)
_, err := cli.Start() // Just start it, it's confusing for callers to remember to start.
return cli, err
@ -65,15 +65,14 @@ func (cli *socketClient) OnStart() error {
var conn net.Conn
RETRY_LOOP:
for {
conn, err = Connect(cli.addr)
conn, err = common.Connect(cli.addr)
if err != nil {
if cli.mustConnect {
return err
} else {
log.Warn(Fmt("abci.socketClient failed to connect to %v. Retrying...", cli.addr))
time.Sleep(time.Second * 3)
continue RETRY_LOOP
}
log.Warn(fmt.Sprintf("abci.socketClient failed to connect to %v. Retrying...", cli.addr))
time.Sleep(time.Second * 3)
continue RETRY_LOOP
}
cli.conn = conn
@ -82,7 +81,6 @@ RETRY_LOOP:
return nil
}
return nil // never happens
}
func (cli *socketClient) OnStop() {
@ -109,7 +107,7 @@ func (cli *socketClient) StopForError(err error) {
}
cli.mtx.Unlock()
log.Warn(Fmt("Stopping abci.socketClient for error: %v", err.Error()))
log.Warn(fmt.Sprintf("Stopping abci.socketClient for error: %v", err.Error()))
cli.Stop()
}
@ -298,11 +296,10 @@ func (cli *socketClient) InfoSync() (resInfo types.ResponseInfo, err error) {
if err := cli.Error(); err != nil {
return resInfo, err
}
if resInfo_ := reqres.Response.GetInfo(); resInfo_ != nil {
return *resInfo_, nil
} else {
return resInfo, nil
if info := reqres.Response.GetInfo(); info != nil {
return *info, nil
}
return resInfo, nil
}
func (cli *socketClient) SetOptionSync(key string, value string) (res types.Result) {
@ -379,11 +376,10 @@ func (cli *socketClient) EndBlockSync(height uint64) (resEndBlock types.Response
if err := cli.Error(); err != nil {
return resEndBlock, err
}
if resEndBlock_ := reqres.Response.GetEndBlock(); resEndBlock_ != nil {
return *resEndBlock_, nil
} else {
return resEndBlock, nil
if blk := reqres.Response.GetEndBlock(); blk != nil {
return *blk, nil
}
return resEndBlock, nil
}
//----------------------------------------

View File

@ -6,12 +6,12 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"strings"
"github.com/tendermint/abci/client"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
"github.com/urfave/cli"
)
@ -135,7 +135,7 @@ func main() {
app.Before = before
err := app.Run(os.Args)
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
}
@ -145,7 +145,7 @@ func before(c *cli.Context) error {
var err error
client, err = abcicli.NewClient(c.GlobalString("address"), c.GlobalString("abci"), false)
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
}
return nil
@ -244,7 +244,7 @@ func cmdSetOption(c *cli.Context) error {
return errors.New("Command set_option takes 2 arguments (key, value)")
}
res := client.SetOptionSync(args[0], args[1])
rsp := newResponse(res, Fmt("%s=%s", args[0], args[1]), false)
rsp := newResponse(res, fmt.Sprintf("%s=%s", args[0], args[1]), false)
printResponse(c, rsp)
return nil
}
@ -284,7 +284,7 @@ func cmdCheckTx(c *cli.Context) error {
// Get application Merkle root hash
func cmdCommit(c *cli.Context) error {
res := client.CommitSync()
rsp := newResponse(res, Fmt("0x%X", res.Data), false)
rsp := newResponse(res, fmt.Sprintf("0x%X", res.Data), false)
printResponse(c, rsp)
return nil
}

View File

@ -2,10 +2,11 @@ package main
import (
"flag"
"log"
"github.com/tendermint/abci/example/counter"
"github.com/tendermint/abci/server"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
func main() {
@ -19,11 +20,11 @@ func main() {
// Start the listener
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
// Wait forever
TrapSignal(func() {
common.TrapSignal(func() {
// Cleanup
srv.Stop()
})

View File

@ -2,11 +2,12 @@ package main
import (
"flag"
"log"
"github.com/tendermint/abci/example/dummy"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
func main() {
@ -27,11 +28,11 @@ func main() {
// Start the listener
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
// Wait forever
TrapSignal(func() {
common.TrapSignal(func() {
// Cleanup
srv.Stop()
})

View File

@ -2,10 +2,12 @@ package main
import (
"flag"
"fmt"
"log"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
func main() {
@ -17,11 +19,11 @@ func main() {
// Start the listener
srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication())
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
// Wait forever
TrapSignal(func() {
common.TrapSignal(func() {
// Cleanup
srv.Stop()
})
@ -58,16 +60,16 @@ func (app *ChainAwareApplication) Commit() types.Result {
}
func (app *ChainAwareApplication) Query(query []byte) types.Result {
return types.NewResultOK([]byte(Fmt("%d,%d", app.beginCount, app.endCount)), "")
return types.NewResultOK([]byte(fmt.Sprintf("%d,%d", app.beginCount, app.endCount)), "")
}
func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {
app.beginCount += 1
app.beginCount++
return
}
func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) {
app.endCount += 1
app.endCount++
return
}

View File

@ -1,6 +1,8 @@
package main
import (
"fmt"
"log"
"strconv"
"strings"
"testing"
@ -8,7 +10,6 @@ import (
"github.com/tendermint/abci/client"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
)
func TestChainAware(t *testing.T) {
@ -25,7 +26,7 @@ func TestChainAware(t *testing.T) {
// Connect to the socket
client, err := abcicli.NewSocketClient("unix://test.sock", false)
if err != nil {
Exit(Fmt("Error starting socket client: %v", err.Error()))
log.Fatal(fmt.Sprintf("Error starting socket client: %v", err.Error()))
}
client.Start()
defer client.Stop()

View File

@ -2,9 +2,9 @@ package counter
import (
"encoding/binary"
"fmt"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
)
type CounterApplication struct {
@ -18,7 +18,7 @@ func NewCounterApplication(serial bool) *CounterApplication {
}
func (app *CounterApplication) Info() types.ResponseInfo {
return types.ResponseInfo{Data: Fmt("{\"hashes\":%v,\"txs\":%v}", app.hashCount, app.txCount)}
return types.ResponseInfo{Data: fmt.Sprintf("{\"hashes\":%v,\"txs\":%v}", app.hashCount, app.txCount)}
}
func (app *CounterApplication) SetOption(key string, value string) (log string) {
@ -31,44 +31,42 @@ func (app *CounterApplication) SetOption(key string, value string) (log string)
func (app *CounterApplication) DeliverTx(tx []byte) types.Result {
if app.serial {
if len(tx) > 8 {
return types.ErrEncodingError.SetLog(Fmt("Max tx size is 8 bytes, got %d", len(tx)))
return types.ErrEncodingError.SetLog(fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx)))
}
tx8 := make([]byte, 8)
copy(tx8[len(tx8)-len(tx):], tx)
txValue := binary.BigEndian.Uint64(tx8)
if txValue != uint64(app.txCount) {
return types.ErrBadNonce.SetLog(Fmt("Invalid nonce. Expected %v, got %v", app.txCount, txValue))
return types.ErrBadNonce.SetLog(fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue))
}
}
app.txCount += 1
app.txCount++
return types.OK
}
func (app *CounterApplication) CheckTx(tx []byte) types.Result {
if app.serial {
if len(tx) > 8 {
return types.ErrEncodingError.SetLog(Fmt("Max tx size is 8 bytes, got %d", len(tx)))
return types.ErrEncodingError.SetLog(fmt.Sprintf("Max tx size is 8 bytes, got %d", len(tx)))
}
tx8 := make([]byte, 8)
copy(tx8[len(tx8)-len(tx):], tx)
txValue := binary.BigEndian.Uint64(tx8)
if txValue < uint64(app.txCount) {
return types.ErrBadNonce.SetLog(Fmt("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue))
return types.ErrBadNonce.SetLog(fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue))
}
}
return types.OK
}
func (app *CounterApplication) Commit() types.Result {
app.hashCount += 1
app.hashCount++
if app.txCount == 0 {
return types.OK
} else {
hash := make([]byte, 8)
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
return types.NewResultOK(hash, "")
}
hash := make([]byte, 8)
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
return types.NewResultOK(hash, "")
}
func (app *CounterApplication) Query(query []byte) types.Result {
@ -76,10 +74,10 @@ func (app *CounterApplication) Query(query []byte) types.Result {
switch queryStr {
case "hash":
return types.NewResultOK(nil, Fmt("%v", app.hashCount))
return types.NewResultOK(nil, fmt.Sprintf("%v", app.hashCount))
case "tx":
return types.NewResultOK(nil, Fmt("%v", app.txCount))
return types.NewResultOK(nil, fmt.Sprintf("%v", app.txCount))
}
return types.ErrUnknownRequest.SetLog(Fmt("Invalid nonce. Expected hash or tx, got %v", queryStr))
return types.ErrUnknownRequest.SetLog(fmt.Sprintf("Invalid nonce. Expected hash or tx, got %v", queryStr))
}

View File

@ -2,10 +2,10 @@ package dummy
import (
"encoding/hex"
"fmt"
"strings"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
"github.com/tendermint/go-merkle"
"github.com/tendermint/go-wire"
)
@ -20,7 +20,7 @@ func NewDummyApplication() *DummyApplication {
}
func (app *DummyApplication) Info() (resInfo types.ResponseInfo) {
return types.ResponseInfo{Data: Fmt("{\"size\":%v}", app.state.Size())}
return types.ResponseInfo{Data: fmt.Sprintf("{\"size\":%v}", app.state.Size())}
}
func (app *DummyApplication) SetOption(key string, value string) (log string) {

View File

@ -2,12 +2,13 @@ package dummy
import (
"bytes"
"fmt"
"io/ioutil"
"sort"
"testing"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
)
@ -107,8 +108,8 @@ func TestValSetChanges(t *testing.T) {
nInit := 5
vals := make([]*types.Validator, total)
for i := 0; i < total; i++ {
pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(Fmt("test%d", i))).PubKey().Bytes()
power := RandInt()
pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(fmt.Sprintf("test%d", i))).PubKey().Bytes()
power := common.RandInt()
vals[i] = &types.Validator{pubkey, uint64(power)}
}
// iniitalize with the first nInit

View File

@ -3,11 +3,12 @@ package dummy
import (
"bytes"
"encoding/hex"
"fmt"
"strconv"
"strings"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
dbm "github.com/tendermint/go-db"
"github.com/tendermint/go-merkle"
"github.com/tendermint/go-wire"
@ -135,7 +136,7 @@ func LoadLastBlock(db dbm.DB) (lastBlock LastBlockInfo) {
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err)
if *err != nil {
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
Exit(Fmt("Data has been corrupted or its spec has changed: %v\n", *err))
log.Crit(fmt.Sprintf("Data has been corrupted or its spec has changed: %v\n", *err))
}
// TODO: ensure that buf is completely read.
}
@ -149,7 +150,7 @@ func SaveLastBlock(db dbm.DB, lastBlock LastBlockInfo) {
wire.WriteBinary(lastBlock, buf, n, err)
if *err != nil {
// TODO
PanicCrisis(*err)
common.PanicCrisis(*err)
}
db.Set(lastBlockKey, buf.Bytes())
}
@ -173,7 +174,7 @@ func (app *PersistentDummyApplication) Validators() (validators []*types.Validat
}
func MakeValSetChangeTx(pubkey []byte, power uint64) []byte {
return []byte(Fmt("val:%X/%d", pubkey, power))
return []byte(fmt.Sprintf("val:%X/%d", pubkey, power))
}
func isValidatorTx(tx []byte) bool {
@ -188,16 +189,16 @@ func (app *PersistentDummyApplication) execValidatorTx(tx []byte) types.Result {
tx = tx[len(ValidatorSetChangePrefix):]
pubKeyAndPower := strings.Split(string(tx), "/")
if len(pubKeyAndPower) != 2 {
return types.ErrEncodingError.SetLog(Fmt("Expected 'pubkey/power'. Got %v", pubKeyAndPower))
return types.ErrEncodingError.SetLog(fmt.Sprintf("Expected 'pubkey/power'. Got %v", pubKeyAndPower))
}
pubkeyS, powerS := pubKeyAndPower[0], pubKeyAndPower[1]
pubkey, err := hex.DecodeString(pubkeyS)
if err != nil {
return types.ErrEncodingError.SetLog(Fmt("Pubkey (%s) is invalid hex", pubkeyS))
return types.ErrEncodingError.SetLog(fmt.Sprintf("Pubkey (%s) is invalid hex", pubkeyS))
}
power, err := strconv.Atoi(powerS)
if err != nil {
return types.ErrEncodingError.SetLog(Fmt("Power (%s) is not an int", powerS))
return types.ErrEncodingError.SetLog(fmt.Sprintf("Power (%s) is not an int", powerS))
}
// update
@ -210,14 +211,14 @@ func (app *PersistentDummyApplication) updateValidator(v *types.Validator) types
if v.Power == 0 {
// remove validator
if !app.app.state.Has(key) {
return types.ErrUnauthorized.SetLog(Fmt("Cannot remove non-existent validator %X", key))
return types.ErrUnauthorized.SetLog(fmt.Sprintf("Cannot remove non-existent validator %X", key))
}
app.app.state.Remove(key)
} else {
// add or update validator
value := bytes.NewBuffer(make([]byte, 0))
if err := types.WriteMessage(v, value); err != nil {
return types.ErrInternalError.SetLog(Fmt("Error encoding validator: %v", err))
return types.ErrInternalError.SetLog(fmt.Sprintf("Error encoding validator: %v", err))
}
app.app.state.Set(key, value.Bytes())
}

View File

@ -2,20 +2,22 @@ package example
import (
"fmt"
"log"
"net"
"reflect"
"testing"
"time"
"golang.org/x/net/context"
"google.golang.org/grpc"
"golang.org/x/net/context"
"github.com/tendermint/abci/client"
"github.com/tendermint/abci/example/dummy"
nilapp "github.com/tendermint/abci/example/nil"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
func TestDummy(t *testing.T) {
@ -40,14 +42,14 @@ func testStream(t *testing.T, app types.Application) {
// Start the listener
server, err := server.NewSocketServer("unix://test.sock", app)
if err != nil {
Exit(Fmt("Error starting socket server: %v", err.Error()))
log.Fatal(fmt.Sprintf("Error starting socket server: %v", err.Error()))
}
defer server.Stop()
// Connect to the socket
client, err := abcicli.NewSocketClient("unix://test.sock", false)
if err != nil {
Exit(Fmt("Error starting socket client: %v", err.Error()))
log.Fatal(fmt.Sprintf("Error starting socket client: %v", err.Error()))
}
client.Start()
defer client.Stop()
@ -58,7 +60,7 @@ func testStream(t *testing.T, app types.Application) {
// Process response
switch r := res.Value.(type) {
case *types.Response_DeliverTx:
counter += 1
counter++
if r.DeliverTx.Code != types.CodeType_OK {
t.Error("DeliverTx failed with ret_code", r.DeliverTx.Code)
}
@ -103,7 +105,7 @@ func testStream(t *testing.T, app types.Application) {
// test grpc
func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) {
return Connect(addr)
return common.Connect(addr)
}
func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
@ -113,14 +115,14 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
// Start the listener
server, err := server.NewGRPCServer("unix://test.sock", app)
if err != nil {
Exit(Fmt("Error starting GRPC server: %v", err.Error()))
log.Fatal(fmt.Sprintf("Error starting GRPC server: %v", err.Error()))
}
defer server.Stop()
// Connect to the socket
conn, err := grpc.Dial("unix://test.sock", grpc.WithInsecure(), grpc.WithDialer(dialerFunc))
if err != nil {
Exit(Fmt("Error dialing GRPC server: %v", err.Error()))
log.Fatal(fmt.Sprintf("Error dialing GRPC server: %v", err.Error()))
}
defer conn.Close()
@ -133,7 +135,7 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
if err != nil {
t.Fatalf("Error in GRPC DeliverTx: %v", err.Error())
}
counter += 1
counter++
if response.Code != types.CodeType_OK {
t.Error("DeliverTx failed with ret_code", response.Code)
}

View File

@ -7,13 +7,13 @@ import (
"google.golang.org/grpc"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
// var maxNumberConnections = 2
type GRPCServer struct {
BaseService
common.BaseService
proto string
addr string
@ -23,7 +23,7 @@ type GRPCServer struct {
app types.ABCIApplicationServer
}
func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) (Service, error) {
func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) (common.Service, error) {
parts := strings.SplitN(protoAddr, "://", 2)
proto, addr := parts[0], parts[1]
s := &GRPCServer{
@ -32,7 +32,7 @@ func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) (Service,
listener: nil,
app: app,
}
s.BaseService = *NewBaseService(nil, "ABCIServer", s)
s.BaseService = *common.NewBaseService(nil, "ABCIServer", s)
_, err := s.Start() // Just start it
return s, err
}

View File

@ -4,11 +4,11 @@ import (
"fmt"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
func NewServer(protoAddr, transport string, app types.Application) (Service, error) {
var s Service
func NewServer(protoAddr, transport string, app types.Application) (common.Service, error) {
var s common.Service
var err error
switch transport {
case "socket":

View File

@ -9,13 +9,13 @@ import (
"sync"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
// var maxNumberConnections = 2
type SocketServer struct {
BaseService
common.BaseService
proto string
addr string
@ -29,7 +29,7 @@ type SocketServer struct {
app types.Application
}
func NewSocketServer(protoAddr string, app types.Application) (Service, error) {
func NewSocketServer(protoAddr string, app types.Application) (common.Service, error) {
parts := strings.SplitN(protoAddr, "://", 2)
proto, addr := parts[0], parts[1]
s := &SocketServer{
@ -39,7 +39,7 @@ func NewSocketServer(protoAddr string, app types.Application) (Service, error) {
app: app,
conns: make(map[int]net.Conn),
}
s.BaseService = *NewBaseService(nil, "ABCIServer", s)
s.BaseService = *common.NewBaseService(nil, "ABCIServer", s)
_, err := s.Start() // Just start it
return s, err
}
@ -72,7 +72,7 @@ func (s *SocketServer) addConn(conn net.Conn) int {
defer s.connsMtx.Unlock()
connID := s.nextConnID
s.nextConnID += 1
s.nextConnID++
s.conns[connID] = conn
return connID
@ -100,7 +100,7 @@ func (s *SocketServer) acceptConnectionsRoutine() {
if !s.IsRunning() {
return // Ignore error from listener closing.
}
Exit("Failed to accept connection: " + err.Error())
log.Crit("Failed to accept connection: " + err.Error())
} else {
log.Notice("Accepted a new connection")
}

View File

@ -3,17 +3,17 @@ package main
import (
"bufio"
"fmt"
//"encoding/hex"
"log"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
func main() {
conn, err := Connect("unix://test.sock")
conn, err := common.Connect("unix://test.sock")
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
// Read a bunch of responses
@ -23,9 +23,9 @@ func main() {
var res = &types.Response{}
err := types.ReadMessage(conn, res)
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
counter += 1
counter++
if counter%1000 == 0 {
fmt.Println("Read", counter)
}
@ -40,14 +40,14 @@ func main() {
err := types.WriteMessage(req, bufWriter)
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
err = bufWriter.Flush()
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
counter += 1
counter++
if counter%1000 == 0 {
fmt.Println("Write", counter)
}

View File

@ -2,21 +2,20 @@ package main
import (
"bufio"
"errors"
"fmt"
"log"
"net"
"reflect"
//"encoding/hex"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
common "github.com/tendermint/go-common"
)
func main() {
conn, err := Connect("unix://test.sock")
conn, err := common.Connect("unix://test.sock")
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
// Make a bunch of requests
@ -25,9 +24,9 @@ func main() {
req := types.ToRequestEcho("foobar")
_, err := makeRequest(conn, req)
if err != nil {
Exit(err.Error())
log.Fatal(err.Error())
}
counter += 1
counter++
if counter%1000 == 0 {
fmt.Println(counter)
}
@ -63,7 +62,7 @@ func makeRequest(conn net.Conn, req *types.Request) (*types.Response, error) {
return nil, err
}
if _, ok := resFlush.Value.(*types.Response_Flush); !ok {
return nil, errors.New(Fmt("Expected flush response but got something else: %v", reflect.TypeOf(resFlush)))
return nil, fmt.Errorf("Expected flush response but got something else: %v", reflect.TypeOf(resFlush))
}
return res, nil

View File

@ -2,18 +2,16 @@ package main
import (
"bytes"
"fmt"
"os"
"time"
"github.com/tendermint/abci/client"
"github.com/tendermint/abci/types"
. "github.com/tendermint/go-common"
"github.com/tendermint/go-process"
)
//----------------------------------------
func StartApp(abciApp string) *process.Process {
func startApp(abciApp string) *process.Process {
// Start the app
//outBuf := NewBufferCloser(nil)
proc, err := process.StartProcess("abci_app",
@ -33,7 +31,7 @@ func StartApp(abciApp string) *process.Process {
return proc
}
func StartClient(abciType string) abcicli.Client {
func startClient(abciType string) abcicli.Client {
// Start client
client, err := abcicli.NewClient("tcp://127.0.0.1:46658", abciType, true)
if err != nil {
@ -42,51 +40,51 @@ func StartClient(abciType string) abcicli.Client {
return client
}
func SetOption(client abcicli.Client, key, value string) {
func setOption(client abcicli.Client, key, value string) {
res := client.SetOptionSync(key, value)
_, _, log := res.Code, res.Data, res.Log
if res.IsErr() {
panic(Fmt("setting %v=%v: \nlog: %v", key, value, log))
panic(fmt.Sprintf("setting %v=%v: \nlog: %v", key, value, log))
}
}
func Commit(client abcicli.Client, hashExp []byte) {
func commit(client abcicli.Client, hashExp []byte) {
res := client.CommitSync()
_, data, log := res.Code, res.Data, res.Log
if res.IsErr() {
panic(Fmt("committing %v\nlog: %v", log))
panic(fmt.Sprintf("committing %v\nlog: %v", log))
}
if !bytes.Equal(res.Data, hashExp) {
panic(Fmt("Commit hash was unexpected. Got %X expected %X",
panic(fmt.Sprintf("Commit hash was unexpected. Got %X expected %X",
data, hashExp))
}
}
func DeliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
func deliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
res := client.DeliverTxSync(txBytes)
code, data, log := res.Code, res.Data, res.Log
if code != codeExp {
panic(Fmt("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
panic(fmt.Sprintf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
code, codeExp, log))
}
if !bytes.Equal(data, dataExp) {
panic(Fmt("DeliverTx response data was unexpected. Got %X expected %X",
panic(fmt.Sprintf("DeliverTx response data was unexpected. Got %X expected %X",
data, dataExp))
}
}
func CheckTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
func checkTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
res := client.CheckTxSync(txBytes)
code, data, log := res.Code, res.Data, res.Log
if res.IsErr() {
panic(Fmt("checking tx %X: %v\nlog: %v", txBytes, log))
panic(fmt.Sprintf("checking tx %X: %v\nlog: %v", txBytes, log))
}
if code != codeExp {
panic(Fmt("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
panic(fmt.Sprintf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
code, codeExp, log))
}
if !bytes.Equal(data, dataExp) {
panic(Fmt("CheckTx response data was unexpected. Got %X expected %X",
panic(fmt.Sprintf("CheckTx response data was unexpected. Got %X expected %X",
data, dataExp))
}
}

View File

@ -27,22 +27,22 @@ func testCounter() {
}
fmt.Printf("Running %s test with abci=%s\n", abciApp, abciType)
appProc := StartApp(abciApp)
appProc := startApp(abciApp)
defer appProc.StopProcess(true)
client := StartClient(abciType)
client := startClient(abciType)
defer client.Stop()
SetOption(client, "serial", "on")
Commit(client, nil)
DeliverTx(client, []byte("abc"), types.CodeType_BadNonce, nil)
Commit(client, nil)
DeliverTx(client, []byte{0x00}, types.CodeType_OK, nil)
Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})
DeliverTx(client, []byte{0x00}, types.CodeType_BadNonce, nil)
DeliverTx(client, []byte{0x01}, types.CodeType_OK, nil)
DeliverTx(client, []byte{0x00, 0x02}, types.CodeType_OK, nil)
DeliverTx(client, []byte{0x00, 0x03}, types.CodeType_OK, nil)
DeliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeType_OK, nil)
DeliverTx(client, []byte{0x00, 0x00, 0x06}, types.CodeType_BadNonce, nil)
Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})
setOption(client, "serial", "on")
commit(client, nil)
deliverTx(client, []byte("abc"), types.CodeType_BadNonce, nil)
commit(client, nil)
deliverTx(client, []byte{0x00}, types.CodeType_OK, nil)
commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1})
deliverTx(client, []byte{0x00}, types.CodeType_BadNonce, nil)
deliverTx(client, []byte{0x01}, types.CodeType_OK, nil)
deliverTx(client, []byte{0x00, 0x02}, types.CodeType_OK, nil)
deliverTx(client, []byte{0x00, 0x03}, types.CodeType_OK, nil)
deliverTx(client, []byte{0x00, 0x00, 0x04}, types.CodeType_OK, nil)
deliverTx(client, []byte{0x00, 0x00, 0x06}, types.CodeType_BadNonce, nil)
commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})
}