github.com/okex/exchain@v1.8.0/libs/tendermint/proxy/client.go (about) 1 package proxy 2 3 import ( 4 "sync" 5 6 abcicli "github.com/okex/exchain/libs/tendermint/abci/client" 7 "github.com/okex/exchain/libs/tendermint/abci/example/counter" 8 "github.com/okex/exchain/libs/tendermint/abci/example/kvstore" 9 "github.com/okex/exchain/libs/tendermint/abci/types" 10 ) 11 12 // NewABCIClient returns newly connected client 13 type ClientCreator interface { 14 NewABCIClient() (abcicli.Client, error) 15 } 16 17 //---------------------------------------------------- 18 // local proxy uses a mutex on an in-proc app 19 20 type localClientCreator struct { 21 mtx *sync.Mutex 22 app types.Application 23 } 24 25 func NewLocalClientCreator(app types.Application) ClientCreator { 26 return &localClientCreator{ 27 mtx: new(sync.Mutex), 28 app: app, 29 } 30 } 31 32 func (l *localClientCreator) NewABCIClient() (abcicli.Client, error) { 33 return abcicli.NewLocalClient(l.mtx, l.app), nil 34 } 35 36 //--------------------------------------------------------------- 37 // remote proxy opens new connections to an external app process 38 39 type remoteClientCreator struct { 40 addr string 41 transport string 42 mustConnect bool 43 } 44 45 //----------------------------------------------------------------- 46 // default 47 48 func DefaultClientCreator(addr, transport, dbDir string) ClientCreator { 49 switch addr { 50 case "counter": 51 return NewLocalClientCreator(counter.NewApplication(false)) 52 case "counter_serial": 53 return NewLocalClientCreator(counter.NewApplication(true)) 54 case "kvstore": 55 return NewLocalClientCreator(kvstore.NewApplication()) 56 case "persistent_kvstore": 57 return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir)) 58 case "noop": 59 return NewLocalClientCreator(types.NewBaseApplication()) 60 } 61 62 return NewLocalClientCreator(types.NewBaseApplication()) 63 }