mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Use Coin type from @cosmjs/launchpad
This commit is contained in:
parent
6f58e7c355
commit
435660cb67
@ -39,6 +39,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@cosmjs/encoding": "^0.22.0",
|
||||
"@cosmjs/launchpad": "^0.22.0",
|
||||
"@cosmjs/math": "^0.22.0",
|
||||
"@cosmjs/proto-signing": "^0.22.0",
|
||||
"@cosmjs/tendermint-rpc": "^0.22.0",
|
||||
|
@ -1,7 +1,8 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Bech32, toAscii, toHex } from "@cosmjs/encoding";
|
||||
import { Coin } from "@cosmjs/launchpad";
|
||||
import { Uint64 } from "@cosmjs/math";
|
||||
import { BaseAccount, Coin, decodeAny } from "@cosmjs/proto-signing";
|
||||
import * as proto from "@cosmjs/proto-signing";
|
||||
import { Client as TendermintClient } from "@cosmjs/tendermint-rpc";
|
||||
import { assertDefined } from "@cosmjs/utils";
|
||||
import Long from "long";
|
||||
@ -33,10 +34,10 @@ export class StargateClient {
|
||||
const accountKey = Uint8Array.from([0x01, ...binAddress]);
|
||||
const responseData = await this.queryVerified("acc", accountKey);
|
||||
|
||||
const { typeUrl, value } = decodeAny(responseData);
|
||||
const { typeUrl, value } = proto.decodeAny(responseData);
|
||||
switch (typeUrl) {
|
||||
case "/cosmos.auth.BaseAccount": {
|
||||
const { account_number, sequence } = BaseAccount.decode(value);
|
||||
const { account_number, sequence } = proto.BaseAccount.decode(value);
|
||||
assertDefined(account_number);
|
||||
assertDefined(sequence);
|
||||
return {
|
||||
@ -49,13 +50,7 @@ export class StargateClient {
|
||||
}
|
||||
}
|
||||
|
||||
public async getBalance(
|
||||
address: string,
|
||||
searchDenom: string,
|
||||
): Promise<{
|
||||
readonly denom: string;
|
||||
readonly amount: string;
|
||||
} | null> {
|
||||
public async getBalance(address: string, searchDenom: string): Promise<Coin | null> {
|
||||
// balance key is a bit tricker, using some prefix stores
|
||||
// https://github.com/cosmwasm/cosmos-sdk/blob/80f7ff62f79777a487d0c7a53c64b0f7e43c47b9/x/bank/keeper/view.go#L74-L77
|
||||
// ("balances", binAddress, denom)
|
||||
@ -66,7 +61,7 @@ export class StargateClient {
|
||||
const bankKey = Uint8Array.from([...toAscii("balances"), ...binAddress, ...toAscii(searchDenom)]);
|
||||
|
||||
const responseData = await this.queryVerified("bank", bankKey);
|
||||
const { amount, denom } = Coin.decode(responseData);
|
||||
const { amount, denom } = proto.Coin.decode(responseData);
|
||||
assertDefined(amount);
|
||||
assertDefined(denom);
|
||||
|
||||
|
9
packages/stargate/types/stargateclient.d.ts
vendored
9
packages/stargate/types/stargateclient.d.ts
vendored
@ -1,3 +1,4 @@
|
||||
import { Coin } from "@cosmjs/launchpad";
|
||||
export interface GetSequenceResult {
|
||||
readonly accountNumber: number;
|
||||
readonly sequence: number;
|
||||
@ -7,13 +8,7 @@ export declare class StargateClient {
|
||||
static connect(endpoint: string): Promise<StargateClient>;
|
||||
private constructor();
|
||||
getSequence(address: string): Promise<GetSequenceResult>;
|
||||
getBalance(
|
||||
address: string,
|
||||
searchDenom: string,
|
||||
): Promise<{
|
||||
readonly denom: string;
|
||||
readonly amount: string;
|
||||
} | null>;
|
||||
getBalance(address: string, searchDenom: string): Promise<Coin | null>;
|
||||
disconnect(): void;
|
||||
private queryVerified;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user