golinted up to and incl modules
This commit is contained in:
parent
35845a958f
commit
0303f2aaaa
|
@ -8,7 +8,7 @@ import (
|
|||
cmn "github.com/tendermint/tmlibs/common"
|
||||
)
|
||||
|
||||
// LoadGenesis - Load the genesis json file
|
||||
// LoadGenesis - Load the genesis file into memory
|
||||
func (app *Basecoin) LoadGenesis(path string) error {
|
||||
genDoc, err := loadGenesis(path)
|
||||
if err != nil {
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
//nolint
|
||||
package errors
|
||||
|
||||
/**
|
||||
* Copyright (C) 2017 Ethan Frey
|
||||
**/
|
||||
|
||||
import (
|
||||
rawerr "errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -14,17 +10,17 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
errDecoding = rawerr.New("Error decoding input")
|
||||
errUnauthorized = rawerr.New("Unauthorized")
|
||||
errInvalidSignature = rawerr.New("Invalid Signature")
|
||||
errTooLarge = rawerr.New("Input size too large")
|
||||
errMissingSignature = rawerr.New("Signature missing")
|
||||
errTooManySignatures = rawerr.New("Too many signatures")
|
||||
errNoChain = rawerr.New("No chain id provided")
|
||||
errWrongChain = rawerr.New("Wrong chain for tx")
|
||||
errUnknownTxType = rawerr.New("Tx type unknown")
|
||||
errInvalidFormat = rawerr.New("Invalid format")
|
||||
errUnknownModule = rawerr.New("Unknown module")
|
||||
errDecoding = fmt.Errorf("Error decoding input")
|
||||
errUnauthorized = fmt.Errorf("Unauthorized")
|
||||
errInvalidSignature = fmt.Errorf("Invalid Signature")
|
||||
errTooLarge = fmt.Errorf("Input size too large")
|
||||
errMissingSignature = fmt.Errorf("Signature missing")
|
||||
errTooManySignatures = fmt.Errorf("Too many signatures")
|
||||
errNoChain = fmt.Errorf("No chain id provided")
|
||||
errWrongChain = fmt.Errorf("Wrong chain for tx")
|
||||
errUnknownTxType = fmt.Errorf("Tx type unknown")
|
||||
errInvalidFormat = fmt.Errorf("Invalid format")
|
||||
errUnknownModule = fmt.Errorf("Unknown module")
|
||||
)
|
||||
|
||||
func ErrUnknownTxType(tx basecoin.Tx) TMError {
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package errors
|
||||
|
||||
/**
|
||||
* Copyright (C) 2017 Ethan Frey
|
||||
**/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
|
@ -23,6 +19,7 @@ type causer interface {
|
|||
Cause() error
|
||||
}
|
||||
|
||||
// TMError is the tendermint abci return type with stack trace
|
||||
type TMError interface {
|
||||
stackTracer
|
||||
ErrorCode() abci.CodeType
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//nolint
|
||||
package coin
|
||||
|
||||
import (
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
/**** code to parse accounts from genesis docs ***/
|
||||
|
||||
// GenesisAccount - genesis account parameters
|
||||
type GenesisAccount struct {
|
||||
Address data.Bytes `json:"address"`
|
||||
// this from types.Account (don't know how to embed this properly)
|
||||
|
@ -21,6 +22,7 @@ type GenesisAccount struct {
|
|||
Balance types.Coins `json:"coins"`
|
||||
}
|
||||
|
||||
// ToAccount - GenesisAccount struct to a basecoin Account
|
||||
func (g GenesisAccount) ToAccount() Account {
|
||||
return Account{
|
||||
Sequence: g.Sequence,
|
||||
|
@ -28,6 +30,7 @@ func (g GenesisAccount) ToAccount() Account {
|
|||
}
|
||||
}
|
||||
|
||||
// GetAddr - Get the address of the genesis account
|
||||
func (g GenesisAccount) GetAddr() ([]byte, error) {
|
||||
noAddr, noPk := len(g.Address) == 0, g.PubKey.Empty()
|
||||
|
||||
|
|
|
@ -12,24 +12,25 @@ import (
|
|||
"github.com/tendermint/basecoin/types"
|
||||
)
|
||||
|
||||
const (
|
||||
NameCoin = "coin"
|
||||
)
|
||||
//NameCoin - name space of the coin module
|
||||
const NameCoin = "coin"
|
||||
|
||||
// Handler writes
|
||||
// Handler includes an accountant
|
||||
type Handler struct {
|
||||
Accountant
|
||||
}
|
||||
|
||||
var _ basecoin.Handler = Handler{}
|
||||
|
||||
// NewHandler - new accountant handler for the coin module
|
||||
func NewHandler() Handler {
|
||||
return Handler{
|
||||
Accountant: NewAccountant(""),
|
||||
}
|
||||
}
|
||||
|
||||
func (_ Handler) Name() string {
|
||||
// Name - return name space
|
||||
func (h Handler) Name() string {
|
||||
return NameCoin
|
||||
}
|
||||
|
||||
|
@ -80,6 +81,7 @@ func (h Handler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoi
|
|||
return basecoin.Result{}, nil
|
||||
}
|
||||
|
||||
// SetOption - sets the genesis account balance
|
||||
func (h Handler) SetOption(l log.Logger, store types.KVStore, module, key, value string) (log string, err error) {
|
||||
if module != NameCoin {
|
||||
return "", errors.ErrUnknownModule(module)
|
||||
|
@ -103,10 +105,9 @@ func (h Handler) SetOption(l log.Logger, store types.KVStore, module, key, value
|
|||
}
|
||||
return "Success", nil
|
||||
|
||||
} else {
|
||||
msg := fmt.Sprintf("Unknown key: %s", key)
|
||||
return "", errors.ErrInternal(msg)
|
||||
}
|
||||
msg := fmt.Sprintf("Unknown key: %s", key)
|
||||
return "", errors.ErrInternal(msg)
|
||||
}
|
||||
|
||||
func checkTx(ctx basecoin.Context, tx basecoin.Tx) (send SendTx, err error) {
|
||||
|
|
|
@ -10,10 +10,13 @@ import (
|
|||
"github.com/tendermint/basecoin/types"
|
||||
)
|
||||
|
||||
// Accountant - custom object to manage coins for the coin module
|
||||
// TODO prefix should be post-fix if maintaining the same key space
|
||||
type Accountant struct {
|
||||
Prefix []byte
|
||||
}
|
||||
|
||||
// NewAccountant - create the new accountant with prefix information
|
||||
func NewAccountant(prefix string) Accountant {
|
||||
if prefix == "" {
|
||||
prefix = NameCoin
|
||||
|
@ -23,6 +26,7 @@ func NewAccountant(prefix string) Accountant {
|
|||
}
|
||||
}
|
||||
|
||||
// GetAccount - Get account from store and address
|
||||
func (a Accountant) GetAccount(store types.KVStore, addr basecoin.Actor) (Account, error) {
|
||||
acct, err := loadAccount(store, a.MakeKey(addr))
|
||||
|
||||
|
@ -68,7 +72,7 @@ func (a Accountant) updateCoins(store types.KVStore, addr basecoin.Actor, coins
|
|||
if seq != acct.Sequence+1 {
|
||||
return acct, ErrInvalidSequence()
|
||||
}
|
||||
acct.Sequence += 1
|
||||
acct.Sequence++
|
||||
}
|
||||
|
||||
// check amount
|
||||
|
@ -81,6 +85,8 @@ func (a Accountant) updateCoins(store types.KVStore, addr basecoin.Actor, coins
|
|||
return acct, nil
|
||||
}
|
||||
|
||||
// MakeKey - generate key bytes from address using accountant prefix
|
||||
// TODO Prefix -> PostFix for consistent namespace
|
||||
func (a Accountant) MakeKey(addr basecoin.Actor) []byte {
|
||||
key := addr.Bytes()
|
||||
if len(a.Prefix) > 0 {
|
||||
|
@ -89,6 +95,7 @@ func (a Accountant) MakeKey(addr basecoin.Actor) []byte {
|
|||
return key
|
||||
}
|
||||
|
||||
// Account - coin account structure
|
||||
type Account struct {
|
||||
Coins types.Coins `json:"coins"`
|
||||
Sequence int `json:"sequence"`
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/tendermint/basecoin"
|
||||
|
||||
"github.com/tendermint/basecoin/types"
|
||||
)
|
||||
|
||||
|
@ -20,12 +19,14 @@ const (
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// TxInput - expected coin movement outputs, used with SendTx
|
||||
type TxInput struct {
|
||||
Address basecoin.Actor `json:"address"`
|
||||
Coins types.Coins `json:"coins"`
|
||||
Sequence int `json:"sequence"` // Nonce: Must be 1 greater than the last committed TxInput
|
||||
}
|
||||
|
||||
// ValidateBasic - validate transaction input
|
||||
func (txIn TxInput) ValidateBasic() error {
|
||||
if txIn.Address.App == "" {
|
||||
return ErrInvalidAddress()
|
||||
|
@ -50,6 +51,7 @@ func (txIn TxInput) String() string {
|
|||
return fmt.Sprintf("TxInput{%v,%v,%v}", txIn.Address, txIn.Coins, txIn.Sequence)
|
||||
}
|
||||
|
||||
// NewTxInput - create a transaction input, used with SendTx
|
||||
func NewTxInput(addr basecoin.Actor, coins types.Coins, sequence int) TxInput {
|
||||
input := TxInput{
|
||||
Address: addr,
|
||||
|
@ -61,11 +63,13 @@ func NewTxInput(addr basecoin.Actor, coins types.Coins, sequence int) TxInput {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// TxOutput - expected coin movement output, used with SendTx
|
||||
type TxOutput struct {
|
||||
Address basecoin.Actor `json:"address"`
|
||||
Coins types.Coins `json:"coins"`
|
||||
}
|
||||
|
||||
// ValidateBasic - validate transaction output
|
||||
func (txOut TxOutput) ValidateBasic() error {
|
||||
if txOut.Address.App == "" {
|
||||
return ErrInvalidAddress()
|
||||
|
@ -87,6 +91,7 @@ func (txOut TxOutput) String() string {
|
|||
return fmt.Sprintf("TxOutput{%X,%v}", txOut.Address, txOut.Coins)
|
||||
}
|
||||
|
||||
// NewTxOutput - create a transaction output, used with SendTx
|
||||
func NewTxOutput(addr basecoin.Actor, coins types.Coins) TxOutput {
|
||||
output := TxOutput{
|
||||
Address: addr,
|
||||
|
@ -97,6 +102,8 @@ func NewTxOutput(addr basecoin.Actor, coins types.Coins) TxOutput {
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// SendTx - high level transaction of the coin module
|
||||
// Satisfies: TxInner
|
||||
type SendTx struct {
|
||||
Inputs []TxInput `json:"inputs"`
|
||||
Outputs []TxOutput `json:"outputs"`
|
||||
|
@ -104,10 +111,12 @@ type SendTx struct {
|
|||
|
||||
var _ basecoin.Tx = NewSendTx(nil, nil)
|
||||
|
||||
// NewSendTx - new SendTx
|
||||
func NewSendTx(in []TxInput, out []TxOutput) basecoin.Tx {
|
||||
return SendTx{Inputs: in, Outputs: out}.Wrap()
|
||||
}
|
||||
|
||||
// ValidateBasic - validate the send transaction
|
||||
func (tx SendTx) ValidateBasic() error {
|
||||
// this just makes sure all the inputs and outputs are properly formatted,
|
||||
// not that they actually have the money inside
|
||||
|
@ -142,6 +151,7 @@ func (tx SendTx) String() string {
|
|||
return fmt.Sprintf("SendTx{%v->%v}", tx.Inputs, tx.Outputs)
|
||||
}
|
||||
|
||||
// Wrap - used to satisfy TxInner
|
||||
func (tx SendTx) Wrap() basecoin.Tx {
|
||||
return basecoin.Tx{tx}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//nolint
|
||||
package fee
|
||||
|
||||
import (
|
||||
|
|
|
@ -7,10 +7,10 @@ import (
|
|||
"github.com/tendermint/basecoin/types"
|
||||
)
|
||||
|
||||
const (
|
||||
NameFee = "fee"
|
||||
)
|
||||
// NameFee - namespace for the fee module
|
||||
const NameFee = "fee"
|
||||
|
||||
// AccountChecker - interface used by SimpleFeeHandler
|
||||
type AccountChecker interface {
|
||||
// Get amount checks the current amount
|
||||
GetAmount(store types.KVStore, addr basecoin.Actor) (types.Coins, error)
|
||||
|
@ -20,13 +20,15 @@ type AccountChecker interface {
|
|||
ChangeAmount(store types.KVStore, addr basecoin.Actor, coins types.Coins) (types.Coins, error)
|
||||
}
|
||||
|
||||
// SimpleFeeHandler - checker object for fee checking
|
||||
type SimpleFeeHandler struct {
|
||||
AccountChecker
|
||||
MinFee types.Coins
|
||||
stack.PassOption
|
||||
}
|
||||
|
||||
func (_ SimpleFeeHandler) Name() string {
|
||||
// Name - return the namespace for the fee module
|
||||
func (SimpleFeeHandler) Name() string {
|
||||
return NameFee
|
||||
}
|
||||
|
||||
|
@ -34,6 +36,7 @@ var _ stack.Middleware = SimpleFeeHandler{}
|
|||
|
||||
// Yes, I know refactor a bit... really too late already
|
||||
|
||||
// CheckTx - check the transaction
|
||||
func (h SimpleFeeHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Checker) (res basecoin.Result, err error) {
|
||||
feeTx, ok := tx.Unwrap().(*Fee)
|
||||
if !ok {
|
||||
|
@ -57,6 +60,7 @@ func (h SimpleFeeHandler) CheckTx(ctx basecoin.Context, store types.KVStore, tx
|
|||
return basecoin.Result{Log: "Valid tx"}, nil
|
||||
}
|
||||
|
||||
// DeliverTx - send the fee handler transaction
|
||||
func (h SimpleFeeHandler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoin.Tx, next basecoin.Deliver) (res basecoin.Result, err error) {
|
||||
feeTx, ok := tx.Unwrap().(*Fee)
|
||||
if !ok {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//nolint
|
||||
package version
|
||||
|
||||
const Maj = "0"
|
||||
|
|
Loading…
Reference in New Issue