Correct json field tags in pricefeed, auction (#301)

* fix: genesis param json tags

* chore: linting

* fix: missing tags in collateral

* fix: genesis auctions tag
This commit is contained in:
Kevin Davis 2020-01-16 16:17:57 +01:00 committed by GitHub
commit a9c92439c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 17 deletions

View File

@ -8,10 +8,10 @@ import (
"github.com/cosmos/cosmos-sdk/x/supply" "github.com/cosmos/cosmos-sdk/x/supply"
) )
// distantFuture is a very large time value to use as initial the ending time for auctions. // DistantFuture is a very large time value to use as initial the ending time for auctions.
// It is not set to the max time supported. This can cause problems with time comparisons, see https://stackoverflow.com/a/32620397. // It is not set to the max time supported. This can cause problems with time comparisons, see https://stackoverflow.com/a/32620397.
// Also amino panics when encoding times ≥ the start of year 10000. // Also amino panics when encoding times ≥ the start of year 10000.
var DistantFuture time.Time = time.Date(9000, 1, 1, 0, 0, 0, 0, time.UTC) var DistantFuture = time.Date(9000, 1, 1, 0, 0, 0, 0, time.UTC)
// Auction is an interface for handling common actions on auctions. // Auction is an interface for handling common actions on auctions.
type Auction interface { type Auction interface {
@ -57,6 +57,7 @@ func (a BaseAuction) GetBid() sdk.Coin { return a.Bid }
// GetEndTime is a getter for auction end time. // GetEndTime is a getter for auction end time.
func (a BaseAuction) GetEndTime() time.Time { return a.EndTime } func (a BaseAuction) GetEndTime() time.Time { return a.EndTime }
// Validate verifies that the auction end time is before max end time
func (a BaseAuction) Validate() error { func (a BaseAuction) Validate() error {
if a.EndTime.After(a.MaxEndTime) { if a.EndTime.After(a.MaxEndTime) {
return fmt.Errorf("MaxEndTime < EndTime (%s < %s)", a.MaxEndTime, a.EndTime) return fmt.Errorf("MaxEndTime < EndTime (%s < %s)", a.MaxEndTime, a.EndTime)

View File

@ -1,5 +1,6 @@
package types package types
// Events for auction module
const ( const (
EventTypeAuctionStart = "auction_start" EventTypeAuctionStart = "auction_start"
EventTypeAuctionBid = "auction_bid" EventTypeAuctionBid = "auction_bid"

View File

@ -20,8 +20,8 @@ type GenesisAuctions []GenesisAuction
// GenesisState is auction state that must be provided at chain genesis. // GenesisState is auction state that must be provided at chain genesis.
type GenesisState struct { type GenesisState struct {
NextAuctionID uint64 `json:"next_auction_id" yaml:"next_auction_id"` NextAuctionID uint64 `json:"next_auction_id" yaml:"next_auction_id"`
Params Params `json:"auction_params" yaml:"auction_params"` Params Params `json:"params" yaml:"params"`
Auctions GenesisAuctions `json:"genesis_auctions" yaml:"genesis_auctions"` Auctions GenesisAuctions `json:"auctions" yaml:"auctions"`
} }
// NewGenesisState returns a new genesis state object for auctions module. // NewGenesisState returns a new genesis state object for auctions module.
@ -50,7 +50,7 @@ func (gs GenesisState) IsEmpty() bool {
return gs.Equal(GenesisState{}) return gs.Equal(GenesisState{})
} }
// ValidateGenesis validates genesis inputs. It returns error if validation of any input fails. // Validate validates genesis inputs. It returns error if validation of any input fails.
func (gs GenesisState) Validate() error { func (gs GenesisState) Validate() error {
if err := gs.Params.Validate(); err != nil { if err := gs.Params.Validate(); err != nil {
return err return err

View File

@ -20,9 +20,11 @@ const (
// DefaultParamspace default name for parameter store // DefaultParamspace default name for parameter store
DefaultParamspace = ModuleName DefaultParamspace = ModuleName
// QuerierRoute route used for abci queries
QuerierRoute = ModuleName QuerierRoute = ModuleName
) )
// Key prefixes
var ( var (
AuctionKeyPrefix = []byte{0x00} // prefix for keys that store auctions AuctionKeyPrefix = []byte{0x00} // prefix for keys that store auctions
AuctionByTimeKeyPrefix = []byte{0x01} // prefix for keys that are part of the auctionsByTime index AuctionByTimeKeyPrefix = []byte{0x01} // prefix for keys that are part of the auctionsByTime index
@ -30,10 +32,12 @@ var (
NextAuctionIDKey = []byte{0x02} // key for the next auction id NextAuctionIDKey = []byte{0x02} // key for the next auction id
) )
// GetAuctionKey returns the bytes of an auction key
func GetAuctionKey(auctionID uint64) []byte { func GetAuctionKey(auctionID uint64) []byte {
return Uint64ToBytes(auctionID) return Uint64ToBytes(auctionID)
} }
// GetAuctionByTimeKey returns the key for iterating auctions by time
func GetAuctionByTimeKey(endTime time.Time, auctionID uint64) []byte { func GetAuctionByTimeKey(endTime time.Time, auctionID uint64) []byte {
return append(sdk.FormatTimeBytes(endTime), Uint64ToBytes(auctionID)...) return append(sdk.FormatTimeBytes(endTime), Uint64ToBytes(auctionID)...)
} }

View File

@ -54,11 +54,10 @@ func ParamKeyTable() subspace.KeyTable {
} }
// ParamSetPairs implements the ParamSet interface and returns all the key/value pairs. // ParamSetPairs implements the ParamSet interface and returns all the key/value pairs.
// nolint
func (p *Params) ParamSetPairs() subspace.ParamSetPairs { func (p *Params) ParamSetPairs() subspace.ParamSetPairs {
return subspace.ParamSetPairs{ return subspace.ParamSetPairs{
{KeyAuctionBidDuration, &p.BidDuration}, {Key: KeyAuctionBidDuration, Value: &p.BidDuration},
{KeyAuctionDuration, &p.MaxAuctionDuration}, {Key: KeyAuctionDuration, Value: &p.MaxAuctionDuration},
} }
} }

View File

@ -19,8 +19,8 @@ func (n QueryResAuctions) String() string {
// QueryAllAuctionParams is the params for an auctions query // QueryAllAuctionParams is the params for an auctions query
type QueryAllAuctionParams struct { type QueryAllAuctionParams struct {
Page int `json"page:" yaml:"page"` Page int `json:"page" yaml:"page"`
Limit int `json"limit:" yaml:"limit"` Limit int `json:"limit" yaml:"limit"`
} }
// NewQueryAllAuctionParams creates a new QueryAllAuctionParams // NewQueryAllAuctionParams creates a new QueryAllAuctionParams

View File

@ -77,8 +77,8 @@ type CollateralParam struct {
LiquidationRatio sdk.Dec `json:"liquidation_ratio" yaml:"liquidation_ratio"` // The ratio (Collateral (priced in stable coin) / Debt) under which a CDP will be liquidated LiquidationRatio sdk.Dec `json:"liquidation_ratio" yaml:"liquidation_ratio"` // The ratio (Collateral (priced in stable coin) / Debt) under which a CDP will be liquidated
DebtLimit sdk.Coins `json:"debt_limit" yaml:"debt_limit"` // Maximum amount of debt allowed to be drawn from this collateral type DebtLimit sdk.Coins `json:"debt_limit" yaml:"debt_limit"` // Maximum amount of debt allowed to be drawn from this collateral type
StabilityFee sdk.Dec `json:"stability_fee" yaml:"stability_fee"` // per second stability fee for loans opened using this collateral StabilityFee sdk.Dec `json:"stability_fee" yaml:"stability_fee"` // per second stability fee for loans opened using this collateral
AuctionSize sdk.Int // Max amount of collateral to sell off in any one auction. AuctionSize sdk.Int `json:"auction_size" yaml:"auction_size"` // Max amount of collateral to sell off in any one auction.
LiquidationPenalty sdk.Dec // percentage penalty (between [0, 1]) applied to a cdp if it is liquidated LiquidationPenalty sdk.Dec `json:"liquidation_penalty" yaml:"liquidation_penalty"` // percentage penalty (between [0, 1]) applied to a cdp if it is liquidated
Prefix byte `json:"prefix" yaml:"prefix"` Prefix byte `json:"prefix" yaml:"prefix"`
MarketID string `json:"market_id" yaml:"market_id"` // marketID for fetching price of the asset from the pricefeed MarketID string `json:"market_id" yaml:"market_id"` // marketID for fetching price of the asset from the pricefeed
ConversionFactor sdk.Int `json:"conversion_factor" yaml:"conversion_factor"` // factor for converting internal units to one base unit of collateral ConversionFactor sdk.Int `json:"conversion_factor" yaml:"conversion_factor"` // factor for converting internal units to one base unit of collateral

View File

@ -6,7 +6,7 @@ import (
// GenesisState - pricefeed state that must be provided at genesis // GenesisState - pricefeed state that must be provided at genesis
type GenesisState struct { type GenesisState struct {
Params Params `json:"asset_params" yaml:"asset_params"` Params Params `json:"params" yaml:"params"`
PostedPrices []PostedPrice `json:"posted_prices" yaml:"posted_prices"` PostedPrices []PostedPrice `json:"posted_prices" yaml:"posted_prices"`
} }