mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 23:02:16 +00:00
counter example
This commit is contained in:
parent
2de72d26cf
commit
c21c2ed69b
69
example/counter.go
Normal file
69
example/counter.go
Normal file
@ -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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user