Use protobuf enums for RetCode. s/RetCode/CodeType/g

This commit is contained in:
Jae Kwon
2016-01-31 20:39:43 -08:00
parent 012abc437b
commit 69e587f57f
10 changed files with 110 additions and 90 deletions

View File

@ -29,29 +29,29 @@ func (app *CounterApplication) SetOption(key string, value string) (log string)
return ""
}
func (app *CounterApplication) AppendTx(tx []byte) (code types.RetCode, result []byte, log string) {
func (app *CounterApplication) AppendTx(tx []byte) (code types.CodeType, result []byte, log string) {
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.RetCodeBadNonce, nil, fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)
return types.CodeType_BadNonce, nil, fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)
}
}
app.txCount += 1
return types.RetCodeOK, nil, ""
return types.CodeType_OK, nil, ""
}
func (app *CounterApplication) CheckTx(tx []byte) (code types.RetCode, result []byte, log string) {
func (app *CounterApplication) CheckTx(tx []byte) (code types.CodeType, result []byte, log string) {
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.RetCodeBadNonce, nil, fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue)
return types.CodeType_BadNonce, nil, fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue)
}
}
return types.RetCodeOK, nil, ""
return types.CodeType_OK, nil, ""
}
func (app *CounterApplication) GetHash() (hash []byte, log string) {
@ -66,6 +66,6 @@ func (app *CounterApplication) GetHash() (hash []byte, log string) {
}
}
func (app *CounterApplication) Query(query []byte) (code types.RetCode, result []byte, log string) {
return types.RetCodeOK, nil, fmt.Sprintf("Query is not supported")
func (app *CounterApplication) Query(query []byte) (code types.CodeType, result []byte, log string) {
return types.CodeType_OK, nil, fmt.Sprintf("Query is not supported")
}

View File

@ -26,13 +26,13 @@ func (app *DummyApplication) SetOption(key string, value string) (log string) {
return ""
}
func (app *DummyApplication) AppendTx(tx []byte) (code types.RetCode, result []byte, log string) {
func (app *DummyApplication) AppendTx(tx []byte) (code types.CodeType, result []byte, log string) {
app.state.Set(tx, tx)
return types.RetCodeOK, nil, ""
return types.CodeType_OK, nil, ""
}
func (app *DummyApplication) CheckTx(tx []byte) (code types.RetCode, result []byte, log string) {
return types.RetCodeOK, nil, ""
func (app *DummyApplication) CheckTx(tx []byte) (code types.CodeType, result []byte, log string) {
return types.CodeType_OK, nil, ""
}
func (app *DummyApplication) GetHash() (hash []byte, log string) {
@ -40,6 +40,6 @@ func (app *DummyApplication) GetHash() (hash []byte, log string) {
return hash, ""
}
func (app *DummyApplication) Query(query []byte) (code types.RetCode, result []byte, log string) {
return types.RetCodeOK, nil, "Query not supported"
func (app *DummyApplication) Query(query []byte) (code types.CodeType, result []byte, log string) {
return types.CodeType_OK, nil, "Query not supported"
}

View File

@ -41,7 +41,7 @@ func TestStream(t *testing.T) {
switch res.Type {
case types.MessageType_AppendTx:
counter += 1
if types.RetCode(res.Code) != types.RetCodeOK {
if res.Code != types.CodeType_OK {
t.Error("AppendTx failed with ret_code", res.Code)
}
if counter > numAppendTxs {