From 7448cdc154e07b8e7c2ad4f6a8022c2088cd80a9 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 30 Nov 2015 15:22:42 -0800 Subject: [PATCH] Add serial=on option for CounterApplication --- example/counter.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/example/counter.go b/example/counter.go index 6e6b6527a..870d5a808 100644 --- a/example/counter.go +++ b/example/counter.go @@ -35,6 +35,7 @@ type CounterAppContext struct { hashCount int txCount int commitCount int + serial bool } func (appC *CounterAppContext) Echo(message string) string { @@ -46,10 +47,22 @@ func (appC *CounterAppContext) Info() []string { } func (appC *CounterAppContext) SetOption(key string, value string) types.RetCode { + if key == "serial" && value == "on" { + appC.serial = true + } return 0 } func (appC *CounterAppContext) AppendTx(tx []byte) ([]types.Event, types.RetCode) { + if appC.serial { + txValue, bz := binary.Varint(tx) + if bz <= 0 { + return nil, types.RetCodeInternalError + } + if txValue != int64(appC.txCount) { + return nil, types.RetCodeInternalError + } + } appC.txCount += 1 return nil, 0 }