-
Notifications
You must be signed in to change notification settings - Fork 55
/
decoder.go
38 lines (31 loc) · 1016 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
32
33
34
35
36
37
38
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/crescent-network/crescent/v5/x/marketmaker/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.MarketMakerKeyPrefix):
var mA, mB types.MarketMaker
cdc.MustUnmarshal(kvA.Value, &mA)
cdc.MustUnmarshal(kvB.Value, &mB)
return fmt.Sprintf("%v\n%v", mA, mB)
case bytes.Equal(kvA.Key[:1], types.DepositKeyPrefix):
var dA, dB types.Deposit
cdc.MustUnmarshal(kvA.Value, &dA)
cdc.MustUnmarshal(kvB.Value, &dB)
return fmt.Sprintf("%v\n%v", dA, dB)
case bytes.Equal(kvA.Key[:1], types.IncentiveKeyPrefix):
var iA, iB types.Incentive
cdc.MustUnmarshal(kvA.Value, &iA)
cdc.MustUnmarshal(kvB.Value, &iB)
return fmt.Sprintf("%v\n%v", iA, iB)
default:
panic(fmt.Sprintf("invalid marketmaker key prefix %X", kvA.Key[:1]))
}
}
}