2015-11-02 07:39:53 -08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
. "github.com/tendermint/go-common"
|
|
|
|
"github.com/tendermint/go-merkle"
|
|
|
|
"github.com/tendermint/go-wire"
|
|
|
|
"github.com/tendermint/tmsp/server"
|
|
|
|
"github.com/tendermint/tmsp/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
// Start the listener
|
2015-11-09 18:16:35 -08:00
|
|
|
_, err := server.StartListener("tcp://127.0.0.1:8080", NewDummyApplication())
|
2015-11-02 07:39:53 -08:00
|
|
|
if err != nil {
|
|
|
|
Exit(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait forever
|
|
|
|
TrapSignal(func() {
|
|
|
|
// Cleanup
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
type DummyApplication struct {
|
|
|
|
state merkle.Tree
|
|
|
|
lastCommitState merkle.Tree
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDummyApplication() *DummyApplication {
|
|
|
|
state := merkle.NewIAVLTree(
|
|
|
|
wire.BasicCodec,
|
|
|
|
wire.BasicCodec,
|
|
|
|
0,
|
|
|
|
nil,
|
|
|
|
)
|
|
|
|
return &DummyApplication{
|
|
|
|
state: state,
|
|
|
|
lastCommitState: state,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-09 16:29:45 -08:00
|
|
|
func (dapp *DummyApplication) Echo(message string) string {
|
|
|
|
return message
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dapp *DummyApplication) Info() []string {
|
|
|
|
return []string{Fmt("size:%v", dapp.state.Size())}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2015-11-16 15:50:26 -08:00
|
|
|
func (dapp *DummyApplication) AppendTx(tx []byte) ([]types.Event, types.RetCode) {
|
2015-11-02 07:39:53 -08:00
|
|
|
dapp.state.Set(tx, tx)
|
2015-11-16 15:50:26 -08:00
|
|
|
return nil, 0
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (dapp *DummyApplication) GetHash() ([]byte, types.RetCode) {
|
|
|
|
hash := dapp.state.Hash()
|
|
|
|
return hash, 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dapp *DummyApplication) Commit() types.RetCode {
|
|
|
|
dapp.lastCommitState = dapp.state.Copy()
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dapp *DummyApplication) Rollback() types.RetCode {
|
|
|
|
dapp.state = dapp.lastCommitState.Copy()
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dapp *DummyApplication) SetEventsMode(mode types.EventsMode) types.RetCode {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dapp *DummyApplication) AddListener(key string) types.RetCode {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dapp *DummyApplication) RemListener(key string) types.RetCode {
|
|
|
|
return 0
|
|
|
|
}
|