mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-06 03:50:46 +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.
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package abciclient
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/tendermint/tendermint/abci/types"
|
|
tmsync "github.com/tendermint/tendermint/internal/libs/sync"
|
|
"github.com/tendermint/tendermint/libs/log"
|
|
)
|
|
|
|
// Creator creates new ABCI clients.
|
|
type Creator func(log.Logger) (Client, error)
|
|
|
|
// NewLocalCreator returns a Creator for the given app,
|
|
// which will be running locally.
|
|
func NewLocalCreator(app types.Application) Creator {
|
|
mtx := new(tmsync.Mutex)
|
|
|
|
return func(_ log.Logger) (Client, error) {
|
|
return NewLocalClient(mtx, app), nil
|
|
}
|
|
}
|
|
|
|
// NewRemoteCreator returns a Creator for the given address (e.g.
|
|
// "192.168.0.1") and transport (e.g. "tcp"). Set mustConnect to true if you
|
|
// want the client to connect before reporting success.
|
|
func NewRemoteCreator(logger log.Logger, addr, transport string, mustConnect bool) Creator {
|
|
return func(log.Logger) (Client, error) {
|
|
remoteApp, err := NewClient(logger, addr, transport, mustConnect)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to connect to proxy: %w", err)
|
|
}
|
|
|
|
return remoteApp, nil
|
|
}
|
|
}
|