Split dummy into 2 files. (#371)

* Update examples/basecoin glide.lock
* Split dummy file
This commit is contained in:
Jae Kwon 2018-01-24 01:04:44 -08:00 committed by GitHub
parent 8650fd70c9
commit 83f0ee31af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 77 additions and 70 deletions

View File

@ -1,14 +1,15 @@
hash: 80794a3459988a7eb794baf7688c71dad4f6c26653d7b707ac0ada93f21e0776
updated: 2018-01-20T22:01:39.658469011-08:00
updated: 2018-01-23T19:03:56.956668196-08:00
imports:
- name: github.com/btcsuite/btcd
version: 2e60448ffcc6bf78332d1fe590260095f554dd78
subpackages:
- btcec
- name: github.com/cosmos/cosmos-sdk
version: 633eaa87b38d9c5b0e938fe6b4f1dfd016247e76
version: 8650fd70c92686a192585e95413915b4302156b7
subpackages:
- baseapp
- examples/basecoin/types
- store
- types
- x/auth
@ -80,17 +81,17 @@ imports:
- edwards25519
- extra25519
- name: github.com/tendermint/go-crypto
version: 32741be2126500d600cede1e2016bbbe2754cb46
version: 12142af1cb4e3479ea4ac98a3171debff87519c6
subpackages:
- keys
- name: github.com/tendermint/go-wire
version: 90af61ec85415e05c7777cd50ff93ba40d34b1e8
version: c7801c1586f51bb28028cd420c599516d7ac9c36
subpackages:
- data
- name: github.com/tendermint/iavl
version: 1dfe265ab4b491418e88e1da6577a8ad594fc989
version: ae2ea4a62f60c72dae81ca6642944ca28cf59889
- name: github.com/tendermint/tmlibs
version: 7a52d47a1676a9fe61d07fde0a48a733cce564c6
version: 80029abc6e20f85079cd751e659a05508773288c
subpackages:
- cli
- cli/flags

View File

@ -1,12 +1,10 @@
package main
import (
"bytes"
"fmt"
"os"
"github.com/tendermint/abci/server"
crypto "github.com/tendermint/go-crypto"
cmn "github.com/tendermint/tmlibs/common"
bam "github.com/cosmos/cosmos-sdk/baseapp"
@ -52,68 +50,6 @@ func main() {
return
}
type dummyTx struct {
key []byte
value []byte
bytes []byte
}
func (tx dummyTx) Get(key interface{}) (value interface{}) {
switch k := key.(type) {
case string:
switch k {
case "key":
return tx.key
case "value":
return tx.value
}
}
return nil
}
func (tx dummyTx) Type() string {
return "dummy"
}
func (tx dummyTx) GetSignBytes() []byte {
return tx.bytes
}
// Should the app be calling this? Or only handlers?
func (tx dummyTx) ValidateBasic() error {
return nil
}
func (tx dummyTx) GetSigners() []crypto.Address {
return nil
}
func (tx dummyTx) GetSignatures() []sdk.StdSignature {
return nil
}
func (tx dummyTx) GetFeePayer() crypto.Address {
return nil
}
func decodeTx(txBytes []byte) (sdk.Tx, error) {
var tx sdk.Tx
split := bytes.Split(txBytes, []byte("="))
if len(split) == 1 {
k := split[0]
tx = dummyTx{k, k, txBytes}
} else if len(split) == 2 {
k, v := split[0], split[1]
tx = dummyTx{k, v, txBytes}
} else {
return nil, fmt.Errorf("too many =")
}
return tx, nil
}
func DummyHandler(storeKey sdk.StoreKey) sdk.Handler {
return func(ctx sdk.Context, tx sdk.Tx) sdk.Result {
// tx is already unmarshalled

70
examples/dummy/tx.go Normal file
View File

@ -0,0 +1,70 @@
package main
import (
"bytes"
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
crypto "github.com/tendermint/go-crypto"
)
type dummyTx struct {
key []byte
value []byte
bytes []byte
}
func (tx dummyTx) Get(key interface{}) (value interface{}) {
switch k := key.(type) {
case string:
switch k {
case "key":
return tx.key
case "value":
return tx.value
}
}
return nil
}
func (tx dummyTx) Type() string {
return "dummy"
}
func (tx dummyTx) GetSignBytes() []byte {
return tx.bytes
}
// Should the app be calling this? Or only handlers?
func (tx dummyTx) ValidateBasic() error {
return nil
}
func (tx dummyTx) GetSigners() []crypto.Address {
return nil
}
func (tx dummyTx) GetSignatures() []sdk.StdSignature {
return nil
}
func (tx dummyTx) GetFeePayer() crypto.Address {
return nil
}
func decodeTx(txBytes []byte) (sdk.Tx, error) {
var tx sdk.Tx
split := bytes.Split(txBytes, []byte("="))
if len(split) == 1 {
k := split[0]
tx = dummyTx{k, k, txBytes}
} else if len(split) == 2 {
k, v := split[0], split[1]
tx = dummyTx{k, v, txBytes}
} else {
return nil, fmt.Errorf("too many =")
}
return tx, nil
}