OSDN Git Service

adjust format for golint (#419)
authoroysheng <33340252+oysheng@users.noreply.github.com>
Tue, 13 Mar 2018 06:06:23 +0000 (14:06 +0800)
committerPaladz <yzhu101@uottawa.ca>
Tue, 13 Mar 2018 06:06:23 +0000 (14:06 +0800)
* standard transaction reserve utxo filter out contract utxo

* distinguish StandardUTXO and ContractUTXO
modfiy spendUTXOAction into no account, the contract utxo is not need to sign
wallet add contract utxo db
adjust function parameter format: the end of parameter is error

* delete ExtContractTag because contract utxo is stored in ContractUTXO

* spendUTXOAction add situation when account is empty
prevoutDBKeys delete return value
filterAccountTxs filter contract transaction to reduce unrelated transaction

* fix golint for blockchain/account/reserve.go

* optimise the import

* adjust format for golint

* adjust format

blockchain/account/accounts.go
blockchain/asset/asset_test.go
blockchain/rpc/net.go
blockchain/txbuilder/txbuilder.go
blockchain/wallet/indexer.go
protocol/txpool.go
protocol/validation/validation_test.go

index a0e3189..8f4641d 100755 (executable)
@@ -5,6 +5,8 @@ import (
        "context"
        "encoding/binary"
        "encoding/json"
+       "sort"
+       "strings"
        "sync"
        "time"
 
@@ -22,8 +24,6 @@ import (
        "github.com/bytom/errors"
        "github.com/bytom/protocol"
        "github.com/bytom/protocol/vm/vmutil"
-       "sort"
-       "strings"
 )
 
 const (
@@ -31,7 +31,6 @@ const (
        aliasPrefix     = "ALI:"
        accountPrefix   = "ACC:"
        accountCPPrefix = "ACP:"
-       keyNextIndex    = "NextIndex"
        indexPrefix     = "ACIDX:"
 )
 
@@ -41,7 +40,6 @@ var (
        ErrFindAccount    = errors.New("fail to find account")
        ErrMarshalAccount = errors.New("failed marshal account")
        ErrMarshalTags    = errors.New("failed marshal account to update tags")
-       ErrStandardQuorum = errors.New("need single key pair account to create standard transaction")
 )
 
 func aliasKey(name string) []byte {
@@ -400,7 +398,7 @@ func (m *Manager) nextIndex(account *Account) uint64 {
        m.acpMu.Lock()
        defer m.acpMu.Unlock()
 
-       key := make([]byte, 0)
+       var key []byte
        key = append(key, account.Signer.XPubs[0].Bytes()...)
 
        accountIndex := make([]byte, 8)
index a102124..babaafe 100644 (file)
@@ -29,7 +29,7 @@ func TestDefineAsset(t *testing.T) {
        }
 
        if !testutil.DeepEqual(asset, found) {
-               t.Errorf("expected asset %s to be recorded as %s", asset, found)
+               t.Errorf("expected asset %v to be recorded as %v", asset, found)
        }
 }
 
index dbb6a88..309c50b 100644 (file)
@@ -5,8 +5,7 @@ import (
        "github.com/bytom/p2p"
 )
 
-//-----------------------------------------------------------------------------
-
+// NetInfo return p2p net status
 func NetInfo(p2pSwitch *p2p.Switch) (*ctypes.ResultNetInfo, error) {
        listening := p2pSwitch.IsListening()
        listeners := []string{}
index f856f8d..5752e9b 100755 (executable)
@@ -17,13 +17,20 @@ import (
 
 // errors
 var (
-       ErrBadRefData          = errors.New("transaction reference data does not match previous template's reference data")
-       ErrBadTxInputIdx       = errors.New("unsigned tx missing input")
+       //ErrBadRefData means invalid reference data
+       ErrBadRefData = errors.New("transaction reference data does not match previous template's reference data")
+       //ErrBadTxInputIdx means unsigned tx input
+       ErrBadTxInputIdx = errors.New("unsigned tx missing input")
+       //ErrBadWitnessComponent means invalid witness component
        ErrBadWitnessComponent = errors.New("invalid witness component")
-       ErrBadAmount           = errors.New("bad asset amount")
-       ErrBlankCheck          = errors.New("unsafe transaction: leaves assets free to control")
-       ErrAction              = errors.New("errors occurred in one or more actions")
-       ErrMissingFields       = errors.New("required field is missing")
+       //ErrBadAmount means invalid asset amount
+       ErrBadAmount = errors.New("bad asset amount")
+       //ErrBlankCheck means unsafe transaction
+       ErrBlankCheck = errors.New("unsafe transaction: leaves assets free to control")
+       //ErrAction means errors occurred in actions
+       ErrAction = errors.New("errors occurred in one or more actions")
+       //ErrMissingFields means missing required fields
+       ErrMissingFields = errors.New("required field is missing")
 )
 
 // Build builds or adds on to a transaction.
index 77348aa..0d0cedd 100755 (executable)
@@ -63,7 +63,7 @@ func calcTxIndexKey(txID string) []byte {
        return []byte(TxIndexPrefix + txID)
 }
 
-//deleteTransaction delete transactions when orphan block rollback
+// deleteTransaction delete transactions when orphan block rollback
 func (w *Wallet) deleteTransactions(batch db.Batch, height uint64) {
        tmpTx := query.AnnotatedTx{}
 
@@ -72,7 +72,7 @@ func (w *Wallet) deleteTransactions(batch db.Batch, height uint64) {
 
        for txIter.Next() {
                if err := json.Unmarshal(txIter.Value(), &tmpTx); err == nil {
-                       //delete index
+                       // delete index
                        batch.Delete(calcTxIndexKey(tmpTx.ID.String()))
                }
 
@@ -80,17 +80,17 @@ func (w *Wallet) deleteTransactions(batch db.Batch, height uint64) {
        }
 }
 
-//ReverseAccountUTXOs process the invalid blocks when orphan block rollback
+// ReverseAccountUTXOs process the invalid blocks when orphan block rollback
 func (w *Wallet) reverseAccountUTXOs(batch db.Batch, b *legacy.Block, txStatus *bc.TransactionStatus) {
        var err error
 
-       //unknow how many spent and retire outputs
+       // unknow how many spent and retire outputs
        reverseOuts := make([]*rawOutput, 0)
 
-       //handle spent UTXOs
+       // handle spent UTXOs
        for txIndex, tx := range b.Transactions {
                for _, inpID := range tx.Tx.InputIDs {
-                       //spend and retire
+                       // spend and retire
                        sp, err := tx.Spend(inpID)
                        if err != nil {
                                continue
@@ -125,13 +125,13 @@ func (w *Wallet) reverseAccountUTXOs(batch db.Batch, b *legacy.Block, txStatus *
                return
        }
 
-       //handle new UTXOs
+       // handle new UTXOs
        for _, tx := range b.Transactions {
                for j := range tx.Outputs {
                        resOutID := tx.ResultIds[j]
                        resOut, ok := tx.Entries[*resOutID].(*bc.Output)
                        if !ok {
-                               //retirement
+                               // retirement
                                continue
                        }
 
@@ -146,9 +146,9 @@ func (w *Wallet) reverseAccountUTXOs(batch db.Batch, b *legacy.Block, txStatus *
        }
 }
 
-//save external and local assets definition,
-//when query ,query local first and if have no then query external
-//details see getAliasDefinition
+// saveExternalAssetDefinition save external and local assets definition,
+// when query ,query local first and if have no then query external
+// details see getAliasDefinition
 func saveExternalAssetDefinition(b *legacy.Block, walletDB db.DB) {
        storeBatch := walletDB.NewBatch()
        defer storeBatch.Write()
@@ -168,7 +168,7 @@ func saveExternalAssetDefinition(b *legacy.Block, walletDB db.DB) {
        }
 }
 
-// Summary is ....
+// Summary is the struct of transaction's input and output summary
 type Summary struct {
        Type         string             `json:"type"`
        AssetID      bc.AssetID         `json:"asset_id,omitempty"`
@@ -179,7 +179,7 @@ type Summary struct {
        Arbitrary    chainjson.HexBytes `json:"arbitrary,omitempty"`
 }
 
-// TxSummary is ....
+// TxSummary is the struct of transaction summary
 type TxSummary struct {
        ID        bc.Hash   `json:"id"`
        Timestamp time.Time `json:"timestamp"`
@@ -187,7 +187,7 @@ type TxSummary struct {
        Outputs   []Summary `json:"outputs"`
 }
 
-//indexTransactions saves all annotated transactions to the database.
+// indexTransactions saves all annotated transactions to the database.
 func (w *Wallet) indexTransactions(batch db.Batch, b *legacy.Block, txStatus *bc.TransactionStatus) error {
        annotatedTxs := w.filterAccountTxs(b, txStatus)
        saveExternalAssetDefinition(b, w.DB)
@@ -207,12 +207,12 @@ func (w *Wallet) indexTransactions(batch db.Batch, b *legacy.Block, txStatus *bc
        return nil
 }
 
-//buildAccountUTXOs process valid blocks to build account unspent outputs db
+// buildAccountUTXOs process valid blocks to build account unspent outputs db
 func (w *Wallet) buildAccountUTXOs(batch db.Batch, b *legacy.Block, txStatus *bc.TransactionStatus) {
        // get the spent UTXOs and delete the UTXOs from DB
        prevoutDBKeys(batch, b, txStatus)
 
-       //handle new UTXOs
+       // handle new UTXOs
        outs := make([]*rawOutput, 0, len(b.Transactions))
        for txIndex, tx := range b.Transactions {
                for j, out := range tx.Outputs {
@@ -236,7 +236,7 @@ func (w *Wallet) buildAccountUTXOs(batch db.Batch, b *legacy.Block, txStatus *bc
                                refData:        *resOut.Data,
                        }
 
-                       //coinbase utxo valid height
+                       // coinbase utxo valid height
                        if txIndex == 0 {
                                out.ValidHeight = b.Height + consensus.CoinbasePendingBlockNumber
                        }
@@ -299,7 +299,7 @@ func loadAccountInfo(outs []*rawOutput, w *Wallet) []*accountOutput {
 
        var hash [32]byte
        for s := range outsByScript {
-               //smart contract UTXO
+               // smart contract UTXO
                if !segwit.IsP2WScript([]byte(s)) {
                        for _, out := range outsByScript[s] {
                                newOut := &accountOutput{
@@ -381,7 +381,7 @@ func upsertConfirmedAccountOutputs(outs []*accountOutput, batch db.Batch) error
        return nil
 }
 
-// filt related and build the fully annotated transactions.
+// filterAccountTxs related and build the fully annotated transactions.
 func (w *Wallet) filterAccountTxs(b *legacy.Block, txStatus *bc.TransactionStatus) []*query.AnnotatedTx {
        annotatedTxs := make([]*query.AnnotatedTx, 0, len(b.Transactions))
        for pos, tx := range b.Transactions {
@@ -417,7 +417,7 @@ func (w *Wallet) filterAccountTxs(b *legacy.Block, txStatus *bc.TransactionStatu
        return annotatedTxs
 }
 
-//GetTransactionsByTxID get account txs by account tx ID
+// GetTransactionsByTxID get account txs by account tx ID
 func (w *Wallet) GetTransactionsByTxID(txID string) ([]*query.AnnotatedTx, error) {
        annotatedTxs := []*query.AnnotatedTx{}
        formatKey := ""
@@ -443,7 +443,7 @@ func (w *Wallet) GetTransactionsByTxID(txID string) ([]*query.AnnotatedTx, error
        return annotatedTxs, nil
 }
 
-//GetTransactionsSummary get transactions summary
+// GetTransactionsSummary get transactions summary
 func (w *Wallet) GetTransactionsSummary(transactions []*query.AnnotatedTx) []TxSummary {
        Txs := make([]TxSummary, 0)
 
@@ -495,7 +495,7 @@ func findTransactionsByAccount(annotatedTx *query.AnnotatedTx, accountID string)
        return false
 }
 
-//GetTransactionsByAccountID get account txs by account ID
+// GetTransactionsByAccountID get account txs by account ID
 func (w *Wallet) GetTransactionsByAccountID(accountID string) ([]*query.AnnotatedTx, error) {
        annotatedTxs := []*query.AnnotatedTx{}
 
@@ -515,7 +515,7 @@ func (w *Wallet) GetTransactionsByAccountID(accountID string) ([]*query.Annotate
        return annotatedTxs, nil
 }
 
-//GetAccountUTXOs return all account unspent outputs
+// GetAccountUTXOs return all account unspent outputs
 func (w *Wallet) GetAccountUTXOs(id string) ([]account.UTXO, error) {
        accountUTXO := account.UTXO{}
        accountUTXOs := make([]account.UTXO, 0)
index 25a7e7a..0d20e75 100644 (file)
@@ -20,8 +20,10 @@ var (
        maxCachedErrTxs = 1000
        maxNewTxChSize  = 1000
        maxNewTxNum     = 10000
+
        // ErrTransactionNotExist is the pre-defined error message
        ErrTransactionNotExist = errors.New("transaction are not existed in the mempool")
+       // ErrPoolIsFull indicates the pool is full
        ErrPoolIsFull          = errors.New("transaction pool reach the max number")
 )
 
@@ -94,7 +96,7 @@ func (mp *TxPool) AddTransaction(tx *legacy.Tx, gasOnlyTx bool, height, fee uint
        }
 
        mp.newTxCh <- tx
-       log.WithField("tx_id", tx.Tx.ID).Info("Add tx to mempool")
+       log.WithField("tx_id", tx.Tx.ID.String()).Info("Add tx to mempool")
        return txD, nil
 }
 
index 30c421b..1beeb49 100644 (file)
@@ -442,7 +442,7 @@ func TestValidateBlock(t *testing.T) {
        for _, c := range cases {
                txRoot, err := bc.MerkleRoot(c.block.Transactions)
                if err != nil {
-                       t.Errorf("computing transaction merkle root", err)
+                       t.Errorf("computing transaction merkle root error: %v", err)
                        continue
                }
                c.block.BlockHeader.TransactionStatus = bc.NewTransactionStatus()
@@ -624,9 +624,9 @@ func sample(tb testing.TB, in *txFixture) *txFixture {
        }
 
        result.tx = &legacy.TxData{
-               Version:       result.txVersion,
-               Inputs:        result.txInputs,
-               Outputs:       result.txOutputs,
+               Version: result.txVersion,
+               Inputs:  result.txInputs,
+               Outputs: result.txOutputs,
        }
 
        return &result