code.vegaprotocol.io/vega@v0.79.0/cmd/vegatools/checktx.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package tools
    17  
    18  import (
    19  	"fmt"
    20  
    21  	"code.vegaprotocol.io/vega/core/config"
    22  	"code.vegaprotocol.io/vega/vegatools/checktx"
    23  
    24  	"github.com/sirupsen/logrus"
    25  )
    26  
    27  type checkTxCmd struct {
    28  	config.OutputFlag
    29  	EncodedTransaction string `description:"The encoded transaction string to compare with vega's own encoding"                         long:"tx"    short:"t"`
    30  	TransactionDir     string `description:"directory containing files with encoded transaction data. One encoded transaction per file" long:"txdir" short:"d"`
    31  }
    32  
    33  func (opts *checkTxCmd) Execute(_ []string) error {
    34  	if opts.EncodedTransaction != "" {
    35  		return checktx.CheckTransaction(opts.EncodedTransaction)
    36  	}
    37  
    38  	if opts.TransactionDir != "" {
    39  		result, err := checktx.CheckTransactionsInDirectory(opts.TransactionDir)
    40  		if err != nil {
    41  			return fmt.Errorf("there was an issue when checking transactions\nerr: %w", err)
    42  		}
    43  
    44  		logrus.Infof("transactions analysed %d, transactions passed: %d, transactions failed: %d", result.TransactionsAnalysed, result.TransactionsPassed, result.TransactionsFailed)
    45  		if result.TransactionsFailed > 0 {
    46  			return fmt.Errorf("one or more transactions failed comparison")
    47  		} else {
    48  			return nil
    49  		}
    50  	}
    51  
    52  	return fmt.Errorf("no valid arg provided")
    53  }