mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-27 10:24:36 +00:00
remove Result from the client package
plus make Client interface more consistent. All *Sync functions now return an error as a second return param. Deliver/Check/Commit use Code to indicate errors and have IsErr() func defined on ResponseXYZ structs.
This commit is contained in:
+22
-25
@@ -23,7 +23,7 @@ func startApp(abciApp string) *process.Process {
|
||||
os.Stdout,
|
||||
)
|
||||
if err != nil {
|
||||
panic("running abci_app: " + err.Error())
|
||||
panicf("running abci_app: %v", err)
|
||||
}
|
||||
|
||||
// TODO a better way to handle this?
|
||||
@@ -41,57 +41,54 @@ func startClient(abciType string) abcicli.Client {
|
||||
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
|
||||
client.SetLogger(logger.With("module", "abcicli"))
|
||||
if _, err := client.Start(); err != nil {
|
||||
panic("connecting to abci_app: " + err.Error())
|
||||
panicf("connecting to abci_app: %v", err.Error())
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func setOption(client abcicli.Client, key, value string) {
|
||||
res := client.SetOptionSync(key, value)
|
||||
_, _, log := res.Code, res.Data, res.Log
|
||||
if res.IsErr() {
|
||||
panic(fmt.Sprintf("setting %v=%v: \nlog: %v", key, value, log))
|
||||
_, err := client.SetOptionSync(key, value)
|
||||
if err != nil {
|
||||
panicf("setting %v=%v: \nerr: %v", key, value, err)
|
||||
}
|
||||
}
|
||||
|
||||
func commit(client abcicli.Client, hashExp []byte) {
|
||||
res := client.CommitSync()
|
||||
_, data, _ := res.Code, res.Data, res.Log
|
||||
if res.IsErr() {
|
||||
panic(fmt.Sprintf("committing err %v\n", res))
|
||||
panicf("committing err %v\n", res)
|
||||
}
|
||||
if !bytes.Equal(res.Data, hashExp) {
|
||||
panic(fmt.Sprintf("Commit hash was unexpected. Got %X expected %X",
|
||||
data, hashExp))
|
||||
panicf("Commit hash was unexpected. Got %X expected %X", res.Data, hashExp)
|
||||
}
|
||||
}
|
||||
|
||||
func deliverTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
||||
res := client.DeliverTxSync(txBytes)
|
||||
code, data, log := res.Code, res.Data, res.Log
|
||||
if code != codeExp {
|
||||
panic(fmt.Sprintf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
|
||||
code, codeExp, log))
|
||||
if res.Code != codeExp {
|
||||
panicf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v", res.Code, codeExp, res.Log)
|
||||
}
|
||||
if !bytes.Equal(data, dataExp) {
|
||||
panic(fmt.Sprintf("DeliverTx response data was unexpected. Got %X expected %X",
|
||||
data, dataExp))
|
||||
if !bytes.Equal(res.Data, dataExp) {
|
||||
panicf("DeliverTx response data was unexpected. Got %X expected %X", res.Data, dataExp)
|
||||
}
|
||||
}
|
||||
|
||||
/*func checkTx(client abcicli.Client, txBytes []byte, codeExp types.CodeType, dataExp []byte) {
|
||||
res := client.CheckTxSync(txBytes)
|
||||
code, data, log := res.Code, res.Data, res.Log
|
||||
if res.IsErr() {
|
||||
panic(fmt.Sprintf("checking tx %X: %v\nlog: %v", txBytes, log))
|
||||
panicf("checking tx %X: %v\nlog: %v", txBytes, res.Log)
|
||||
}
|
||||
if code != codeExp {
|
||||
panic(fmt.Sprintf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
|
||||
code, codeExp, log))
|
||||
if res.Code != codeExp {
|
||||
panicf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
|
||||
res.Code, codeExp, res.Log)
|
||||
}
|
||||
if !bytes.Equal(data, dataExp) {
|
||||
panic(fmt.Sprintf("CheckTx response data was unexpected. Got %X expected %X",
|
||||
data, dataExp))
|
||||
if !bytes.Equal(res.Data, dataExp) {
|
||||
panicf("CheckTx response data was unexpected. Got %X expected %X",
|
||||
res.Data, dataExp)
|
||||
}
|
||||
}*/
|
||||
|
||||
func panicf(format string, a ...interface{}) {
|
||||
panic(fmt.Sprintf(format, a))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user