/
decoder.go
66 lines (54 loc) 路 1.96 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/crescent-network/crescent/v5/x/amm/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, types.LastPoolIdKey):
idA := sdk.BigEndianToUint64(kvA.Value)
idB := sdk.BigEndianToUint64(kvB.Value)
return fmt.Sprintf("%d\n%d", idA, idB)
case bytes.Equal(kvA.Key, types.LastPositionIdKey):
idA := sdk.BigEndianToUint64(kvA.Value)
idB := sdk.BigEndianToUint64(kvB.Value)
return fmt.Sprintf("%d\n%d", idA, idB)
case bytes.Equal(kvA.Key[:1], types.PoolKeyPrefix):
var pA, pB types.Pool
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.PoolStateKeyPrefix):
var psA, psB types.PoolState
cdc.MustUnmarshal(kvA.Value, &psA)
cdc.MustUnmarshal(kvB.Value, &psB)
return fmt.Sprintf("%v\n%v", psA, psB)
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.TickInfoKeyPrefix):
var tA, tB types.TickInfo
cdc.MustUnmarshal(kvA.Value, &tA)
cdc.MustUnmarshal(kvB.Value, &tB)
return fmt.Sprintf("%v\n%v", tA, tB)
case bytes.Equal(kvA.Key, types.LastFarmingPlanIdKey):
idA := sdk.BigEndianToUint64(kvA.Value)
idB := sdk.BigEndianToUint64(kvB.Value)
return fmt.Sprintf("%d\n%d", idA, idB)
case bytes.Equal(kvA.Key[:1], types.FarmingPlanKeyPrefix):
var pA, pB types.FarmingPlan
cdc.MustUnmarshal(kvA.Value, &pA)
cdc.MustUnmarshal(kvB.Value, &pB)
return fmt.Sprintf("%v\n%v", pA, pB)
default:
panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1]))
}
}
}