mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
simulation decoders for kava modules
This commit is contained in:
parent
1a2137761e
commit
11ed343dea
5
go.mod
5
go.mod
@ -12,9 +12,14 @@ require (
|
||||
github.com/spf13/cobra v0.0.5
|
||||
github.com/spf13/viper v1.4.0
|
||||
github.com/stretchr/testify v1.4.0
|
||||
github.com/tendermint/ed25519 v0.0.0-20171027050219-d8387025d2b9 // indirect
|
||||
github.com/tendermint/go-amino v0.15.0
|
||||
github.com/tendermint/go-crypto v0.9.0
|
||||
github.com/tendermint/tendermint v0.32.7
|
||||
github.com/tendermint/tm-db v0.2.0
|
||||
github.com/tendermint/tmlibs v0.9.0 // indirect
|
||||
github.com/zondax/ledger-go v0.11.0 // indirect
|
||||
github.com/zondax/ledger-goclient v0.9.9 // indirect
|
||||
golang.org/x/net v0.0.0-20190930134127-c5a3c61f89f3 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.4
|
||||
)
|
||||
|
11
go.sum
11
go.sum
@ -40,6 +40,7 @@ github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7
|
||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/cosmos/cosmos-sdk v0.34.4-0.20191010193331-18de630d0ae1 h1:yb+E8HGzFnO0YwLS6OCBIAVWtN8KfCYoKeO9mgAmQN0=
|
||||
github.com/cosmos/cosmos-sdk v0.34.4-0.20191010193331-18de630d0ae1/go.mod h1:IGBhkbOK1ebLqMWjtgo99zUxWHsA5IOb6N9CI8nHs0Y=
|
||||
github.com/cosmos/cosmos-sdk v0.38.2 h1:IeDZxxTgTMGJRZsV4s482O2gxjhLzToX5Zy1uwyasDs=
|
||||
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
|
||||
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU=
|
||||
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
|
||||
@ -234,9 +235,13 @@ github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s
|
||||
github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U=
|
||||
github.com/tendermint/crypto v0.0.0-20190823183015-45b1026d81ae h1:AOXNM7c2Vvo45SjAgeWF8Wy+NS7/NCqzRNpUc+HPAec=
|
||||
github.com/tendermint/crypto v0.0.0-20190823183015-45b1026d81ae/go.mod h1:z4YtwM70uOnk8h0pjJYlj3zdYwi9l03By6iAIF5j/Pk=
|
||||
github.com/tendermint/ed25519 v0.0.0-20171027050219-d8387025d2b9 h1:zccWau0P8FELSb4HTDJ88hRo+WVNMbIbg27rFqDrhCE=
|
||||
github.com/tendermint/ed25519 v0.0.0-20171027050219-d8387025d2b9/go.mod h1:nt45hbhDkWVdMBkr2TOgOzCrpBccXdN09WOiOYTHVEk=
|
||||
github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso=
|
||||
github.com/tendermint/go-amino v0.15.0 h1:TC4e66P59W7ML9+bxio17CPKnxW3nKIRAYskntMAoRk=
|
||||
github.com/tendermint/go-amino v0.15.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME=
|
||||
github.com/tendermint/go-crypto v0.9.0 h1:knZL34Ccy6BDjsPXwBslVTtyUpvOVAGbZMHcQriXulM=
|
||||
github.com/tendermint/go-crypto v0.9.0/go.mod h1:bL+jG0FvO892QRYHtA/lEIQSMMq7anlRPTGbsWzQntU=
|
||||
github.com/tendermint/iavl v0.12.4 h1:hd1woxUGISKkfUWBA4mmmTwOua6PQZTJM/F0FDrmMV8=
|
||||
github.com/tendermint/iavl v0.12.4/go.mod h1:8LHakzt8/0G3/I8FUU0ReNx98S/EP6eyPJkAUvEXT/o=
|
||||
github.com/tendermint/tendermint v0.32.1/go.mod h1:jmPDAKuNkev9793/ivn/fTBnfpA9mGBww8MPRNPNxnU=
|
||||
@ -246,6 +251,8 @@ github.com/tendermint/tendermint v0.32.7/go.mod h1:D2+A3pNjY+Po72X0mTfaXorFhiVI8
|
||||
github.com/tendermint/tm-db v0.1.1/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw=
|
||||
github.com/tendermint/tm-db v0.2.0 h1:rJxgdqn6fIiVJZy4zLpY1qVlyD0TU6vhkT4kEf71TQQ=
|
||||
github.com/tendermint/tm-db v0.2.0/go.mod h1:0cPKWu2Mou3IlxecH+MEUSYc1Ch537alLe6CpFrKzgw=
|
||||
github.com/tendermint/tmlibs v0.9.0 h1:3aU/D2v3aecqpODOuBXCfi950bHTefD5Pps5X3XuJDc=
|
||||
github.com/tendermint/tmlibs v0.9.0/go.mod h1:4L0tAKpLTioy14VnmbXYTLIJN0pCMiehxDMdN6zZfM8=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
@ -253,6 +260,10 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
|
||||
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
||||
github.com/zondax/hid v0.9.0 h1:eiT3P6vNxAEVxXMw66eZUAAnU2zD33JBkfG/EnfAKl8=
|
||||
github.com/zondax/hid v0.9.0/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
|
||||
github.com/zondax/ledger-go v0.11.0 h1:EEqUh6eaZucWAaGo87G7sJiqRNJpzBZr+I9PpGgjjPg=
|
||||
github.com/zondax/ledger-go v0.11.0/go.mod h1:NI6JDs8VWwgh+9Bf1vPZMm9Xufp2Q7Iwm2IzxJWzmus=
|
||||
github.com/zondax/ledger-goclient v0.9.9 h1:XBvqkjluVda8dTYwPh2DPnlSGVEeoH1a1OprEAn8C98=
|
||||
github.com/zondax/ledger-goclient v0.9.9/go.mod h1:ILyu7qO5zsod0bzyxY9NCMlFTb8AXZzJAJf0T85b2jA=
|
||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
|
||||
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
|
@ -1,12 +1,37 @@
|
||||
package simulation
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
|
||||
"github.com/kava-labs/kava/x/bep3/types"
|
||||
)
|
||||
|
||||
// DecodeStore unmarshals the KVPair's Value to the module's corresponding type
|
||||
func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string {
|
||||
// TODO implement this
|
||||
return ""
|
||||
switch {
|
||||
case bytes.Equal(kvA.Key[:1], types.AtomicSwapKeyPrefix):
|
||||
var swapA, swapB *types.AtomicSwap
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &swapA)
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &swapB)
|
||||
return fmt.Sprintf("%v\n%v", swapA, swapB)
|
||||
|
||||
case bytes.Equal(kvA.Key[:1], types.AssetSupplyKeyPrefix):
|
||||
var supplyA, supplyB types.AssetSupply
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &supplyA)
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &supplyB)
|
||||
return fmt.Sprintf("%s\n%s", supplyA, supplyB)
|
||||
|
||||
case bytes.Equal(kvA.Key[:1], types.AtomicSwapByBlockPrefix),
|
||||
bytes.Equal(kvA.Key[:1], types.AtomicSwapLongtermStoragePrefix):
|
||||
var bytesA cmn.HexBytes = kvA.Value
|
||||
var bytesB cmn.HexBytes = kvA.Value
|
||||
return fmt.Sprintf("%s\n%s", bytesA.String(), bytesB.String())
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1]))
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,60 @@
|
||||
package simulation
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
|
||||
"github.com/kava-labs/kava/x/cdp/types"
|
||||
)
|
||||
|
||||
// DecodeStore unmarshals the KVPair's Value to the corresponding cdp type
|
||||
func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string {
|
||||
// TODO implement this
|
||||
return ""
|
||||
switch {
|
||||
case bytes.Equal(kvA.Key[:1], types.CdpIDKeyPrefix):
|
||||
var cdpIDsA, cdpIDsB []uint64
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &cdpIDsA)
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &cdpIDsB)
|
||||
return fmt.Sprintf("%v\n%v", cdpIDsA, cdpIDsB)
|
||||
|
||||
case bytes.Equal(kvA.Key[:1], types.CdpIDKey),
|
||||
bytes.Equal(kvA.Key[:1], types.CollateralRatioIndexPrefix):
|
||||
idA := binary.BigEndian.Uint64(kvA.Value)
|
||||
idB := binary.BigEndian.Uint64(kvB.Value)
|
||||
return fmt.Sprintf("%d\n%d", idA, idB)
|
||||
|
||||
case bytes.Equal(kvA.Key[:1], types.DebtDenomKey),
|
||||
bytes.Equal(kvA.Key[:1], types.GovDenomKey):
|
||||
var denomA, denomB string
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &denomA)
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &denomB)
|
||||
return fmt.Sprintf("%s\n%s", denomA, denomB)
|
||||
|
||||
case bytes.Equal(kvA.Key[:1], types.DepositKeyPrefix):
|
||||
var depositA, depositB types.Deposit
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &depositA)
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &depositB)
|
||||
return fmt.Sprintf("%s\n%s", depositA, depositB)
|
||||
|
||||
case bytes.Equal(kvA.Key[:1], types.PrincipalKeyPrefix):
|
||||
var totalA, totalB sdk.Int
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &totalA)
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &totalB)
|
||||
return fmt.Sprintf("%s\n%s", totalA, totalB)
|
||||
|
||||
case bytes.Equal(kvA.Key[:1], types.PreviousBlockTimeKey),
|
||||
bytes.Equal(kvA.Key[:1], types.PreviousDistributionTimeKey):
|
||||
var timeA, timeB time.Time
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &timeA)
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &timeB)
|
||||
return fmt.Sprintf("%s\n%s", timeA, timeB)
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1]))
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,26 @@
|
||||
package simulation
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
|
||||
"github.com/kava-labs/kava/x/kavadist/types"
|
||||
)
|
||||
|
||||
// DecodeStore unmarshals the KVPair's Value to the corresponding cdp type
|
||||
func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string {
|
||||
// TODO implement this
|
||||
return ""
|
||||
switch {
|
||||
case bytes.Equal(kvA.Key[:1], types.PreviousBlockTimeKey):
|
||||
var timeA, timeB time.Time
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &timeA)
|
||||
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &timeB)
|
||||
return fmt.Sprintf("%s\n%s", timeA, timeB)
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1]))
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,31 @@
|
||||
package simulation
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
|
||||
"github.com/kava-labs/kava/x/pricefeed/types"
|
||||
)
|
||||
|
||||
// DecodeStore unmarshals the KVPair's Value to the corresponding pricefeed type
|
||||
func DecodeStore(cdc *codec.Codec, kvA, kvB cmn.KVPair) string {
|
||||
// TODO implement this
|
||||
return ""
|
||||
switch {
|
||||
case bytes.Contains(kvA.Key[:1], []byte(types.CurrentPricePrefix)):
|
||||
var priceA, priceB types.CurrentPrice
|
||||
cdc.MustUnmarshalBinaryBare(kvA.Value, &priceA)
|
||||
cdc.MustUnmarshalBinaryBare(kvB.Value, &priceB)
|
||||
return fmt.Sprintf("%s\n%s", priceA, priceB)
|
||||
|
||||
case bytes.Contains(kvA.Key[:1], []byte(types.RawPriceFeedPrefix)):
|
||||
var postedPriceA, postedPriceB types.PostedPrice
|
||||
cdc.MustUnmarshalBinaryBare(kvA.Value, &postedPriceA)
|
||||
cdc.MustUnmarshalBinaryBare(kvB.Value, &postedPriceB)
|
||||
return fmt.Sprintf("%s\n%s", postedPriceA, postedPriceB)
|
||||
|
||||
default:
|
||||
panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1]))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user