From 44f22e351b207cafa05bfff3abdc35fd27ef3b4a Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Tue, 12 Jan 2016 14:04:24 -0800 Subject: [PATCH] Add RetCodeBadNonce and fix response formats --- README.md | 5 ++++- cmd/tmsp-cli/tmsp-cli.go | 12 ++++++------ example/golang/counter.go | 4 ++-- example/js/app.js | 4 ++-- example/python/app.py | 4 ++-- example/python3/app.py | 4 ++-- types/retcode.go | 1 + types/retcode_string.go | 6 +++--- 8 files changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0df4c6c3..8924f57c 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,10 @@ For more information on TMSP, motivations, and tutorials, please visit [our blog ## Changelog +### Jan 12th, 2016 + +* Added "RetCodeBadNonce = 0x06" return code + ### Jan 8th, 2016 Tendermint/TMSP now comes to consensus on the order first before AppendTx. @@ -79,4 +83,3 @@ In the future, we can include a bitarray or merkle structure in the block so any To prevent spam, applications can implement their “CheckTx” messages to deduct some balance, so at least spam txs will cost something. This isn’t any more work that what we already needed to do, so it’s not any worse. You can see the new changes in the tendermint/tendermint “order_first” branch, and tendermint/tmsp “order_first” branch. If you your TMSP apps to me I can help with the transition. Please take a look at how the examples in TMSP changed, e.g. how AppContext was removed, CheckTx was added, how the TMSP msg bytes changed, and how commit/rollback messages were removed. - diff --git a/cmd/tmsp-cli/tmsp-cli.go b/cmd/tmsp-cli/tmsp-cli.go index 96575fd0..a623a95a 100644 --- a/cmd/tmsp-cli/tmsp-cli.go +++ b/cmd/tmsp-cli/tmsp-cli.go @@ -129,7 +129,7 @@ func cmdBatch(app *cli.App, c *cli.Context) { func cmdConsole(app *cli.App, c *cli.Context) { for { - fmt.Printf("> ") + fmt.Printf("\n> ") bufReader := bufio.NewReader(os.Stdin) line, more, err := bufReader.ReadLine() if more { @@ -154,7 +154,7 @@ func cmdEcho(c *cli.Context) { if err != nil { Exit(err.Error()) } - fmt.Println(res) + fmt.Println("->", res) } // Get some info from the application @@ -163,7 +163,7 @@ func cmdInfo(c *cli.Context) { if err != nil { Exit(err.Error()) } - fmt.Println(res) + fmt.Println("->", res) } // Set an option on the application @@ -176,7 +176,7 @@ func cmdSetOption(c *cli.Context) { if err != nil { Exit(err.Error()) } - fmt.Printf("%s=%s\n", args[0], args[1]) + fmt.Println("->", Fmt("%s=%s", args[0], args[1])) } // Append a new tx to application @@ -199,7 +199,7 @@ func cmdAppendTx(c *cli.Context) { if err != nil { Exit(err.Error()) } - fmt.Println("Response:", res) + fmt.Println("->", res) } // Validate a tx @@ -222,7 +222,7 @@ func cmdCheckTx(c *cli.Context) { if err != nil { Exit(err.Error()) } - fmt.Println("Response:", res) + fmt.Println("->", res) } // Get application Merkle root hash diff --git a/example/golang/counter.go b/example/golang/counter.go index 1c3b944a..56546700 100644 --- a/example/golang/counter.go +++ b/example/golang/counter.go @@ -38,7 +38,7 @@ func (app *CounterApplication) AppendTx(tx []byte) ([]types.Event, types.RetCode copy(tx8, tx) txValue := binary.LittleEndian.Uint64(tx8) if txValue != uint64(app.txCount) { - return nil, types.RetCodeInternalError + return nil, types.RetCodeBadNonce } } app.txCount += 1 @@ -51,7 +51,7 @@ func (app *CounterApplication) CheckTx(tx []byte) types.RetCode { copy(tx8, tx) txValue := binary.LittleEndian.Uint64(tx8) if txValue < uint64(app.txCount) { - return types.RetCodeInternalError + return types.RetCodeBadNonce } } return 0 diff --git a/example/js/app.js b/example/js/app.js index e6978e1d..bbdf0490 100644 --- a/example/js/app.js +++ b/example/js/app.js @@ -32,7 +32,7 @@ CounterApp.prototype.append_tx = function(txBytes){ r = new msg.buffer(txByteArray) txValue = wire.decode_big_endian(r, txBytes.length) if (txValue != this.txCount){ - return {"ret_code":1} + return {"ret_code":6} } } this.txCount += 1; @@ -48,7 +48,7 @@ CounterApp.prototype.check_tx = function(txBytes){ r = new msg.buffer(txByteArray) txValue = wire.decode_big_endian(r, txBytes.length) if (txValue < this.txCount){ - return {"ret_code":1} + return {"ret_code":6} } } return {"ret_code":0} diff --git a/example/python/app.py b/example/python/app.py index c8470d99..49831ef5 100644 --- a/example/python/app.py +++ b/example/python/app.py @@ -31,7 +31,7 @@ class CounterApplication(): txValue = decode_big_endian( BytesBuffer(txByteArray), len(txBytes)) if txValue != self.txCount: - return None, 1 + return None, 6 self.txCount += 1 return None, 0 @@ -43,7 +43,7 @@ class CounterApplication(): txValue = decode_big_endian( BytesBuffer(txByteArray), len(txBytes)) if txValue < self.txCount: - return 1 + return 6 return 0 def get_hash(self): diff --git a/example/python3/app.py b/example/python3/app.py index 6d950ff6..b3616327 100644 --- a/example/python3/app.py +++ b/example/python3/app.py @@ -31,7 +31,7 @@ class CounterApplication(): txValue = decode_big_endian( BytesBuffer(txByteArray), len(txBytes)) if txValue != self.txCount: - return None, 1 + return None, 6 self.txCount += 1 return None, 0 @@ -43,7 +43,7 @@ class CounterApplication(): txValue = decode_big_endian( BytesBuffer(txByteArray), len(txBytes)) if txValue < self.txCount: - return 1 + return 6 return 0 def get_hash(self): diff --git a/types/retcode.go b/types/retcode.go index 559164c6..8f3ad5bf 100644 --- a/types/retcode.go +++ b/types/retcode.go @@ -14,6 +14,7 @@ const ( RetCodeInsufficientFees RetCode = 3 RetCodeUnknownRequest RetCode = 4 RetCodeEncodingError RetCode = 5 + RetCodeBadNonce RetCode = 6 ) func (r RetCode) Error() error { diff --git a/types/retcode_string.go b/types/retcode_string.go index f60dca15..65457041 100644 --- a/types/retcode_string.go +++ b/types/retcode_string.go @@ -4,12 +4,12 @@ package types import "fmt" -const _RetCode_name = "RetCodeOKRetCodeInternalErrorRetCodeUnauthorizedRetCodeInsufficientFeesRetCodeUnknownRequestRetCodeEncodingError" +const _RetCode_name = "RetCodeOKRetCodeInternalErrorRetCodeUnauthorizedRetCodeInsufficientFeesRetCodeUnknownRequestRetCodeEncodingErrorRetCodeInvalidNonce" -var _RetCode_index = [...]uint8{0, 9, 29, 48, 71, 92, 112} +var _RetCode_index = [...]uint8{0, 9, 29, 48, 71, 92, 112, 131} func (i RetCode) String() string { - if i < 0 || i+1 >= RetCode(len(_RetCode_index)) { + if i < 0 || i >= RetCode(len(_RetCode_index)-1) { return fmt.Sprintf("RetCode(%d)", i) } return _RetCode_name[_RetCode_index[i]:_RetCode_index[i+1]]