Skip to content

Commit

Permalink
text(oracle-proto): proto lint, PriceWithTimeAndRound->PriceTimeRound
Browse files Browse the repository at this point in the history
  • Loading branch information
leonz789 committed Apr 18, 2024
1 parent cb6e88c commit ecfda24
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 87 deletions.
2 changes: 1 addition & 1 deletion proto/exocore/oracle/price.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ message PriceSource{
}

// price with its specified timestamp and roundid(if from deteministic source)
message PriceWithTimeAndRound {
message PriceTimeRound {
// price
string price = 1;
// decimal of the corresponding price
Expand Down
2 changes: 1 addition & 1 deletion proto/exocore/oracle/prices.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ message Prices {
// next round id of the price to be updated
uint64 next_round_id = 2 [(gogoproto.customname) = "NextRoundID"];
// price list of all history round prices for the token
repeated PriceWithTimeAndRound price_list = 3;
repeated PriceTimeRound price_list = 3;
}
4 changes: 2 additions & 2 deletions x/oracle/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestGenesis(t *testing.T) {
PricesList: []types.Prices{
{
TokenID: 1,
PriceList: []*types.PriceWithTimeAndRound{
PriceList: []*types.PriceTimeRound{
{
Price: "100",
Decimal: 1,
Expand All @@ -29,7 +29,7 @@ func TestGenesis(t *testing.T) {
},
{
TokenID: 2,
PriceList: []*types.PriceWithTimeAndRound{
PriceList: []*types.PriceTimeRound{
{
Price: "109",
Decimal: 1,
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/keeper/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

type PriceItemKV struct {
TokenID uint64
PriceTR types.PriceWithTimeAndRound
PriceTR types.PriceTimeRound
}

type roundInfo struct {
Expand Down Expand Up @@ -124,7 +124,7 @@ func (agc *AggregatorContext) FillPrice(msg *types.MsgCreatePrice) (*PriceItemKV
if finalPrice := feederWorker.aggregate(); finalPrice != nil {
agc.rounds[msg.FeederID].status = 2
feederWorker.seal()
return &PriceItemKV{agc.params.GetTokenFeeder(msg.FeederID).TokenID, types.PriceWithTimeAndRound{
return &PriceItemKV{agc.params.GetTokenFeeder(msg.FeederID).TokenID, types.PriceTimeRound{
Price: finalPrice.String(),
Decimal: agc.params.GetTokenInfo(msg.FeederID).Decimal,
// TODO: check the format
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/keeper/msg_server_create_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ var _ = Describe("MsgCreatePrice", func() {
Expect(prices[0]).Should(BeEquivalentTo(types.Prices{
TokenID: 1,
NextRoundID: 2,
PriceList: []*types.PriceWithTimeAndRound{
PriceList: []*types.PriceTimeRound{
{
Price: testdata.PTD2.Price,
Decimal: testdata.PTD2.Decimal,
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (suite *KeeperSuite) TestCreatePriceSingleBlock() {
suite.Exactly(types.Prices{
TokenID: 1,
NextRoundID: 2,
PriceList: []*types.PriceWithTimeAndRound{
PriceList: []*types.PriceTimeRound{
{},
{
Price: testdata.PTD2.Price,
Expand Down Expand Up @@ -111,7 +111,7 @@ func (suite *KeeperSuite) TestCreatePriceTwoBlock() {
suite.Exactly(types.Prices{
TokenID: 1,
NextRoundID: 2,
PriceList: []*types.PriceWithTimeAndRound{
PriceList: []*types.PriceTimeRound{
{},
{
Price: testdata.PTD1.Price,
Expand Down
14 changes: 7 additions & 7 deletions x/oracle/keeper/prices.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func (k Keeper) GetPrices(

val.TokenID = tokenID
val.NextRoundID = nextRoundID
val.PriceList = make([]*types.PriceWithTimeAndRound, nextRoundID)
val.PriceList = make([]*types.PriceTimeRound, nextRoundID)
// 0 roundId is reserved, expect the roundid corresponds to the slice index
val.PriceList[0] = &types.PriceWithTimeAndRound{}
val.PriceList[0] = &types.PriceTimeRound{}
for i := uint64(1); i < nextRoundID; i++ {
b := store.Get(types.PricesRoundKey(i))
val.PriceList[i] = &types.PriceWithTimeAndRound{}
val.PriceList[i] = &types.PriceTimeRound{}
if b != nil {
// should always be true since we don't delete prices from history round
k.cdc.MustUnmarshal(b, val.PriceList[i])
Expand Down Expand Up @@ -80,7 +80,7 @@ func (k Keeper) GetAllPrices(ctx sdk.Context) (list []types.Prices) {
if nextRoundID {
price.NextRoundID = binary.BigEndian.Uint64(iterator.Value())
} else {
var val types.PriceWithTimeAndRound
var val types.PriceTimeRound
k.cdc.MustUnmarshal(iterator.Value(), &val)
price.PriceList = append(price.PriceList, &val)
}
Expand All @@ -91,7 +91,7 @@ func (k Keeper) GetAllPrices(ctx sdk.Context) (list []types.Prices) {
return list
}

func (k Keeper) AppendPriceTR(ctx sdk.Context, tokenID uint64, priceTR types.PriceWithTimeAndRound) {
func (k Keeper) AppendPriceTR(ctx sdk.Context, tokenID uint64, priceTR types.PriceTimeRound) {
nextRoundID := k.GetNextRoundID(ctx, tokenID)
if nextRoundID != priceTR.RoundID {
return
Expand All @@ -103,7 +103,7 @@ func (k Keeper) AppendPriceTR(ctx sdk.Context, tokenID uint64, priceTR types.Pri
}

// func(k Keeper) SetPriceTR(ctx sdk.Context, tokenID int32, priceTR){}
func (k Keeper) GetPriceTRRoundID(ctx sdk.Context, tokenID uint64, roundID uint64) (price types.PriceWithTimeAndRound, found bool) {
func (k Keeper) GetPriceTRRoundID(ctx sdk.Context, tokenID uint64, roundID uint64) (price types.PriceTimeRound, found bool) {
store := k.getPriceTRStore(ctx, tokenID)

b := store.Get(types.PricesRoundKey(roundID))
Expand All @@ -116,7 +116,7 @@ func (k Keeper) GetPriceTRRoundID(ctx sdk.Context, tokenID uint64, roundID uint6
return
}

func (k Keeper) GetPriceTRLatest(ctx sdk.Context, tokenID uint64) (price types.PriceWithTimeAndRound, found bool) {
func (k Keeper) GetPriceTRLatest(ctx sdk.Context, tokenID uint64) (price types.PriceTimeRound, found bool) {
// store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.PricesKeyPrefix))
// store = prefix.NewStore(store, types.PricesKey(tokenID))
store := k.getPriceTRStore(ctx, tokenID)
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/keeper/prices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func createNPrices(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Prices
items[i] = types.Prices{
TokenID: uint64(i + 1),
NextRoundID: 2,
PriceList: []*types.PriceWithTimeAndRound{
PriceList: []*types.PriceTimeRound{
testdata.PTR1,
testdata.PTR2,
testdata.PTR3,
Expand All @@ -42,7 +42,7 @@ func TestPricesGet(t *testing.T) {
rst, found := keeper.GetPrices(ctx, 1)
require.True(t, found)
pRes := testdata.P1
pRes.PriceList = append([]*types.PriceWithTimeAndRound{{}}, testdata.P1.PriceList...)
pRes.PriceList = append([]*types.PriceTimeRound{{}}, testdata.P1.PriceList...)
require.Equal(t, pRes, rst)
// items := createNPrices(keeper, ctx, 10)
//
Expand Down
6 changes: 3 additions & 3 deletions x/oracle/keeper/testdata/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ func newPS(sourceID uint64, prices ...*types.PriceTimeDetID) *types.PriceSource
}
}

func newPTR(price string, roundID uint64) *types.PriceWithTimeAndRound {
return &types.PriceWithTimeAndRound{
func newPTR(price string, roundID uint64) *types.PriceTimeRound {
return &types.PriceTimeRound{
Price: price,
Decimal: 18,
Timestamp: "",
RoundID: roundID,
}
}

func newPrices(tokenID uint64, nextRoundID uint64, pList ...*types.PriceWithTimeAndRound) types.Prices {
func newPrices(tokenID uint64, nextRoundID uint64, pList ...*types.PriceTimeRound) types.Prices {
return types.Prices{
TokenID: tokenID,
NextRoundID: nextRoundID,
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val
)
} else {
nextRoundID := am.keeper.GetNextRoundID(ctx, tokenID)
am.keeper.AppendPriceTR(ctx, tokenID, types.PriceWithTimeAndRound{
am.keeper.AppendPriceTR(ctx, tokenID, types.PriceTimeRound{
RoundID: nextRoundID,
})
logInfo += fmt.Sprintf(", roundID:%d, price:-", nextRoundID)
Expand Down
2 changes: 1 addition & 1 deletion x/oracle/types/key_prices.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func PricesKey(
return key
}

// PricesRoundKey returns the store key to retrieve a PriceWithTimeAndRound from the index fields
// PricesRoundKey returns the store key to retrieve a PriceTimeRound from the index fields
func PricesRoundKey(
roundID uint64,
) []byte {
Expand Down
99 changes: 49 additions & 50 deletions x/oracle/types/price.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ecfda24

Please sign in to comment.