Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index supply by denom #8517

Merged
merged 16 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func AddTestAddrsFromPubKeys(app *SimApp, ctx sdk.Context, pubKeys []cryptotypes
func setTotalSupply(app *SimApp, ctx sdk.Context, accAmt sdk.Int, totalAccounts int) {
totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), accAmt.MulRaw(int64(totalAccounts))))
prevSupply := app.BankKeeper.GetSupply(ctx)
app.BankKeeper.SetSupply(ctx, banktypes.NewSupply(prevSupply.GetTotal().Add(totalSupply...)))
app.BankKeeper.SetSupply(ctx, banktypes.NewSupply(prevSupply.Add(totalSupply...)).GetTotal())
}

// AddTestAddrs constructs and returns accNum amount of accounts with an
Expand Down
41 changes: 30 additions & 11 deletions x/bank/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ type Keeper interface {
InitGenesis(sdk.Context, *types.GenesisState)
ExportGenesis(sdk.Context) *types.GenesisState

GetSupply(ctx sdk.Context) exported.SupplyI
SetSupply(ctx sdk.Context, supply exported.SupplyI)
GetSupply(ctx sdk.Context, denom string) sdk.Coin
GetTotalSupply(ctx sdk.Context) sdk.Coins
SetSupply(ctx sdk.Context, supply sdk.Coins)
InflateSupply()
DeflateSupply()


GetDenomMetaData(ctx sdk.Context, denom string) (types.Metadata, bool)
SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metadata)
Expand Down Expand Up @@ -153,30 +157,45 @@ func (k BaseKeeper) UndelegateCoins(ctx sdk.Context, moduleAccAddr, delegatorAdd
}

// GetSupply retrieves the Supply from store
func (k BaseKeeper) GetSupply(ctx sdk.Context) exported.SupplyI {
func (k BaseKeeper) GetSupply(ctx sdk.Context, denom string) sdk.Coin {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.SupplyKey)
supplyStore := prefix.NewStore(store, types.SupplyKey)

bz := supplyStore.Get([]byte(denom))
if bz == nil {
panic("stored supply should not have been nil")
}

supply, err := k.UnmarshalSupply(bz)
var coin sdk.Coin
err := k.cdc.UnmarshalBinaryBare(bz, &coin)
if err != nil {
panic(err)
}

return supply
return coin
}

// SetSupply sets the Supply to store
func (k BaseKeeper) SetSupply(ctx sdk.Context, supply exported.SupplyI) {
func (k BaseKeeper) SetSupply(ctx sdk.Context, supply sdk.Coins) {
store := ctx.KVStore(k.storeKey)
bz, err := k.MarshalSupply(supply)
if err != nil {
panic(err)
supplyStore := prefix.NewStore(store, types.SupplyKey)

for _, coin := range supply{
bz := k.cdc.MustMarshalBinaryBare(&coin)
supplyStore.Set([]byte(coin.Denom), bz)
}
}

func (k BaseKeeper) GetTotalSupply(ctx sdk.Context) sdk.Coins {
for
}

func (k BaseKeeper) InflateSupply() {
panic("implement me")
}

store.Set(types.SupplyKey, bz)
func (k BaseKeeper) DeflateSupply() {
panic("implement me")
}

// GetDenomMetaData retrieves the denomination metadata
Expand Down