-
Notifications
You must be signed in to change notification settings - Fork 30
/
decoder.go
31 lines (27 loc) · 960 Bytes
/
decoder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/irisnet/irismod/modules/random/types"
)
// DecodeStore unmarshals the KVPair's Value to the corresponding random type
func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], types.RandomKey):
var randomA, randomB types.Random
cdc.MustUnmarshal(kvA.Value, &randomA)
cdc.MustUnmarshal(kvB.Value, &randomB)
return fmt.Sprintf("randA: %v\nrandB: %v", randomA, randomB)
case bytes.Equal(kvA.Key[:1], types.RandomRequestQueueKey):
var requestA, requestB types.Request
cdc.MustUnmarshal(kvA.Value, &requestA)
cdc.MustUnmarshal(kvB.Value, &requestB)
return fmt.Sprintf("requestA: %v\nrequestB: %v", requestA, requestB)
default:
panic(fmt.Sprintf("invalid random key prefix %X", kvA.Key[:1]))
}
}
}