github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/tm2/pkg/bft/proxy/client.go (about) 1 package proxy 2 3 import ( 4 "sync" 5 6 abcicli "github.com/gnolang/gno/tm2/pkg/bft/abci/client" 7 "github.com/gnolang/gno/tm2/pkg/bft/abci/example/counter" 8 "github.com/gnolang/gno/tm2/pkg/bft/abci/example/kvstore" 9 abci "github.com/gnolang/gno/tm2/pkg/bft/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 abci.Application 23 } 24 25 func NewLocalClientCreator(app abci.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 // DefaultClientCreator 38 39 // Returns the local application, or constructs a new one via proxy. 40 // This function is meant to work with config fields. 41 func DefaultClientCreator(local abci.Application, proxy string, transport, dbDir string) ClientCreator { 42 if local != nil { 43 // local applications (ignores other arguments) 44 return NewLocalClientCreator(local) 45 } else { 46 switch proxy { 47 // default mock applications 48 case "mock://counter": 49 return NewLocalClientCreator(counter.NewCounterApplication(false)) 50 case "mock://counter_serial": 51 return NewLocalClientCreator(counter.NewCounterApplication(true)) 52 case "mock://kvstore": 53 return NewLocalClientCreator(kvstore.NewKVStoreApplication()) 54 case "mock://persistent_kvstore": 55 return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir)) 56 case "mock://noop": 57 return NewLocalClientCreator(abci.NewBaseApplication()) 58 default: 59 // socket transport applications 60 panic("proxy scheme not yet supported: " + proxy) 61 } 62 } 63 }