github.com/adoriasoft/tendermint@v0.34.0-dev1.0.20200722151356-96d84601a75a/rpc/core/evidence.go (about)

     1  package core
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	ctypes "github.com/tendermint/tendermint/rpc/core/types"
     8  	rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types"
     9  	"github.com/tendermint/tendermint/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  }