-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #131 from onomyprotocol/hieu/genesis
feat(x/vault, x/auction, x/oracle): Init & ExportGenesis
- Loading branch information
Showing
23 changed files
with
1,560 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,95 @@ | ||
package keeper | ||
|
||
import ( | ||
"cosmossdk.io/collections" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/onomyprotocol/reserve/x/auction/types" | ||
) | ||
|
||
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) { | ||
func (k Keeper) InitGenesis(ctx sdk.Context, genState types.GenesisState) error { | ||
if err := k.SetParams(ctx, genState.Params); err != nil { | ||
panic(err) | ||
return err | ||
} | ||
err := k.LastestAuctionPeriods.Set(ctx, ctx.BlockTime().Unix()) | ||
if err != nil { | ||
panic(err) | ||
return err | ||
} | ||
|
||
for _, auction := range genState.Auctions { | ||
err := k.Auctions.Set(ctx, auction.AuctionId, auction) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
allBids := map[uint64][]types.Bid{} | ||
for _, bidByAddress := range genState.BidByAddress { | ||
err := k.BidByAddress.Set(ctx, collections.Join(bidByAddress.AuctionId, sdk.AccAddress(bidByAddress.Bidder)), bidByAddress.Bids) | ||
if err != nil { | ||
return err | ||
} | ||
allBids[bidByAddress.AuctionId] = append(allBids[bidByAddress.AuctionId], bidByAddress.Bids.Bids...) | ||
} | ||
|
||
for auctionId, bids:= range allBids { | ||
bidQueue := types.BidQueue{ | ||
AuctionId: auctionId, | ||
Bids: bids, | ||
} | ||
err := k.Bids.Set(ctx, auctionId, bidQueue) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
err = k.AuctionIdSeq.Set(ctx, genState.AuctionSequence) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, bidSequence := range genState.BidSequences { | ||
err = k.BidIdSeq.Set(ctx, bidSequence.AuctionId, bidSequence.Sequence) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { | ||
genesis := types.DefaultGenesis() | ||
genesis.Params = k.GetParams(ctx) | ||
params := k.GetParams(ctx) | ||
lastestAuctionPeriod, err := k.LastestAuctionPeriods.Get(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return genesis | ||
auctions, err := k.GetAllAuctions(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
bidsByAddress, err := k.GetAllBidByAddress(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
auctionIdSequence, err := k.AuctionIdSeq.Peek(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
bidsIdSequence, err := k.GetAllBidsSequence(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return &types.GenesisState{ | ||
Params: params, | ||
Auctions: auctions, | ||
BidByAddress: bidsByAddress, | ||
AuctionSequence: auctionIdSequence, | ||
LastestAuctionPeriods: lastestAuctionPeriod, | ||
BidSequences: bidsIdSequence, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.