Merge pull request #285 from CosmWasm/bank-extension
Add bank extension
This commit is contained in:
commit
5fd8396271
@ -23,6 +23,8 @@ export { makeSignBytes } from "./encoding";
|
||||
export {
|
||||
AuthAccountsResponse,
|
||||
AuthExtension,
|
||||
BankBalancesResponse,
|
||||
BankExtension,
|
||||
BlockResponse,
|
||||
BroadcastMode,
|
||||
EncodeTxResponse,
|
||||
@ -33,6 +35,7 @@ export {
|
||||
PostTxsResponse,
|
||||
SearchTxsResponse,
|
||||
setupAuthExtension,
|
||||
setupBankExtension,
|
||||
setupSupplyExtension,
|
||||
SupplyExtension,
|
||||
TxsResponse,
|
||||
|
||||
45
packages/sdk38/src/lcdapi/bank.spec.ts
Normal file
45
packages/sdk38/src/lcdapi/bank.spec.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import {
|
||||
makeRandomAddress,
|
||||
nonNegativeIntegerMatcher,
|
||||
pendingWithoutWasmd,
|
||||
unused,
|
||||
wasmd,
|
||||
} from "../testutils.spec";
|
||||
import { BankExtension, setupBankExtension } from "./bank";
|
||||
import { LcdClient } from "./lcdclient";
|
||||
|
||||
function makeBankClient(apiUrl: string): LcdClient & BankExtension {
|
||||
return LcdClient.withExtensions({ apiUrl }, setupBankExtension);
|
||||
}
|
||||
|
||||
describe("BankExtension", () => {
|
||||
it("returns correct values for the unused account", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeBankClient(wasmd.endpoint);
|
||||
const balances = await client.bank.balances(unused.address);
|
||||
expect(balances).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [
|
||||
{
|
||||
denom: "ucosm",
|
||||
amount: "1000000000",
|
||||
},
|
||||
{
|
||||
denom: "ustake",
|
||||
amount: "1000000000",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("returns an empty result for a non-existent account", async () => {
|
||||
pendingWithoutWasmd();
|
||||
const client = makeBankClient(wasmd.endpoint);
|
||||
const nonExistentAddress = makeRandomAddress();
|
||||
const balances = await client.bank.balances(nonExistentAddress);
|
||||
expect(balances).toEqual({
|
||||
height: jasmine.stringMatching(nonNegativeIntegerMatcher),
|
||||
result: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
24
packages/sdk38/src/lcdapi/bank.ts
Normal file
24
packages/sdk38/src/lcdapi/bank.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { Coin } from "../coins";
|
||||
import { LcdClient } from "./lcdclient";
|
||||
|
||||
export interface BankBalancesResponse {
|
||||
readonly height: string;
|
||||
readonly result: readonly Coin[];
|
||||
}
|
||||
|
||||
export interface BankExtension {
|
||||
readonly bank: {
|
||||
readonly balances: (address: string) => Promise<BankBalancesResponse>;
|
||||
};
|
||||
}
|
||||
|
||||
export function setupBankExtension(base: LcdClient): BankExtension {
|
||||
return {
|
||||
bank: {
|
||||
balances: async (address: string) => {
|
||||
const path = `/bank/balances/${address}`;
|
||||
return base.get(path);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
export { AuthExtension, AuthAccountsResponse, setupAuthExtension } from "./auth";
|
||||
export { BankBalancesResponse, BankExtension, setupBankExtension } from "./bank";
|
||||
export { setupSupplyExtension, SupplyExtension, TotalSupplyAllResponse, TotalSupplyResponse } from "./supply";
|
||||
|
||||
//
|
||||
|
||||
3
packages/sdk38/types/index.d.ts
vendored
3
packages/sdk38/types/index.d.ts
vendored
@ -21,6 +21,8 @@ export { makeSignBytes } from "./encoding";
|
||||
export {
|
||||
AuthAccountsResponse,
|
||||
AuthExtension,
|
||||
BankBalancesResponse,
|
||||
BankExtension,
|
||||
BlockResponse,
|
||||
BroadcastMode,
|
||||
EncodeTxResponse,
|
||||
@ -31,6 +33,7 @@ export {
|
||||
PostTxsResponse,
|
||||
SearchTxsResponse,
|
||||
setupAuthExtension,
|
||||
setupBankExtension,
|
||||
setupSupplyExtension,
|
||||
SupplyExtension,
|
||||
TxsResponse,
|
||||
|
||||
12
packages/sdk38/types/lcdapi/bank.d.ts
vendored
Normal file
12
packages/sdk38/types/lcdapi/bank.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { Coin } from "../coins";
|
||||
import { LcdClient } from "./lcdclient";
|
||||
export interface BankBalancesResponse {
|
||||
readonly height: string;
|
||||
readonly result: readonly Coin[];
|
||||
}
|
||||
export interface BankExtension {
|
||||
readonly bank: {
|
||||
readonly balances: (address: string) => Promise<BankBalancesResponse>;
|
||||
};
|
||||
}
|
||||
export declare function setupBankExtension(base: LcdClient): BankExtension;
|
||||
1
packages/sdk38/types/lcdapi/index.d.ts
vendored
1
packages/sdk38/types/lcdapi/index.d.ts
vendored
@ -1,4 +1,5 @@
|
||||
export { AuthExtension, AuthAccountsResponse, setupAuthExtension } from "./auth";
|
||||
export { BankBalancesResponse, BankExtension, setupBankExtension } from "./bank";
|
||||
export { setupSupplyExtension, SupplyExtension, TotalSupplyAllResponse, TotalSupplyResponse } from "./supply";
|
||||
export {
|
||||
BlockResponse,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user