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

Implemented new "account balance query by denom" endpoint #2

Merged
merged 2 commits into from Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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 CosmosSharp/CosmosSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Copyright>Copyright (c) 2021 BTCTrader</Copyright>
<PackageId>BTCTrader.CosmosSharp</PackageId>
<Product>BTCTrader.CosmosSharp</Product>
<Version>1.1.1</Version>
<Version>1.1.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
23 changes: 22 additions & 1 deletion CosmosSharp/StargateApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,32 @@ public async Task<AccountModel> GetAccount(string accountName, CancellationToken
return await _httpHandler.GetJsonAsync<AccountModel>(url, _config.HeaderKeyValues, cancellationToken);
}

public async Task<BalanceResponse> GetAccountBalance(string accountName, string denom, CancellationToken cancellationToken)
/// <summary>
/// Receives account balance via cosmos-sdk <b>before v0.44.4</b>. See more details about change in <a href="https://github.com/cosmos/cosmos-sdk/pull/10394#discussion_r734448254"><i>query account balance endpoint fix</i></a> and <a href="https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.4"><i>release notes</i></a>.
/// </summary>
/// <param name="accountName">address</param>
/// <param name="denom">denom or IBC denom</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<BalanceResponse> GetAccountBalanceLegacy(string accountName, string denom, CancellationToken cancellationToken)
{
var url = $"{_config.HttpEndpoint}/cosmos/bank/v1beta1/balances/{accountName}/{denom}";
return await _httpHandler.GetJsonAsync<BalanceResponse>(url, _config.HeaderKeyValues, cancellationToken);
}

/// <summary>
/// Receives account balance via cosmos-sdk <b>as from v0.44.4</b>. See more details about <a href="https://github.com/cosmos/cosmos-sdk/pull/10394#discussion_r734448254"><i>query account balance endpoint fix</i></a> and <a href="https://github.com/cosmos/cosmos-sdk/releases/tag/v0.44.4"><i>release notes</i></a>.
/// </summary>
/// <param name="accountName">address</param>
/// <param name="denom">denom or IBC denom</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<BalanceResponse> GetAccountBalance(string accountName, string denom, CancellationToken cancellationToken)
{
// grpc-gateway query account balance by IBC denom had an incorrect endpoint
var url = $"{_config.HttpEndpoint}/cosmos/bank/v1beta1/balances/{accountName}/by_denom?denom={denom}";
return await _httpHandler.GetJsonAsync<BalanceResponse>(url, _config.HeaderKeyValues, cancellationToken);
}

public async Task<BlockInfo> GetLatestBlock(CancellationToken cancellationToken)
{
Expand Down