Add query for the total supply of a coin (#903)

* add bank supply query

* remove a local dev dependency
This commit is contained in:
larry
2022-09-07 15:53:55 +01:00
committed by GitHub
parent aee42296b4
commit b8c1d76a9a
3 changed files with 19 additions and 0 deletions

View File

@@ -189,6 +189,16 @@ func BankQuerier(bankKeeper types.BankViewKeeper) func(ctx sdk.Context, request
}
return json.Marshal(res)
}
if request.Supply != nil {
coin := bankKeeper.GetSupply(ctx, request.Supply.Denom)
res := wasmvmtypes.SupplyResponse{
Amount: wasmvmtypes.Coin{
Denom: coin.Denom,
Amount: coin.Amount.String(),
},
}
return json.Marshal(res)
}
return nil, wasmvmtypes.UnsupportedRequest{Kind: "unknown BankQuery variant"}
}
}

View File

@@ -511,10 +511,18 @@ func (m mockWasmQueryKeeper) IsPinnedCode(ctx sdk.Context, codeID uint64) bool {
}
type bankKeeperMock struct {
GetSupplyFn func(ctx sdk.Context, denom string) sdk.Coin
GetBalanceFn func(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
GetAllBalancesFn func(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
}
func (m bankKeeperMock) GetSupply(ctx sdk.Context, denom string) sdk.Coin {
if m.GetSupplyFn == nil {
panic("not expected to be called")
}
return m.GetSupplyFn(ctx, denom)
}
func (m bankKeeperMock) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
if m.GetBalanceFn == nil {
panic("not expected to be called")

View File

@@ -17,6 +17,7 @@ import (
type BankViewKeeper interface {
GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
GetSupply(ctx sdk.Context, denom string) sdk.Coin
}
// Burner is a subset of the sdk bank keeper methods