mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-08 06:15:33 +00:00
This is a very small change, but removes a method from the `service.Service` interface (a win!) and forces callers to explicitly pass loggers in to objects during construction rather than (later) injecting them. There's not a real need for this kind of lazy construction of loggers, and I think a decent potential for confusion for mutable loggers. The main concern I have is that this changes the constructor API for ABCI clients. I think this is fine, and I suspect that as we plumb contexts through, and make changes to the RPC services there'll be a number of similar sorts of changes to various (quasi) public interfaces, which I think we should welcome.
43 lines
1.4 KiB
Go
43 lines
1.4 KiB
Go
package proxy
|
|
|
|
import (
|
|
"io"
|
|
|
|
abciclient "github.com/tendermint/tendermint/abci/client"
|
|
"github.com/tendermint/tendermint/abci/example/kvstore"
|
|
"github.com/tendermint/tendermint/abci/types"
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
e2e "github.com/tendermint/tendermint/test/e2e/app"
|
|
)
|
|
|
|
// DefaultClientCreator returns a default ClientCreator, which will create a
|
|
// local client if addr is one of: 'kvstore',
|
|
// 'persistent_kvstore', 'e2e', or 'noop', otherwise - a remote client.
|
|
//
|
|
// The Closer is a noop except for persistent_kvstore applications,
|
|
// which will clean up the store.
|
|
func DefaultClientCreator(logger log.Logger, addr, transport, dbDir string) (abciclient.Creator, io.Closer) {
|
|
switch addr {
|
|
case "kvstore":
|
|
return abciclient.NewLocalCreator(kvstore.NewApplication()), noopCloser{}
|
|
case "persistent_kvstore":
|
|
app := kvstore.NewPersistentKVStoreApplication(dbDir)
|
|
return abciclient.NewLocalCreator(app), app
|
|
case "e2e":
|
|
app, err := e2e.NewApplication(e2e.DefaultConfig(dbDir))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return abciclient.NewLocalCreator(app), noopCloser{}
|
|
case "noop":
|
|
return abciclient.NewLocalCreator(types.NewBaseApplication()), noopCloser{}
|
|
default:
|
|
mustConnect := false // loop retrying
|
|
return abciclient.NewRemoteCreator(logger, addr, transport, mustConnect), noopCloser{}
|
|
}
|
|
}
|
|
|
|
type noopCloser struct{}
|
|
|
|
func (noopCloser) Close() error { return nil }
|