github.com/DFWallet/tendermint-cosmos@v0.0.2/rpc/core/evidence.go (about)

     1  package core
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	ctypes "github.com/DFWallet/tendermint-cosmos/rpc/core/types"
     8  	rpctypes "github.com/DFWallet/tendermint-cosmos/rpc/jsonrpc/types"
     9  	"github.com/DFWallet/tendermint-cosmos/types"
    10  )
    11  
    12  // BroadcastEvidence broadcasts evidence of the misbehavior.
    13  // More: https://docs.tendermint.com/master/rpc/#/Info/broadcast_evidence
    14  func BroadcastEvidence(ctx *rpctypes.Context, ev types.Evidence) (*ctypes.ResultBroadcastEvidence, error) {
    15  	if ev == nil {
    16  		return nil, errors.New("no evidence was provided")
    17  	}
    18  
    19  	if err := ev.ValidateBasic(); err != nil {
    20  		return nil, fmt.Errorf("evidence.ValidateBasic failed: %w", err)
    21  	}
    22  
    23  	if err := env.EvidencePool.AddEvidence(ev); err != nil {
    24  		return nil, fmt.Errorf("failed to add evidence: %w", err)
    25  	}
    26  	return &ctypes.ResultBroadcastEvidence{Hash: ev.Hash()}, nil
    27  }