more golint updating
This commit is contained in:
+6
-5
@@ -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()
|
||||
|
||||
+8
-4
@@ -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()
|
||||
|
||||
+13
-13
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user