mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-12 23:01:30 +00:00
Group (code,data,log) return values into types.Result
This commit is contained in:
@@ -29,29 +29,37 @@ func (app *CounterApplication) SetOption(key string, value string) (log string)
|
||||
return ""
|
||||
}
|
||||
|
||||
func (app *CounterApplication) AppendTx(tx []byte) (code types.CodeType, result []byte, log string) {
|
||||
func (app *CounterApplication) AppendTx(tx []byte) types.Result {
|
||||
if app.serial {
|
||||
tx8 := make([]byte, 8)
|
||||
copy(tx8[len(tx8)-len(tx):], tx)
|
||||
txValue := binary.BigEndian.Uint64(tx8)
|
||||
if txValue != uint64(app.txCount) {
|
||||
return types.CodeType_BadNonce, nil, fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)
|
||||
return types.Result{
|
||||
Code: types.CodeType_BadNonce,
|
||||
Data: nil,
|
||||
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue),
|
||||
}
|
||||
}
|
||||
}
|
||||
app.txCount += 1
|
||||
return types.CodeType_OK, nil, ""
|
||||
return types.NewResultOK(nil, "")
|
||||
}
|
||||
|
||||
func (app *CounterApplication) CheckTx(tx []byte) (code types.CodeType, result []byte, log string) {
|
||||
func (app *CounterApplication) CheckTx(tx []byte) types.Result {
|
||||
if app.serial {
|
||||
tx8 := make([]byte, 8)
|
||||
copy(tx8[len(tx8)-len(tx):], tx)
|
||||
txValue := binary.BigEndian.Uint64(tx8)
|
||||
if txValue < uint64(app.txCount) {
|
||||
return types.CodeType_BadNonce, nil, fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue)
|
||||
return types.Result{
|
||||
Code: types.CodeType_BadNonce,
|
||||
Data: nil,
|
||||
Log: fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue),
|
||||
}
|
||||
}
|
||||
}
|
||||
return types.CodeType_OK, nil, ""
|
||||
return types.NewResultOK(nil, "")
|
||||
}
|
||||
|
||||
func (app *CounterApplication) Commit() (hash []byte, log string) {
|
||||
@@ -66,6 +74,6 @@ func (app *CounterApplication) Commit() (hash []byte, log string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (app *CounterApplication) Query(query []byte) (code types.CodeType, result []byte, log string) {
|
||||
return types.CodeType_OK, nil, fmt.Sprintf("Query is not supported")
|
||||
func (app *CounterApplication) Query(query []byte) types.Result {
|
||||
return types.NewResultOK(nil, fmt.Sprintf("Query is not supported"))
|
||||
}
|
||||
|
||||
@@ -28,18 +28,18 @@ func (app *DummyApplication) SetOption(key string, value string) (log string) {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (app *DummyApplication) AppendTx(tx []byte) (code types.CodeType, result []byte, log string) {
|
||||
func (app *DummyApplication) AppendTx(tx []byte) types.Result {
|
||||
parts := strings.Split(string(tx), "=")
|
||||
if len(parts) == 2 {
|
||||
app.state.Set([]byte(parts[0]), []byte(parts[1]))
|
||||
} else {
|
||||
app.state.Set(tx, tx)
|
||||
}
|
||||
return types.CodeType_OK, nil, ""
|
||||
return types.NewResultOK(nil, "")
|
||||
}
|
||||
|
||||
func (app *DummyApplication) CheckTx(tx []byte) (code types.CodeType, result []byte, log string) {
|
||||
return types.CodeType_OK, nil, ""
|
||||
func (app *DummyApplication) CheckTx(tx []byte) types.Result {
|
||||
return types.NewResultOK(nil, "")
|
||||
}
|
||||
|
||||
func (app *DummyApplication) Commit() (hash []byte, log string) {
|
||||
@@ -47,8 +47,8 @@ func (app *DummyApplication) Commit() (hash []byte, log string) {
|
||||
return hash, ""
|
||||
}
|
||||
|
||||
func (app *DummyApplication) Query(query []byte) (code types.CodeType, result []byte, log string) {
|
||||
func (app *DummyApplication) Query(query []byte) types.Result {
|
||||
index, value, exists := app.state.Get(query)
|
||||
resStr := Fmt("Index=%v value=%v exists=%v", index, string(value), exists)
|
||||
return types.CodeType_OK, []byte(resStr), ""
|
||||
return types.NewResultOK([]byte(resStr), "")
|
||||
}
|
||||
|
||||
@@ -19,18 +19,18 @@ func (app *NilApplication) SetOption(key string, value string) (log string) {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (app *NilApplication) AppendTx(tx []byte) (code types.CodeType, result []byte, log string) {
|
||||
return types.CodeType_OK, nil, ""
|
||||
func (app *NilApplication) AppendTx(tx []byte) types.Result {
|
||||
return types.NewResultOK(nil, "")
|
||||
}
|
||||
|
||||
func (app *NilApplication) CheckTx(tx []byte) (code types.CodeType, result []byte, log string) {
|
||||
return types.CodeType_OK, nil, ""
|
||||
func (app *NilApplication) CheckTx(tx []byte) types.Result {
|
||||
return types.NewResultOK(nil, "")
|
||||
}
|
||||
|
||||
func (app *NilApplication) Commit() (hash []byte, log string) {
|
||||
return []byte("nil"), ""
|
||||
}
|
||||
|
||||
func (app *NilApplication) Query(query []byte) (code types.CodeType, result []byte, log string) {
|
||||
return types.CodeType_OK, nil, ""
|
||||
func (app *NilApplication) Query(query []byte) types.Result {
|
||||
return types.NewResultOK(nil, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user