-
Notifications
You must be signed in to change notification settings - Fork 55
/
decoder.go
46 lines (38 loc) 路 1.34 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
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/crescent-network/crescent/v3/x/liquidfarming/types"
)
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
// Value to the corresponding liquidfarming 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.LiquidFarmKeyPrefix):
var lA, lB types.LiquidFarm
cdc.MustUnmarshal(kvA.Value, &lA)
cdc.MustUnmarshal(kvB.Value, &lB)
return fmt.Sprintf("%v\n%v", lA, lB)
case bytes.Equal(kvA.Key[:1], types.CompoundingRewardsKeyPrefix):
var cA, cB types.CompoundingRewards
cdc.MustUnmarshal(kvA.Value, &cA)
cdc.MustUnmarshal(kvB.Value, &cB)
return fmt.Sprintf("%v\n%v", cA, cB)
case bytes.Equal(kvA.Key[:1], types.RewardsAuctionKeyPrefix):
var rA, rB types.RewardsAuction
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.BidKeyPrefix):
var bA, bB types.Bid
cdc.MustUnmarshal(kvA.Value, &bA)
cdc.MustUnmarshal(kvB.Value, &bB)
return fmt.Sprintf("%v\n%v", bA, bB)
default:
panic(fmt.Sprintf("invalid liquid farm key prefix %X", kvA.Key[:1]))
}
}
}