Remove TMSP Commit/Rollback; Add CheckTx

This commit is contained in:
Jae Kwon
2016-01-08 16:52:02 -08:00
parent aa3e87450a
commit f15476b157
17 changed files with 227 additions and 376 deletions

View File

@ -1,8 +1,6 @@
package example
import (
"sync"
. "github.com/tendermint/go-common"
"github.com/tendermint/go-merkle"
"github.com/tendermint/go-wire"
@ -10,7 +8,6 @@ import (
)
type DummyApplication struct {
mtx sync.Mutex
state merkle.Tree
}
@ -24,74 +21,36 @@ func NewDummyApplication() *DummyApplication {
return &DummyApplication{state: state}
}
func (dapp *DummyApplication) Open() types.AppContext {
dapp.mtx.Lock()
defer dapp.mtx.Unlock()
return &DummyAppContext{
app: dapp,
state: dapp.state.Copy(),
}
}
func (dapp *DummyApplication) commitState(state merkle.Tree) {
dapp.mtx.Lock()
defer dapp.mtx.Unlock()
dapp.state = state.Copy()
}
func (dapp *DummyApplication) getState() merkle.Tree {
dapp.mtx.Lock()
defer dapp.mtx.Unlock()
return dapp.state.Copy()
}
//--------------------------------------------------------------------------------
type DummyAppContext struct {
app *DummyApplication
state merkle.Tree
}
func (dac *DummyAppContext) Echo(message string) string {
func (app *DummyApplication) Echo(message string) string {
return message
}
func (dac *DummyAppContext) Info() []string {
return []string{Fmt("size:%v", dac.state.Size())}
func (app *DummyApplication) Info() []string {
return []string{Fmt("size:%v", app.state.Size())}
}
func (dac *DummyAppContext) SetOption(key string, value string) types.RetCode {
func (app *DummyApplication) SetOption(key string, value string) types.RetCode {
return 0
}
func (dac *DummyAppContext) AppendTx(tx []byte) ([]types.Event, types.RetCode) {
dac.state.Set(tx, tx)
func (app *DummyApplication) AppendTx(tx []byte) ([]types.Event, types.RetCode) {
app.state.Set(tx, tx)
return nil, 0
}
func (dac *DummyAppContext) GetHash() ([]byte, types.RetCode) {
hash := dac.state.Hash()
func (app *DummyApplication) CheckTx(tx []byte) types.RetCode {
return 0 // all txs are valid
}
func (app *DummyApplication) GetHash() ([]byte, types.RetCode) {
hash := app.state.Hash()
return hash, 0
}
func (dac *DummyAppContext) Commit() types.RetCode {
dac.app.commitState(dac.state)
func (app *DummyApplication) AddListener(key string) types.RetCode {
return 0
}
func (dac *DummyAppContext) Rollback() types.RetCode {
dac.state = dac.app.getState()
func (app *DummyApplication) RemListener(key string) types.RetCode {
return 0
}
func (dac *DummyAppContext) AddListener(key string) types.RetCode {
return 0
}
func (dac *DummyAppContext) RemListener(key string) types.RetCode {
return 0
}
func (dac *DummyAppContext) Close() error {
return nil
}