-
Notifications
You must be signed in to change notification settings - Fork 54
/
decoder.go
52 lines (43 loc) 路 1.53 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
45
46
47
48
49
50
51
52
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/crescent-network/crescent/x/farming/types"
)
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
// Value to the corresponding farming 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.PlanKeyPrefix):
var pA, pB types.BasePlan
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.StakingKeyPrefix):
var sA, sB types.Staking
cdc.MustUnmarshal(kvA.Value, &sA)
cdc.MustUnmarshal(kvB.Value, &sB)
return fmt.Sprintf("%v\n%v", sA, sB)
case bytes.Equal(kvA.Key[:1], types.QueuedStakingKeyPrefix):
var sA, sB types.QueuedStaking
cdc.MustUnmarshal(kvA.Value, &sA)
cdc.MustUnmarshal(kvB.Value, &sB)
return fmt.Sprintf("%v\n%v", sA, sB)
case bytes.Equal(kvA.Key[:1], types.HistoricalRewardsKeyPrefix):
var rA, rB types.HistoricalRewards
cdc.MustUnmarshal(kvA.Value, &rA)
cdc.MustUnmarshal(kvB.Value, &rB)
return fmt.Sprintf("%v\n%v", rA, rB)
case bytes.Equal(kvA.Key[:1], types.OutstandingRewardsKeyPrefix):
var rA, rB types.OutstandingRewards
cdc.MustUnmarshal(kvA.Value, &rA)
cdc.MustUnmarshal(kvB.Value, &rB)
return fmt.Sprintf("%v\n%v", rA, rB)
default:
panic(fmt.Sprintf("invalid farming key prefix %X", kvA.Key[:1]))
}
}
}