Conform to TMSP v0.2

This commit is contained in:
Jae Kwon
2016-01-25 14:34:08 -08:00
parent 26d64208d1
commit 236c7afe9e
10 changed files with 48 additions and 85 deletions
+3 -5
View File
@@ -1,7 +1,7 @@
package proxy
import (
tmspcli "github.com/tendermint/tmsp/client/golang"
tmspcli "github.com/tendermint/tmsp/client"
)
type AppConn interface {
@@ -14,10 +14,8 @@ type AppConn interface {
CheckTxAsync(tx []byte)
GetHashAsync()
SetOptionAsync(key string, value string)
AddListenerAsync(key string)
RemListenerAsync(key string)
InfoSync() (info []string, err error)
InfoSync() (info string, err error)
FlushSync() error
GetHashSync() (hash []byte, err error)
GetHashSync() (hash []byte, log string, err error)
}
+14 -43
View File
@@ -1,7 +1,7 @@
package proxy
import (
tmspcli "github.com/tendermint/tmsp/client/golang"
tmspcli "github.com/tendermint/tmsp/client"
tmsp "github.com/tendermint/tmsp/types"
"sync"
)
@@ -31,12 +31,9 @@ func (app *localAppConn) Error() error {
}
func (app *localAppConn) EchoAsync(msg string) {
app.mtx.Lock()
msg2 := app.Application.Echo(msg)
app.mtx.Unlock()
app.Callback(
tmsp.RequestEcho{msg},
tmsp.ResponseEcho{msg2},
tmsp.ResponseEcho{msg},
)
}
@@ -46,71 +43,45 @@ func (app *localAppConn) FlushAsync() {
func (app *localAppConn) SetOptionAsync(key string, value string) {
app.mtx.Lock()
retCode := app.Application.SetOption(key, value)
log := app.Application.SetOption(key, value)
app.mtx.Unlock()
app.Callback(
tmsp.RequestSetOption{key, value},
tmsp.ResponseSetOption{retCode},
tmsp.ResponseSetOption{log},
)
}
func (app *localAppConn) AppendTxAsync(tx []byte) {
app.mtx.Lock()
events, retCode := app.Application.AppendTx(tx)
code, result, log := app.Application.AppendTx(tx)
app.mtx.Unlock()
app.Callback(
tmsp.RequestAppendTx{tx},
tmsp.ResponseAppendTx{retCode},
tmsp.ResponseAppendTx{code, result, log},
)
for _, event := range events {
app.Callback(
nil,
tmsp.ResponseEvent{event},
)
}
}
func (app *localAppConn) CheckTxAsync(tx []byte) {
app.mtx.Lock()
retCode := app.Application.CheckTx(tx)
code, result, log := app.Application.CheckTx(tx)
app.mtx.Unlock()
app.Callback(
tmsp.RequestCheckTx{tx},
tmsp.ResponseCheckTx{retCode},
tmsp.ResponseCheckTx{code, result, log},
)
}
func (app *localAppConn) GetHashAsync() {
app.mtx.Lock()
hash, retCode := app.Application.GetHash()
hash, log := app.Application.GetHash()
app.mtx.Unlock()
app.Callback(
tmsp.RequestGetHash{},
tmsp.ResponseGetHash{retCode, hash},
tmsp.ResponseGetHash{hash, log},
)
}
func (app *localAppConn) AddListenerAsync(key string) {
app.mtx.Lock()
retCode := app.Application.AddListener(key)
app.mtx.Unlock()
app.Callback(
tmsp.RequestAddListener{key},
tmsp.ResponseAddListener{retCode},
)
}
func (app *localAppConn) RemListenerAsync(key string) {
app.mtx.Lock()
retCode := app.Application.RemListener(key)
app.mtx.Unlock()
app.Callback(
tmsp.RequestRemListener{key},
tmsp.ResponseRemListener{retCode},
)
}
func (app *localAppConn) InfoSync() (info []string, err error) {
func (app *localAppConn) InfoSync() (info string, err error) {
app.mtx.Lock()
info = app.Application.Info()
app.mtx.Unlock()
@@ -121,9 +92,9 @@ func (app *localAppConn) FlushSync() error {
return nil
}
func (app *localAppConn) GetHashSync() (hash []byte, err error) {
func (app *localAppConn) GetHashSync() (hash []byte, log string, err error) {
app.mtx.Lock()
hash, retCode := app.Application.GetHash()
hash, log = app.Application.GetHash()
app.mtx.Unlock()
return hash, retCode.Error()
return hash, log, nil
}
+1 -1
View File
@@ -3,7 +3,7 @@ package proxy
import (
"net"
tmspcli "github.com/tendermint/tmsp/client/golang"
tmspcli "github.com/tendermint/tmsp/client"
)
// This is goroutine-safe, but users should beware that
+1 -1
View File
@@ -92,7 +92,7 @@ func TestInfo(t *testing.T) {
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
if data[0] != "size:0" {
if data != "size:0" {
t.Error("Expected ResponseInfo with one element 'size:0' but got something else")
}
}