-
Notifications
You must be signed in to change notification settings - Fork 55
/
decoder.go
44 lines (36 loc) 路 1.18 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/crescent-network/crescent/v4/x/lpfarm/types"
)
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.PlanKeyPrefix):
var pA, pB types.Plan
cdc.MustUnmarshal(kvA.Value, &pA)
cdc.MustUnmarshal(kvB.Value, &pB)
return fmt.Sprintf("%v\n%v", pA, pB)
case bytes.Equal(kvA.Key[:1], types.FarmKeyPrefix):
var fA, fB types.Farm
cdc.MustUnmarshal(kvA.Value, &fA)
cdc.MustUnmarshal(kvB.Value, &fB)
return fmt.Sprintf("%v\n%v", fA, fB)
case bytes.Equal(kvA.Key[:1], types.PositionKeyPrefix):
var pA, pB types.Position
cdc.MustUnmarshal(kvA.Value, &pA)
cdc.MustUnmarshal(kvB.Value, &pB)
return fmt.Sprintf("%v\n%v", pA, pB)
case bytes.Equal(kvA.Key[:1], types.HistoricalRewardsKeyPrefix):
var hA, hB types.HistoricalRewards
cdc.MustUnmarshal(kvA.Value, &hA)
cdc.MustUnmarshal(kvB.Value, &hB)
return fmt.Sprintf("%v\n%v", hA, hB)
default:
panic(fmt.Sprintf("invalid lpfarm key prefix %X", kvA.Key[:1]))
}
}
}