more golint updating
This commit is contained in:
parent
58bc1e3cf8
commit
82c0f98235
|
@ -19,15 +19,15 @@ func (h holder) Unwrap() validate {
|
|||
return h.validate
|
||||
}
|
||||
|
||||
type DemoTx struct {
|
||||
type demoTx struct {
|
||||
Age int
|
||||
}
|
||||
|
||||
func (t DemoTx) Wrap() holder {
|
||||
func (t demoTx) Wrap() holder {
|
||||
return holder{t}
|
||||
}
|
||||
|
||||
func (t DemoTx) ValidateBasic() error {
|
||||
func (t demoTx) ValidateBasic() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ func TestErrorMatches(t *testing.T) {
|
|||
{errWrongChain, ErrWrongChain("hakz"), true},
|
||||
{errUnknownTxType, ErrUnknownTxType(holder{}), true},
|
||||
{errUnknownTxType, ErrUnknownTxType("some text here..."), true},
|
||||
{errUnknownTxType, ErrUnknownTxType(DemoTx{5}.Wrap()), true},
|
||||
{errUnknownTxType, ErrUnknownTxType(demoTx{5}.Wrap()), true},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
package auth contains generic Signable implementations that can be used
|
||||
Package auth contains generic Signable implementations that can be used
|
||||
by your application or tests to handle authentication needs.
|
||||
|
||||
It currently supports transaction data as opaque bytes and either single
|
||||
|
@ -63,6 +63,7 @@ type OneSig struct {
|
|||
Signed `json:"signature"`
|
||||
}
|
||||
|
||||
//Interfaces to fulfill
|
||||
var _ keys.Signable = &OneSig{}
|
||||
var _ basecoin.TxLayer = &OneSig{}
|
||||
|
||||
|
@ -71,14 +72,13 @@ func NewSig(tx basecoin.Tx) *OneSig {
|
|||
return &OneSig{Tx: tx}
|
||||
}
|
||||
|
||||
//nolint
|
||||
func (s *OneSig) Wrap() basecoin.Tx {
|
||||
return basecoin.Tx{s}
|
||||
}
|
||||
|
||||
func (s *OneSig) Next() basecoin.Tx {
|
||||
return s.Tx
|
||||
}
|
||||
|
||||
func (s *OneSig) ValidateBasic() error {
|
||||
return s.Tx.ValidateBasic()
|
||||
}
|
||||
|
@ -135,6 +135,7 @@ type MultiSig struct {
|
|||
Sigs []Signed `json:"signatures"`
|
||||
}
|
||||
|
||||
//Interfaces to fulfill
|
||||
var _ keys.Signable = &MultiSig{}
|
||||
var _ basecoin.TxLayer = &MultiSig{}
|
||||
|
||||
|
@ -143,14 +144,13 @@ func NewMulti(tx basecoin.Tx) *MultiSig {
|
|||
return &MultiSig{Tx: tx}
|
||||
}
|
||||
|
||||
// nolint
|
||||
func (s *MultiSig) Wrap() basecoin.Tx {
|
||||
return basecoin.Tx{s}
|
||||
}
|
||||
|
||||
func (s *MultiSig) Next() basecoin.Tx {
|
||||
return s.Tx
|
||||
}
|
||||
|
||||
func (s *MultiSig) ValidateBasic() error {
|
||||
return s.Tx.ValidateBasic()
|
||||
}
|
||||
|
@ -204,6 +204,7 @@ func (s *MultiSig) Signers() ([]crypto.PubKey, error) {
|
|||
return keys, nil
|
||||
}
|
||||
|
||||
// Sign - sign the transaction with private key
|
||||
func Sign(tx keys.Signable, key crypto.PrivKey) error {
|
||||
msg := tx.SignBytes()
|
||||
pubkey := key.PubKey()
|
||||
|
|
|
@ -21,19 +21,24 @@ func init() {
|
|||
RegisterImplementation(ChainTx{}, TypeChainTx, ByteChainTx)
|
||||
}
|
||||
|
||||
//Interfaces to fulfill
|
||||
var _ basecoin.TxInner = &MultiTx{}
|
||||
var _ basecoin.TxInner = &ChainTx{}
|
||||
|
||||
/**** MultiTx ******/
|
||||
|
||||
// MultiTx - a transaction containing multiple transactions
|
||||
type MultiTx struct {
|
||||
Txs []basecoin.Tx `json:"txs"`
|
||||
}
|
||||
|
||||
//nolint - TxInner Functions
|
||||
func NewMultiTx(txs ...basecoin.Tx) basecoin.Tx {
|
||||
return (MultiTx{Txs: txs}).Wrap()
|
||||
}
|
||||
|
||||
func (mt MultiTx) Wrap() basecoin.Tx {
|
||||
return basecoin.Tx{mt}
|
||||
}
|
||||
|
||||
func (mt MultiTx) ValidateBasic() error {
|
||||
for _, t := range mt.Txs {
|
||||
err := t.ValidateBasic()
|
||||
|
@ -52,14 +57,13 @@ type ChainTx struct {
|
|||
ChainID string `json:"chain_id"`
|
||||
}
|
||||
|
||||
//nolint - TxInner Functions
|
||||
func NewChainTx(chainID string, tx basecoin.Tx) basecoin.Tx {
|
||||
return (ChainTx{Tx: tx, ChainID: chainID}).Wrap()
|
||||
}
|
||||
|
||||
func (c ChainTx) Wrap() basecoin.Tx {
|
||||
return basecoin.Tx{c}
|
||||
}
|
||||
|
||||
func (c ChainTx) ValidateBasic() error {
|
||||
// TODO: more checks? chainID?
|
||||
return c.Tx.ValidateBasic()
|
||||
|
|
|
@ -118,10 +118,10 @@ func (coins Coins) IsValid() bool {
|
|||
//
|
||||
// TODO: handle empty coins!
|
||||
// Currently appends an empty coin ...
|
||||
func (coinsA Coins) Plus(coinsB Coins) Coins {
|
||||
func (coins Coins) Plus(coinsB Coins) Coins {
|
||||
sum := []Coin{}
|
||||
indexA, indexB := 0, 0
|
||||
lenA, lenB := len(coinsA), len(coinsB)
|
||||
lenA, lenB := len(coins), len(coinsB)
|
||||
for {
|
||||
if indexA == lenA {
|
||||
if indexB == lenB {
|
||||
|
@ -129,9 +129,9 @@ func (coinsA Coins) Plus(coinsB Coins) Coins {
|
|||
}
|
||||
return append(sum, coinsB[indexB:]...)
|
||||
} else if indexB == lenB {
|
||||
return append(sum, coinsA[indexA:]...)
|
||||
return append(sum, coins[indexA:]...)
|
||||
}
|
||||
coinA, coinB := coinsA[indexA], coinsB[indexB]
|
||||
coinA, coinB := coins[indexA], coinsB[indexB]
|
||||
switch strings.Compare(coinA.Denom, coinB.Denom) {
|
||||
case -1:
|
||||
sum = append(sum, coinA)
|
||||
|
@ -168,15 +168,15 @@ func (coins Coins) Negative() Coins {
|
|||
}
|
||||
|
||||
// Minus subtracts a set of coins from another (adds the inverse)
|
||||
func (coinsA Coins) Minus(coinsB Coins) Coins {
|
||||
return coinsA.Plus(coinsB.Negative())
|
||||
func (coins Coins) Minus(coinsB Coins) Coins {
|
||||
return coins.Plus(coinsB.Negative())
|
||||
}
|
||||
|
||||
// IsGTE returns True iff coinsA is NonNegative(), and for every
|
||||
// IsGTE returns True iff coins is NonNegative(), and for every
|
||||
// currency in coinsB, the currency is present at an equal or greater
|
||||
// amount in coinsB
|
||||
func (coinsA Coins) IsGTE(coinsB Coins) bool {
|
||||
diff := coinsA.Minus(coinsB)
|
||||
func (coins Coins) IsGTE(coinsB Coins) bool {
|
||||
diff := coins.Minus(coinsB)
|
||||
if len(diff) == 0 {
|
||||
return true
|
||||
}
|
||||
|
@ -189,12 +189,12 @@ func (coins Coins) IsZero() bool {
|
|||
}
|
||||
|
||||
// IsEqual returns true if the two sets of Coins have the same value
|
||||
func (coinsA Coins) IsEqual(coinsB Coins) bool {
|
||||
if len(coinsA) != len(coinsB) {
|
||||
func (coins Coins) IsEqual(coinsB Coins) bool {
|
||||
if len(coins) != len(coinsB) {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < len(coinsA); i++ {
|
||||
if coinsA[i] != coinsB[i] {
|
||||
for i := 0; i < len(coins); i++ {
|
||||
if coins[i] != coinsB[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ func init() {
|
|||
|
||||
/**** Fee ****/
|
||||
|
||||
var _ basecoin.TxLayer = &Fee{}
|
||||
|
||||
// Fee attaches a fee payment to the embedded tx
|
||||
type Fee struct {
|
||||
Tx basecoin.Tx `json:"tx"`
|
||||
|
@ -26,19 +28,17 @@ type Fee struct {
|
|||
// Gas coin.Coin `json:"gas"` // ?????
|
||||
}
|
||||
|
||||
// nolint - TxInner Functions
|
||||
func NewFee(tx basecoin.Tx, fee coin.Coin, payer basecoin.Actor) basecoin.Tx {
|
||||
return (&Fee{Tx: tx, Fee: fee, Payer: payer}).Wrap()
|
||||
}
|
||||
|
||||
func (f *Fee) ValidateBasic() error {
|
||||
// TODO: more checks
|
||||
return f.Tx.ValidateBasic()
|
||||
}
|
||||
|
||||
func (f *Fee) Wrap() basecoin.Tx {
|
||||
return basecoin.Tx{f}
|
||||
}
|
||||
|
||||
func (f *Fee) Next() basecoin.Tx {
|
||||
return f.Tx
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/basecoin/tests"
|
||||
"github.com/tendermint/go-wire"
|
||||
)
|
||||
|
|
|
@ -9,11 +9,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
"github.com/tendermint/tendermint/rpc/lib/client"
|
||||
"github.com/tendermint/tendermint/rpc/lib/types"
|
||||
"github.com/tendermint/go-wire"
|
||||
_ "github.com/tendermint/tendermint/rpc/core/types" // Register RPCResponse > Result types
|
||||
"github.com/tendermint/tendermint/rpc/lib/client"
|
||||
"github.com/tendermint/tendermint/rpc/lib/types"
|
||||
cmn "github.com/tendermint/tmlibs/common"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -23,6 +23,7 @@ type secureContext struct {
|
|||
log.Logger
|
||||
}
|
||||
|
||||
// NewContext - create a new secureContext
|
||||
func NewContext(chain string, logger log.Logger) basecoin.Context {
|
||||
return secureContext{
|
||||
id: nonce(rand.Int63()),
|
||||
|
|
|
@ -33,10 +33,15 @@ type RawTx struct {
|
|||
data.Bytes
|
||||
}
|
||||
|
||||
var _ basecoin.TxInner = RawTx{}
|
||||
|
||||
// nolint
|
||||
func NewRawTx(d []byte) basecoin.Tx {
|
||||
return RawTx{data.Bytes(d)}.Wrap()
|
||||
}
|
||||
func (r RawTx) Wrap() basecoin.Tx {
|
||||
return basecoin.Tx{r}
|
||||
}
|
||||
|
||||
func (r RawTx) ValidateBasic() error {
|
||||
if len(r.Bytes) > rawMaxSize {
|
||||
return errors.ErrTooLarge()
|
||||
|
@ -44,10 +49,6 @@ func (r RawTx) ValidateBasic() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewRawTx(d []byte) basecoin.Tx {
|
||||
return RawTx{data.Bytes(d)}.Wrap()
|
||||
}
|
||||
|
||||
// OKHandler just used to return okay to everything
|
||||
type OKHandler struct {
|
||||
Log string
|
||||
|
@ -56,7 +57,8 @@ type OKHandler struct {
|
|||
|
||||
var _ basecoin.Handler = OKHandler{}
|
||||
|
||||
func (_ OKHandler) Name() string {
|
||||
// Name - return handler's name
|
||||
func (OKHandler) Name() string {
|
||||
return NameOK
|
||||
}
|
||||
|
||||
|
@ -77,18 +79,19 @@ type EchoHandler struct {
|
|||
|
||||
var _ basecoin.Handler = EchoHandler{}
|
||||
|
||||
func (_ EchoHandler) Name() string {
|
||||
// Name - return handler's name
|
||||
func (EchoHandler) Name() string {
|
||||
return NameEcho
|
||||
}
|
||||
|
||||
// CheckTx always returns an empty success tx
|
||||
func (_ EchoHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (EchoHandler) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
data, err := data.ToWire(tx)
|
||||
return basecoin.Result{Data: data}, err
|
||||
}
|
||||
|
||||
// DeliverTx always returns an empty success tx
|
||||
func (_ EchoHandler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
func (EchoHandler) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx) (res basecoin.Result, err error) {
|
||||
data, err := data.ToWire(tx)
|
||||
return basecoin.Result{Data: data}, err
|
||||
}
|
||||
|
@ -101,7 +104,8 @@ type FailHandler struct {
|
|||
|
||||
var _ basecoin.Handler = FailHandler{}
|
||||
|
||||
func (_ FailHandler) Name() string {
|
||||
// Name - return handler's name
|
||||
func (FailHandler) Name() string {
|
||||
return NameFail
|
||||
}
|
||||
|
||||
|
@ -124,7 +128,8 @@ type PanicHandler struct {
|
|||
|
||||
var _ basecoin.Handler = PanicHandler{}
|
||||
|
||||
func (_ PanicHandler) Name() string {
|
||||
// Name - return handler's name
|
||||
func (PanicHandler) Name() string {
|
||||
return NamePanic
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//nolint
|
||||
package stack
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//nolint
|
||||
package stack
|
||||
|
||||
import (
|
||||
|
@ -19,57 +20,70 @@ type Middleware interface {
|
|||
}
|
||||
|
||||
type CheckerMiddle interface {
|
||||
CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error)
|
||||
CheckTx(ctx basecoin.Context, store state.KVStore,
|
||||
tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error)
|
||||
}
|
||||
|
||||
type CheckerMiddleFunc func(basecoin.Context, state.KVStore, basecoin.Tx, basecoin.Checker) (basecoin.Result, error)
|
||||
type CheckerMiddleFunc func(basecoin.Context, state.KVStore,
|
||||
basecoin.Tx, basecoin.Checker) (basecoin.Result, error)
|
||||
|
||||
func (c CheckerMiddleFunc) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) {
|
||||
func (c CheckerMiddleFunc) CheckTx(ctx basecoin.Context, store state.KVStore,
|
||||
tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) {
|
||||
return c(ctx, store, tx, next)
|
||||
}
|
||||
|
||||
type DeliverMiddle interface {
|
||||
DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error)
|
||||
DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx,
|
||||
next basecoin.Deliver) (basecoin.Result, error)
|
||||
}
|
||||
|
||||
type DeliverMiddleFunc func(basecoin.Context, state.KVStore, basecoin.Tx, basecoin.Deliver) (basecoin.Result, error)
|
||||
type DeliverMiddleFunc func(basecoin.Context, state.KVStore,
|
||||
basecoin.Tx, basecoin.Deliver) (basecoin.Result, error)
|
||||
|
||||
func (d DeliverMiddleFunc) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) {
|
||||
func (d DeliverMiddleFunc) DeliverTx(ctx basecoin.Context, store state.KVStore,
|
||||
tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) {
|
||||
return d(ctx, store, tx, next)
|
||||
}
|
||||
|
||||
type SetOptionMiddle interface {
|
||||
SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error)
|
||||
SetOption(l log.Logger, store state.KVStore, module,
|
||||
key, value string, next basecoin.SetOptioner) (string, error)
|
||||
}
|
||||
|
||||
type SetOptionMiddleFunc func(log.Logger, state.KVStore, string, string, string, basecoin.SetOptioner) (string, error)
|
||||
type SetOptionMiddleFunc func(log.Logger, state.KVStore,
|
||||
string, string, string, basecoin.SetOptioner) (string, error)
|
||||
|
||||
func (c SetOptionMiddleFunc) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) {
|
||||
func (c SetOptionMiddleFunc) SetOption(l log.Logger, store state.KVStore,
|
||||
module, key, value string, next basecoin.SetOptioner) (string, error) {
|
||||
return c(l, store, module, key, value, next)
|
||||
}
|
||||
|
||||
// holders
|
||||
type PassCheck struct{}
|
||||
|
||||
func (_ PassCheck) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) {
|
||||
func (_ PassCheck) CheckTx(ctx basecoin.Context, store state.KVStore,
|
||||
tx basecoin.Tx, next basecoin.Checker) (basecoin.Result, error) {
|
||||
return next.CheckTx(ctx, store, tx)
|
||||
}
|
||||
|
||||
type PassDeliver struct{}
|
||||
|
||||
func (_ PassDeliver) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) {
|
||||
func (_ PassDeliver) DeliverTx(ctx basecoin.Context, store state.KVStore,
|
||||
tx basecoin.Tx, next basecoin.Deliver) (basecoin.Result, error) {
|
||||
return next.DeliverTx(ctx, store, tx)
|
||||
}
|
||||
|
||||
type PassOption struct{}
|
||||
|
||||
func (_ PassOption) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) {
|
||||
func (_ PassOption) SetOption(l log.Logger, store state.KVStore, module,
|
||||
key, value string, next basecoin.SetOptioner) (string, error) {
|
||||
return next.SetOption(l, store, module, key, value)
|
||||
}
|
||||
|
||||
type NopOption struct{}
|
||||
|
||||
func (_ NopOption) SetOption(l log.Logger, store state.KVStore, module, key, value string, next basecoin.SetOptioner) (string, error) {
|
||||
func (_ NopOption) SetOption(l log.Logger, store state.KVStore, module,
|
||||
key, value string, next basecoin.SetOptioner) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
|
@ -98,14 +112,17 @@ func (w wrapped) Name() string {
|
|||
return w.h.Name()
|
||||
}
|
||||
|
||||
func (w wrapped) CheckTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, _ basecoin.Checker) (basecoin.Result, error) {
|
||||
func (w wrapped) CheckTx(ctx basecoin.Context, store state.KVStore,
|
||||
tx basecoin.Tx, _ basecoin.Checker) (basecoin.Result, error) {
|
||||
return w.h.CheckTx(ctx, store, tx)
|
||||
}
|
||||
|
||||
func (w wrapped) DeliverTx(ctx basecoin.Context, store state.KVStore, tx basecoin.Tx, _ basecoin.Deliver) (basecoin.Result, error) {
|
||||
func (w wrapped) DeliverTx(ctx basecoin.Context, store state.KVStore,
|
||||
tx basecoin.Tx, _ basecoin.Deliver) (basecoin.Result, error) {
|
||||
return w.h.DeliverTx(ctx, store, tx)
|
||||
}
|
||||
|
||||
func (w wrapped) SetOption(l log.Logger, store state.KVStore, module, key, value string, _ basecoin.SetOptioner) (string, error) {
|
||||
func (w wrapped) SetOption(l log.Logger, store state.KVStore,
|
||||
module, key, value string, _ basecoin.SetOptioner) (string, error) {
|
||||
return w.h.SetOption(l, store, module, key, value)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue