lint: remove dot import (go-common)
Spell out the package explicitly. This commit is totally textual, and does not change any logic. The swiss-army knife package may serve a kick-start in early stage development. But as the codebase growing, we might want to retire it gradually: For simple wrapping functions, just inline it on the call site. For larger pice of code, make it an independent package.
This commit is contained in:
parent
c65bb21a51
commit
fcaa545e1e
|
@ -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
|
||||
|
|
|
@ -9,13 +9,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 +31,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 {
|
||||
|
@ -50,7 +50,7 @@ RETRY_LOOP:
|
|||
if cli.mustConnect {
|
||||
return err
|
||||
} else {
|
||||
log.Warn(Fmt("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr))
|
||||
log.Warn(common.Fmt("abci.grpcClient failed to connect to %v. Retrying...\n", cli.addr))
|
||||
time.Sleep(time.Second * 3)
|
||||
continue RETRY_LOOP
|
||||
}
|
||||
|
@ -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(common.Fmt("Stopping abci.grpcClient for error: %v", err.Error()))
|
||||
cli.Stop()
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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,12 +65,12 @@ 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))
|
||||
log.Warn(common.Fmt("abci.socketClient failed to connect to %v. Retrying...", cli.addr))
|
||||
time.Sleep(time.Second * 3)
|
||||
continue RETRY_LOOP
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ func (cli *socketClient) StopForError(err error) {
|
|||
}
|
||||
cli.mtx.Unlock()
|
||||
|
||||
log.Warn(Fmt("Stopping abci.socketClient for error: %v", err.Error()))
|
||||
log.Warn(common.Fmt("Stopping abci.socketClient for error: %v", err.Error()))
|
||||
cli.Stop()
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
|
||||
"github.com/tendermint/abci/client"
|
||||
"github.com/tendermint/abci/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
common "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())
|
||||
common.Exit(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())
|
||||
common.Exit(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, common.Fmt("%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, common.Fmt("0x%X", res.Data), false)
|
||||
printResponse(c, rsp)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
|
||||
"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 +19,11 @@ func main() {
|
|||
// Start the listener
|
||||
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
common.Exit(err.Error())
|
||||
}
|
||||
|
||||
// Wait forever
|
||||
TrapSignal(func() {
|
||||
common.TrapSignal(func() {
|
||||
// Cleanup
|
||||
srv.Stop()
|
||||
})
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"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 +27,11 @@ func main() {
|
|||
// Start the listener
|
||||
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
common.Exit(err.Error())
|
||||
}
|
||||
|
||||
// Wait forever
|
||||
TrapSignal(func() {
|
||||
common.TrapSignal(func() {
|
||||
// Cleanup
|
||||
srv.Stop()
|
||||
})
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
|
||||
"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 +17,11 @@ func main() {
|
|||
// Start the listener
|
||||
srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication())
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
common.Exit(err.Error())
|
||||
}
|
||||
|
||||
// Wait forever
|
||||
TrapSignal(func() {
|
||||
common.TrapSignal(func() {
|
||||
// Cleanup
|
||||
srv.Stop()
|
||||
})
|
||||
|
@ -58,7 +58,7 @@ 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(common.Fmt("%d,%d", app.beginCount, app.endCount)), "")
|
||||
}
|
||||
|
||||
func (app *ChainAwareApplication) BeginBlock(hash []byte, header *types.Header) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/tendermint/abci/client"
|
||||
"github.com/tendermint/abci/server"
|
||||
"github.com/tendermint/abci/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
common "github.com/tendermint/go-common"
|
||||
)
|
||||
|
||||
func TestChainAware(t *testing.T) {
|
||||
|
@ -25,7 +25,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()))
|
||||
common.Exit(Fmt("Error starting socket client: %v", err.Error()))
|
||||
}
|
||||
client.Start()
|
||||
defer client.Stop()
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"encoding/binary"
|
||||
|
||||
"github.com/tendermint/abci/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
common "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: common.Fmt("{\"hashes\":%v,\"txs\":%v}", app.hashCount, app.txCount)}
|
||||
}
|
||||
|
||||
func (app *CounterApplication) SetOption(key string, value string) (log string) {
|
||||
|
@ -31,13 +31,13 @@ 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(common.Fmt("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(common.Fmt("Invalid nonce. Expected %v, got %v", app.txCount, txValue))
|
||||
}
|
||||
}
|
||||
app.txCount += 1
|
||||
|
@ -47,13 +47,13 @@ func (app *CounterApplication) DeliverTx(tx []byte) types.Result {
|
|||
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(common.Fmt("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(common.Fmt("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue))
|
||||
}
|
||||
}
|
||||
return types.OK
|
||||
|
@ -76,10 +76,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, common.Fmt("%v", app.hashCount))
|
||||
case "tx":
|
||||
return types.NewResultOK(nil, Fmt("%v", app.txCount))
|
||||
return types.NewResultOK(nil, common.Fmt("%v", app.txCount))
|
||||
}
|
||||
|
||||
return types.ErrUnknownRequest.SetLog(Fmt("Invalid nonce. Expected hash or tx, got %v", queryStr))
|
||||
return types.ErrUnknownRequest.SetLog(common.Fmt("Invalid nonce. Expected hash or tx, got %v", queryStr))
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/tendermint/abci/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
common "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: common.Fmt("{\"size\":%v}", app.state.Size())}
|
||||
}
|
||||
|
||||
func (app *DummyApplication) SetOption(key string, value string) (log string) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"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 +107,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(common.Fmt("test%d", i))).PubKey().Bytes()
|
||||
power := common.RandInt()
|
||||
vals[i] = &types.Validator{pubkey, uint64(power)}
|
||||
}
|
||||
// iniitalize with the first nInit
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"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 +135,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))
|
||||
common.Exit(common.Fmt("Data has been corrupted or its spec has changed: %v\n", *err))
|
||||
}
|
||||
// TODO: ensure that buf is completely read.
|
||||
}
|
||||
|
@ -149,7 +149,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 +173,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(common.Fmt("val:%X/%d", pubkey, power))
|
||||
}
|
||||
|
||||
func isValidatorTx(tx []byte) bool {
|
||||
|
@ -188,16 +188,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(common.Fmt("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(common.Fmt("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(common.Fmt("Power (%s) is not an int", powerS))
|
||||
}
|
||||
|
||||
// update
|
||||
|
@ -210,14 +210,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(common.Fmt("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(common.Fmt("Error encoding validator: %v", err))
|
||||
}
|
||||
app.app.state.Set(key, value.Bytes())
|
||||
}
|
||||
|
|
|
@ -7,15 +7,16 @@ import (
|
|||
"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 +41,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()))
|
||||
common.Exit(common.Fmt("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()))
|
||||
common.Exit(common.Fmt("Error starting socket client: %v", err.Error()))
|
||||
}
|
||||
client.Start()
|
||||
defer client.Stop()
|
||||
|
@ -113,14 +114,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()))
|
||||
common.Exit(common.Fmt("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()))
|
||||
common.Exit(common.Fmt("Error dialing GRPC server: %v", err.Error()))
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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":
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ func (s *SocketServer) acceptConnectionsRoutine() {
|
|||
if !s.IsRunning() {
|
||||
return // Ignore error from listener closing.
|
||||
}
|
||||
Exit("Failed to accept connection: " + err.Error())
|
||||
common.Exit("Failed to accept connection: " + err.Error())
|
||||
} else {
|
||||
log.Notice("Accepted a new connection")
|
||||
}
|
||||
|
|
|
@ -3,17 +3,16 @@ package main
|
|||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
//"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())
|
||||
common.Exit(err.Error())
|
||||
}
|
||||
|
||||
// Read a bunch of responses
|
||||
|
@ -23,7 +22,7 @@ func main() {
|
|||
var res = &types.Response{}
|
||||
err := types.ReadMessage(conn, res)
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
common.Exit(err.Error())
|
||||
}
|
||||
counter += 1
|
||||
if counter%1000 == 0 {
|
||||
|
@ -40,11 +39,11 @@ func main() {
|
|||
|
||||
err := types.WriteMessage(req, bufWriter)
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
common.Exit(err.Error())
|
||||
}
|
||||
err = bufWriter.Flush()
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
common.Exit(err.Error())
|
||||
}
|
||||
|
||||
counter += 1
|
||||
|
|
|
@ -6,17 +6,16 @@ import (
|
|||
"fmt"
|
||||
"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())
|
||||
common.Exit(err.Error())
|
||||
}
|
||||
|
||||
// Make a bunch of requests
|
||||
|
@ -25,7 +24,7 @@ func main() {
|
|||
req := types.ToRequestEcho("foobar")
|
||||
_, err := makeRequest(conn, req)
|
||||
if err != nil {
|
||||
Exit(err.Error())
|
||||
common.Exit(err.Error())
|
||||
}
|
||||
counter += 1
|
||||
if counter%1000 == 0 {
|
||||
|
@ -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, errors.New(common.Fmt("Expected flush response but got something else: %v", reflect.TypeOf(resFlush)))
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
"github.com/tendermint/abci/client"
|
||||
"github.com/tendermint/abci/types"
|
||||
. "github.com/tendermint/go-common"
|
||||
common "github.com/tendermint/go-common"
|
||||
"github.com/tendermint/go-process"
|
||||
)
|
||||
|
||||
|
@ -46,7 +46,7 @@ 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(common.Fmt("setting %v=%v: \nlog: %v", key, value, log))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,10 +54,10 @@ 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(common.Fmt("committing %v\nlog: %v", log))
|
||||
}
|
||||
if !bytes.Equal(res.Data, hashExp) {
|
||||
panic(Fmt("Commit hash was unexpected. Got %X expected %X",
|
||||
panic(common.Fmt("Commit hash was unexpected. Got %X expected %X",
|
||||
data, hashExp))
|
||||
}
|
||||
}
|
||||
|
@ -66,11 +66,11 @@ func DeliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, da
|
|||
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(common.Fmt("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(common.Fmt("DeliverTx response data was unexpected. Got %X expected %X",
|
||||
data, dataExp))
|
||||
}
|
||||
}
|
||||
|
@ -79,14 +79,14 @@ func CheckTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, data
|
|||
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(common.Fmt("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(common.Fmt("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(common.Fmt("CheckTx response data was unexpected. Got %X expected %X",
|
||||
data, dataExp))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue