Add RetCodeBadNonce and fix response formats
This commit is contained in:
parent
87b9866d1f
commit
44f22e351b
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -14,6 +14,7 @@ const (
|
|||
RetCodeInsufficientFees RetCode = 3
|
||||
RetCodeUnknownRequest RetCode = 4
|
||||
RetCodeEncodingError RetCode = 5
|
||||
RetCodeBadNonce RetCode = 6
|
||||
)
|
||||
|
||||
func (r RetCode) Error() error {
|
||||
|
|
|
@ -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]]
|
||||
|
|
Loading…
Reference in New Issue