Add query for the total supply of a coin (#903)
* add bank supply query * remove a local dev dependency
This commit is contained in:
@@ -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"}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user