Trường hợp như thế này thì sẽ cast được
package main
import (
"fmt"
"time"
)
type Vote struct {
}
type Evidence interface {
ABCI() []Evidence // forms individual evidence to be sent to the application
Bytes() []byte // bytes which comprise the evidence
Hash() []byte // hash of the evidence
Height() int64 // height of the infraction
String() string // string format of the evidence
Time() time.Time // time of the infraction
ValidateBasic() error // basic consistency check
}
type DuplicateVoteEvidence struct {
VoteA *Vote `json:"vote_a"`
VoteB *Vote `json:"vote_b"`
// abci specific information
TotalVotingPower int64
ValidatorPower int64
Timestamp time.Time
}
func NewEvidence() Evidence {
return &DuplicateVoteEvidence{}
}
func (this *DuplicateVoteEvidence) ABCI() []Evidence { return nil}
func (this *DuplicateVoteEvidence)Bytes() []byte{return nil} // bytes which comprise the evidence
func (this *DuplicateVoteEvidence)Hash() []byte {return nil} // hash of the evidence
func (this *DuplicateVoteEvidence)Height() int64 {return 0} // height of the infraction
func (this *DuplicateVoteEvidence)String() string {return ""} // string format of the evidence
func (this *DuplicateVoteEvidence)Time() time.Time {return time.Time{}} // time of the infraction
func (this *DuplicateVoteEvidence)ValidateBasic() error{return nil} // basic consistency check
func main() {
evidenceFromEachValidator := make([]Evidence, 0)
evidenceFromEachValidator = append(evidenceFromEachValidator, NewEvidence())
// set giá trị cho evidenceFromEachValidator
for _, ev := range evidenceFromEachValidator {
_, ok := ev.(*DuplicateVoteEvidence)
if ok {
fmt.Println("Cast success")
} else {
fmt.Println("Cast fail")
}
}
}