more comments cleanup

This commit is contained in:
rigelrozanski 2018-02-05 01:59:11 +01:00
parent 41ae60c1fb
commit da538a8bf6
9 changed files with 46 additions and 48 deletions

View File

@ -35,26 +35,29 @@ type BaseApp struct {
// Unmarshal []byte into sdk.Tx
txDecoder sdk.TxDecoder
// Ante handler for fee and auth.
// Ante handler for fee and auth
defaultAnteHandler sdk.AnteHandler
// Handle any kind of message.
// Handle any kind of message
router Router
//--------------------
// Volatile
// CheckTx state, a cache-wrap of `.cms`.
// CheckTx state, a cache-wrap of `.cms`
msCheck sdk.CacheMultiStore
// DeliverTx state, a cache-wrap of `.cms`.
// DeliverTx state, a cache-wrap of `.cms`
msDeliver sdk.CacheMultiStore
// Current block header
header *abci.Header
// Cached validator changes from DeliverTx.
// Cached validator changes from DeliverTx
valUpdates []abci.Validator
// function to
initStater sdk.InitStater
}
var _ abci.Application = &BaseApp{}

View File

@ -184,6 +184,7 @@ func (coins Coins) IsNotNegative() bool {
return true
}
// Returns the amount of a denom from coins
func (coins Coins) AmountOf(denom string) int64 {
switch len(coins) {
case 0:
@ -192,9 +193,8 @@ func (coins Coins) AmountOf(denom string) int64 {
coin := coins[0]
if coin.Denom == denom {
return coin.Amount
} else {
return 0
}
return 0
default:
midIdx := len(coins) / 2 // 2:1, 3:1, 4:2
coin := coins[midIdx]

View File

@ -192,7 +192,7 @@ func TestAmountOf(t *testing.T) {
cases := []struct {
coins Coins
amountOf int64
amountOf_ int64
amountOfSpace int64
amountOfGAS int64
amountOfMINERAL int64
amountOfTREE int64
@ -210,7 +210,7 @@ func TestAmountOf(t *testing.T) {
for _, tc := range cases {
assert.Equal(t, tc.amountOf, tc.coins.AmountOf(""))
assert.Equal(t, tc.amountOf_, tc.coins.AmountOf(" "))
assert.Equal(t, tc.amountOfSpace, tc.coins.AmountOf(" "))
assert.Equal(t, tc.amountOfGAS, tc.coins.AmountOf("GAS"))
assert.Equal(t, tc.amountOfMINERAL, tc.coins.AmountOf("MINERAL"))
assert.Equal(t, tc.amountOfTREE, tc.coins.AmountOf("TREE"))

View File

@ -30,6 +30,7 @@ type Context struct {
// it's probably not what you want to do.
}
// create a new context
func NewContext(ms MultiStore, header abci.Header, isCheckTx bool, txBytes []byte) Context {
c := Context{
Context: context.Background(),
@ -45,6 +46,7 @@ func NewContext(ms MultiStore, header abci.Header, isCheckTx bool, txBytes []byt
return c
}
// is context nil
func (c Context) IsZero() bool {
return c.Context == nil
}
@ -52,6 +54,7 @@ func (c Context) IsZero() bool {
//----------------------------------------
// Getting a value
// context value for the provided key
func (c Context) Value(key interface{}) interface{} {
value := c.Context.Value(key)
if cloner, ok := value.(cloner); ok {
@ -71,34 +74,28 @@ func (c Context) KVStore(key StoreKey) KVStore {
//----------------------------------------
// With* (setting a value)
// nolint
func (c Context) WithValue(key interface{}, value interface{}) Context {
return c.withValue(key, value)
}
func (c Context) WithCloner(key interface{}, value cloner) Context {
return c.withValue(key, value)
}
func (c Context) WithCacheWrapper(key interface{}, value CacheWrapper) Context {
return c.withValue(key, value)
}
func (c Context) WithProtoMsg(key interface{}, value proto.Message) Context {
return c.withValue(key, value)
}
func (c Context) WithString(key interface{}, value string) Context {
return c.withValue(key, value)
}
func (c Context) WithInt32(key interface{}, value int32) Context {
return c.withValue(key, value)
}
func (c Context) WithUint32(key interface{}, value uint32) Context {
return c.withValue(key, value)
}
func (c Context) WithUint64(key interface{}, value uint64) Context {
return c.withValue(key, value)
}
@ -138,47 +135,38 @@ func (c Context) multiStore() MultiStore {
return c.Value(contextKeyMultiStore).(MultiStore)
}
// nolint
func (c Context) BlockHeader() abci.Header {
return c.Value(contextKeyBlockHeader).(abci.Header)
}
func (c Context) BlockHeight() int64 {
return c.Value(contextKeyBlockHeight).(int64)
}
func (c Context) ChainID() string {
return c.Value(contextKeyChainID).(string)
}
func (c Context) IsCheckTx() bool {
return c.Value(contextKeyIsCheckTx).(bool)
}
func (c Context) TxBytes() []byte {
return c.Value(contextKeyTxBytes).([]byte)
}
func (c Context) WithMultiStore(ms MultiStore) Context {
return c.withValue(contextKeyMultiStore, ms)
}
func (c Context) WithBlockHeader(header abci.Header) Context {
var _ proto.Message = &header // for cloning.
return c.withValue(contextKeyBlockHeader, header)
}
func (c Context) WithBlockHeight(height int64) Context {
return c.withValue(contextKeyBlockHeight, height)
}
func (c Context) WithChainID(chainID string) Context {
return c.withValue(contextKeyChainID, chainID)
}
func (c Context) WithIsCheckTx(isCheckTx bool) Context {
return c.withValue(contextKeyIsCheckTx, isCheckTx)
}
func (c Context) WithTxBytes(txBytes []byte) Context {
return c.withValue(contextKeyTxBytes, txBytes)
}
@ -199,6 +187,7 @@ type cloner interface {
Clone() interface{} // deep copy
}
// XXX add description
type Op struct {
// type is always 'with'
gen int
@ -221,7 +210,7 @@ func newThePast() *thePast {
func (pst *thePast) bump(op Op) {
pst.mtx.Lock()
pst.ver += 1
pst.ver++
pst.ops = append(pst.ops, op)
pst.mtx.Unlock()
}
@ -240,7 +229,6 @@ func (pst *thePast) getOp(ver int64) (Op, bool) {
l := int64(len(pst.ops))
if l < ver || ver <= 0 {
return Op{}, false
} else {
}
return pst.ops[ver-1], true
}
}

View File

@ -7,19 +7,20 @@ import (
"github.com/tendermint/go-crypto"
)
// ABCI Response Code
type CodeType uint32
// is everything okay?
func (code CodeType) IsOK() bool {
if code == CodeOK {
return true
} else {
}
return false
}
}
const (
// ABCI Response Codes
// Base SDK reserves 0 ~ 99.
const (
CodeOK CodeType = 0
CodeInternal CodeType = 1
CodeTxParse CodeType = 2
@ -59,34 +60,28 @@ func CodeToDefaultMsg(code CodeType) string {
// All errors are created via constructors so as to enable us to hijack them
// and inject stack traces if we really want to.
// nolint
func ErrInternal(msg string) Error {
return newError(CodeInternal, msg)
}
func ErrTxParse(msg string) Error {
return newError(CodeTxParse, msg)
}
func ErrBadNonce(msg string) Error {
return newError(CodeBadNonce, msg)
}
func ErrUnauthorized(msg string) Error {
return newError(CodeUnauthorized, msg)
}
func ErrInsufficientFunds(msg string) Error {
return newError(CodeInsufficientFunds, msg)
}
func ErrUnknownRequest(msg string) Error {
return newError(CodeUnknownRequest, msg)
}
func ErrUnrecognizedAddress(addr crypto.Address) Error {
return newError(CodeUnrecognizedAddress, addr.String())
}
func ErrInvalidSequence(msg string) Error {
return newError(CodeInvalidSequence, msg)
}
@ -94,6 +89,7 @@ func ErrInvalidSequence(msg string) Error {
//----------------------------------------
// Error & sdkError
// sdk Error type
type Error interface {
Error() string
ABCICode() CodeType

View File

@ -1,5 +1,6 @@
package types
// core function variable which application runs for transactions
type Handler func(ctx Context, msg Msg) Result
// If newCtx.IsZero(), ctx is used instead.

View File

@ -2,6 +2,7 @@ package types
import crypto "github.com/tendermint/go-crypto"
// Standard Signature
type StdSignature struct {
crypto.PubKey // optional
crypto.Signature

View File

@ -9,12 +9,12 @@ import (
// NOTE: These are implemented in cosmos-sdk/store.
type Store interface {
type Store interface { //nolint
GetStoreType() StoreType
CacheWrapper
}
// Something that can persist to disk.
// something that can persist to disk
type Committer interface {
Commit() CommitID
LastCommitID() CommitID
@ -37,7 +37,7 @@ type Queryable interface {
//----------------------------------------
// MultiStore
type MultiStore interface {
type MultiStore interface { //nolint
Store
// Cache wrap MultiStore.
@ -139,10 +139,6 @@ type CacheKVStore interface {
cache-wraps make no sense. It can return KVStore, HeapStore,
SpaceStore, etc.
*/
type CacheWrapper interface {
CacheWrap() CacheWrap
}
type CacheWrap interface {
// Write syncs with the underlying store.
@ -152,6 +148,10 @@ type CacheWrap interface {
CacheWrap() CacheWrap
}
type CacheWrapper interface { //nolint
CacheWrap() CacheWrap
}
//----------------------------------------
// CommitID
@ -161,7 +161,7 @@ type CommitID struct {
Hash []byte
}
func (cid CommitID) IsZero() bool {
func (cid CommitID) IsZero() bool { //nolint
return cid.Version == 0 && len(cid.Hash) == 0
}
@ -172,9 +172,11 @@ func (cid CommitID) String() string {
//----------------------------------------
// Store types
// kind of store
type StoreType int
const (
//nolint
StoreTypeMulti StoreType = iota
StoreTypeDB
StoreTypeIAVL

View File

@ -4,6 +4,7 @@ import (
crypto "github.com/tendermint/go-crypto"
)
// Transactions messages must fulfill the Msg
type Msg interface {
// Return the message type.
@ -26,6 +27,7 @@ type Msg interface {
GetSigners() []crypto.Address
}
// Transactions objects must fulfill the Tx
type Tx interface {
// Gets the Msg.
@ -47,13 +49,18 @@ type Tx interface {
var _ Tx = (*StdTx)(nil)
// standard transaction form
type StdTx struct {
Msg
Signatures []StdSignature
}
//nolint
func (tx StdTx) GetMsg() Msg { return tx.Msg }
func (tx StdTx) GetFeePayer() crypto.Address { return tx.Signatures[0].PubKey.Address() }
func (tx StdTx) GetSignatures() []StdSignature { return tx.Signatures }
//-------------------------------------
// Application function variable used to unmarshal transaction bytes
type TxDecoder func(txBytes []byte) (Tx, Error)