From c21c2ed69b243553dcff8da1d45b84d5f4a5621d Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 29 Nov 2015 03:43:49 -0500 Subject: [PATCH] counter example --- example/counter.go | 69 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 example/counter.go diff --git a/example/counter.go b/example/counter.go new file mode 100644 index 000000000..f52997323 --- /dev/null +++ b/example/counter.go @@ -0,0 +1,69 @@ +package example + +import ( + "encoding/binary" + "fmt" + + . "github.com/tendermint/go-common" + "github.com/tendermint/tmsp/types" +) + +type CounterApplication struct { + hashCount int + lastHashCount int + + txCount int + lastTxCount int + + commitCount int +} + +func NewCounterApplication() *CounterApplication { + return &CounterApplication{} +} + +func (dapp *CounterApplication) Echo(message string) string { + return message +} + +func (dapp *CounterApplication) Info() []string { + return []string{Fmt("hash, tx, commit counts:%d, %d, %d", dapp.hashCount, dapp.txCount, dapp.commitCount)} +} + +func (dapp *CounterApplication) SetOption(key string, value string) types.RetCode { + return 0 +} + +func (dapp *CounterApplication) AppendTx(tx []byte) ([]types.Event, types.RetCode) { + dapp.txCount += 1 + return nil, 0 +} + +func (dapp *CounterApplication) GetHash() ([]byte, types.RetCode) { + fmt.Println("getting hash!") + hash := make([]byte, 32) + binary.PutVarint(hash, int64(dapp.hashCount)) + dapp.hashCount += 1 + return hash, 0 +} + +func (dapp *CounterApplication) Commit() types.RetCode { + dapp.lastHashCount = dapp.hashCount + dapp.lastTxCount = dapp.txCount + dapp.commitCount += 1 + return 0 +} + +func (dapp *CounterApplication) Rollback() types.RetCode { + dapp.hashCount = dapp.lastHashCount + dapp.txCount = dapp.lastTxCount + return 0 +} + +func (dapp *CounterApplication) AddListener(key string) types.RetCode { + return 0 +} + +func (dapp *CounterApplication) RemListener(key string) types.RetCode { + return 0 +}