github.com/Finschia/finschia-sdk@v0.48.1/x/evidence/simulation/decoder.go (about) 1 package simulation 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "github.com/Finschia/finschia-sdk/types/kv" 8 "github.com/Finschia/finschia-sdk/x/evidence/exported" 9 "github.com/Finschia/finschia-sdk/x/evidence/types" 10 ) 11 12 type EvidenceUnmarshaler interface { 13 UnmarshalEvidence([]byte) (exported.Evidence, error) 14 } 15 16 // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's 17 // Value to the corresponding evidence type. 18 func NewDecodeStore(cdc EvidenceUnmarshaler) func(kvA, kvB kv.Pair) string { 19 return func(kvA, kvB kv.Pair) string { 20 switch { 21 case bytes.Equal(kvA.Key[:1], types.KeyPrefixEvidence): 22 evidenceA, err := cdc.UnmarshalEvidence(kvA.Value) 23 if err != nil { 24 panic(fmt.Sprintf("cannot unmarshal evidence: %s", err.Error())) 25 } 26 27 evidenceB, err := cdc.UnmarshalEvidence(kvB.Value) 28 if err != nil { 29 panic(fmt.Sprintf("cannot unmarshal evidence: %s", err.Error())) 30 } 31 32 return fmt.Sprintf("%v\n%v", evidenceA, evidenceB) 33 default: 34 panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1])) 35 } 36 } 37 }