-
Notifications
You must be signed in to change notification settings - Fork 39
/
decoder.go
52 lines (47 loc) · 1.97 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"
gogotypes "github.com/gogo/protobuf/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/classic-terra/core/v3/x/oracle/types"
)
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
// Value to the corresponding oracle 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.ExchangeRateKey):
var exchangeRateA, exchangeRateB sdk.DecProto
cdc.MustUnmarshal(kvA.Value, &exchangeRateA)
cdc.MustUnmarshal(kvB.Value, &exchangeRateB)
return fmt.Sprintf("%v\n%v", exchangeRateA, exchangeRateB)
case bytes.Equal(kvA.Key[:1], types.FeederDelegationKey):
return fmt.Sprintf("%v\n%v", sdk.AccAddress(kvA.Value), sdk.AccAddress(kvB.Value))
case bytes.Equal(kvA.Key[:1], types.MissCounterKey):
var counterA, counterB gogotypes.UInt64Value
cdc.MustUnmarshal(kvA.Value, &counterA)
cdc.MustUnmarshal(kvB.Value, &counterB)
return fmt.Sprintf("%v\n%v", counterA.Value, counterB.Value)
case bytes.Equal(kvA.Key[:1], types.AggregateExchangeRatePrevoteKey):
var prevoteA, prevoteB types.AggregateExchangeRatePrevote
cdc.MustUnmarshal(kvA.Value, &prevoteA)
cdc.MustUnmarshal(kvB.Value, &prevoteB)
return fmt.Sprintf("%v\n%v", prevoteA, prevoteB)
case bytes.Equal(kvA.Key[:1], types.AggregateExchangeRateVoteKey):
var voteA, voteB types.AggregateExchangeRateVote
cdc.MustUnmarshal(kvA.Value, &voteA)
cdc.MustUnmarshal(kvB.Value, &voteB)
return fmt.Sprintf("%v\n%v", voteA, voteB)
case bytes.Equal(kvA.Key[:1], types.TobinTaxKey):
var tobinTaxA, tobinTaxB sdk.DecProto
cdc.MustUnmarshal(kvA.Value, &tobinTaxA)
cdc.MustUnmarshal(kvB.Value, &tobinTaxB)
return fmt.Sprintf("%v\n%v", tobinTaxA, tobinTaxB)
default:
panic(fmt.Sprintf("invalid oracle key prefix %X", kvA.Key[:1]))
}
}
}