Merge pull request #493 from cosmos/sed-dummy-kvstore

rename dummy to kvstore
This commit is contained in:
Ethan Buchman 2018-02-21 00:10:16 -05:00 committed by GitHub
commit e18d8ea558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 23 deletions

View File

@ -58,9 +58,6 @@ godocs:
######################################## ########################################
### Testing ### Testing
TUTORIALS=$(shell find docs/guide -name "*md" -type f)
#test: test_unit test_cli test_tutorial
test: test_unit # test_cli test: test_unit # test_cli
test_unit: test_unit:

View File

@ -282,7 +282,7 @@ func NewHandler(am sdk.AccountMapper) sdk.Handler {
### vs encoding/json ### vs encoding/json
### vs protobuf ### vs protobuf
## Dummy example ## KVStore example
## Basecoin example ## Basecoin example

View File

@ -421,8 +421,8 @@ vs encoding/json
vs protobuf vs protobuf
~~~~~~~~~~~ ~~~~~~~~~~~
Dummy example KVStore example
------------- ---------------
Basecoin example Basecoin example
---------------- ----------------

View File

@ -27,7 +27,7 @@ func main() {
var capKeyMainStore = sdk.NewKVStoreKey("main") var capKeyMainStore = sdk.NewKVStoreKey("main")
// Create BaseApp. // Create BaseApp.
var baseApp = bam.NewBaseApp("dummy", logger, db) var baseApp = bam.NewBaseApp("kvstore", logger, db)
// Set mounts for BaseApp's MultiStore. // Set mounts for BaseApp's MultiStore.
baseApp.MountStore(capKeyMainStore, sdk.StoreTypeIAVL) baseApp.MountStore(capKeyMainStore, sdk.StoreTypeIAVL)
@ -36,7 +36,7 @@ func main() {
baseApp.SetTxDecoder(decodeTx) baseApp.SetTxDecoder(decodeTx)
// Set a handler Route. // Set a handler Route.
baseApp.Router().AddRoute("dummy", DummyHandler(capKeyMainStore)) baseApp.Router().AddRoute("kvstore", KVStoreHandler(capKeyMainStore))
// Load latest version. // Load latest version.
if err := baseApp.LoadLatestVersion(capKeyMainStore); err != nil { if err := baseApp.LoadLatestVersion(capKeyMainStore); err != nil {
@ -60,11 +60,11 @@ func main() {
return return
} }
func DummyHandler(storeKey sdk.StoreKey) sdk.Handler { func KVStoreHandler(storeKey sdk.StoreKey) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { return func(ctx sdk.Context, msg sdk.Msg) sdk.Result {
dTx, ok := msg.(dummyTx) dTx, ok := msg.(kvstoreTx)
if !ok { if !ok {
panic("DummyHandler should only receive dummyTx") panic("KVStoreHandler should only receive kvstoreTx")
} }
// tx is already unmarshalled // tx is already unmarshalled

View File

@ -8,13 +8,13 @@ import (
) )
// An sdk.Tx which is its own sdk.Msg. // An sdk.Tx which is its own sdk.Msg.
type dummyTx struct { type kvstoreTx struct {
key []byte key []byte
value []byte value []byte
bytes []byte bytes []byte
} }
func (tx dummyTx) Get(key interface{}) (value interface{}) { func (tx kvstoreTx) Get(key interface{}) (value interface{}) {
switch k := key.(type) { switch k := key.(type) {
case string: case string:
switch k { switch k {
@ -27,32 +27,32 @@ func (tx dummyTx) Get(key interface{}) (value interface{}) {
return nil return nil
} }
func (tx dummyTx) Type() string { func (tx kvstoreTx) Type() string {
return "dummy" return "kvstore"
} }
func (tx dummyTx) GetMsg() sdk.Msg { func (tx kvstoreTx) GetMsg() sdk.Msg {
return tx return tx
} }
func (tx dummyTx) GetSignBytes() []byte { func (tx kvstoreTx) GetSignBytes() []byte {
return tx.bytes return tx.bytes
} }
// Should the app be calling this? Or only handlers? // Should the app be calling this? Or only handlers?
func (tx dummyTx) ValidateBasic() sdk.Error { func (tx kvstoreTx) ValidateBasic() sdk.Error {
return nil return nil
} }
func (tx dummyTx) GetSigners() []crypto.Address { func (tx kvstoreTx) GetSigners() []crypto.Address {
return nil return nil
} }
func (tx dummyTx) GetSignatures() []sdk.StdSignature { func (tx kvstoreTx) GetSignatures() []sdk.StdSignature {
return nil return nil
} }
func (tx dummyTx) GetFeePayer() crypto.Address { func (tx kvstoreTx) GetFeePayer() crypto.Address {
return nil return nil
} }
@ -64,10 +64,10 @@ func decodeTx(txBytes []byte) (sdk.Tx, sdk.Error) {
split := bytes.Split(txBytes, []byte("=")) split := bytes.Split(txBytes, []byte("="))
if len(split) == 1 { if len(split) == 1 {
k := split[0] k := split[0]
tx = dummyTx{k, k, txBytes} tx = kvstoreTx{k, k, txBytes}
} else if len(split) == 2 { } else if len(split) == 2 {
k, v := split[0], split[1] k, v := split[0], split[1]
tx = dummyTx{k, v, txBytes} tx = kvstoreTx{k, v, txBytes}
} else { } else {
return nil, sdk.ErrTxParse("too many =") return nil, sdk.ErrTxParse("too many =")
} }