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

Feature/new api #314

Merged
merged 5 commits into from
Jul 15, 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
12 changes: 12 additions & 0 deletions src/client/lcd/api/AuthAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,16 @@ describe('AuthAPI', () => {
);
});
});

describe('parameters', () => {
it('parameters', async () => {
const param = await auth.parameters();

expect(param.max_memo_characters).toBeGreaterThanOrEqual(0);
expect(param.tx_sig_limit).toBeGreaterThanOrEqual(0);
expect(param.tx_size_cost_per_byte).toBeGreaterThanOrEqual(0);
expect(param.sig_verify_cost_ed25519).toBeGreaterThanOrEqual(0);
expect(param.sig_verify_cost_secp256k1).toBeGreaterThanOrEqual(0);
});
});
});
33 changes: 33 additions & 0 deletions src/client/lcd/api/AuthAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ import { BaseAPI } from './BaseAPI';
import { APIParams } from '../APIRequester';
import { LCDClient } from '../LCDClient';

export interface AuthParams {
max_memo_characters: number;
tx_sig_limit: number;
tx_size_cost_per_byte: number;
sig_verify_cost_ed25519: number;
sig_verify_cost_secp256k1: number;
}

export namespace AuthParams {
export interface Data {
max_memo_characters: string;
tx_sig_limit: string;
tx_size_cost_per_byte: string;
sig_verify_cost_ed25519: string;
sig_verify_cost_secp256k1: string;
}
}

export class AuthAPI extends BaseAPI {
constructor(public lcd: LCDClient) {
super(lcd.apiRequester);
Expand All @@ -35,4 +53,19 @@ export class AuthAPI extends BaseAPI {
}>(`/cosmos/auth/v1beta1/accounts/${address}`, params);
return Account.fromData(account, this.lcd.config.isClassic);
}

public async parameters(params: APIParams = {}): Promise<AuthParams> {
if (this.lcd.config.isClassic) {
throw new Error('Not supported for the network');
}
return this.c
.get<{ params: AuthParams.Data }>(`/cosmos/auth/v1beta1/params`, params)
.then(({ params: d }) => ({
max_memo_characters: Number.parseInt(d.max_memo_characters),
tx_sig_limit: Number.parseInt(d.tx_sig_limit),
tx_size_cost_per_byte: Number.parseInt(d.tx_size_cost_per_byte),
sig_verify_cost_ed25519: Number.parseInt(d.sig_verify_cost_ed25519),
sig_verify_cost_secp256k1: Number.parseInt(d.sig_verify_cost_secp256k1),
}));
}
}
8 changes: 8 additions & 0 deletions src/client/lcd/api/BankAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ describe('BankAPI', () => {
const totalSupply = await bank.total();
expect(totalSupply[0].toArray().length).toBeGreaterThan(0);
});

describe('parameters', () => {
it('parameters', async () => {
const param = await bank.parameters();

expect(param.default_send_enabled).toBeDefined();
});
});
});
37 changes: 37 additions & 0 deletions src/client/lcd/api/BankAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@ import { Coins, AccAddress } from '../../../core';
import { APIParams, Pagination, PaginationOptions } from '../APIRequester';
import { LCDClient } from '../LCDClient';

export interface SendEnabled {
denom: string;
enabled: boolean;
}

export namespace SendEnabled {
export interface Data {
denom: string;
enabled: boolean;
}
}
export interface BankParams {
send_enabled: SendEnabled[];
default_send_enabled: boolean;
}

export namespace BankParams {
export interface Data {
send_enabled: SendEnabled.Data[];
default_send_enabled: boolean;
}
}

export class BankAPI extends BaseAPI {
constructor(public lcd: LCDClient) {
super(lcd.apiRequester);
Expand Down Expand Up @@ -56,4 +79,18 @@ export class BankAPI extends BaseAPI {
}>(`/cosmos/bank/v1beta1/spendable_balances/${address}`, params)
.then(d => [Coins.fromData(d.balances), d.pagination]);
}

public async parameters(params: APIParams = {}): Promise<BankParams> {
if (this.lcd.config.isClassic) {
throw new Error('Not supported for the network');
}
return this.c
.get<{ params: BankParams.Data }>(`/cosmos/bank/v1beta1/params`, params)
.then(({ params: d }) => ({
send_enabled: d.send_enabled,
default_send_enabled: d.default_send_enabled,
}));
}

// TODO: TBD: implement denoms_medata?
}
85 changes: 69 additions & 16 deletions src/client/lcd/api/IbcAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Height } from '../../../core/ibc/core/client/Height';
import { LCDClient } from '../LCDClient';
import { IbcAPI } from './IbcAPI';

Expand All @@ -15,26 +16,78 @@ describe('IbcClientAPI', () => {
});

it('client_states', async () => {
const res = await ibc.client_states();
const res = await ibc.clientStates();
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
});

// it('client_state', async () => {
// const res = await ibc.client_state('07-tendermint-0');
// expect(res).not.toBeNull();
// expect(res).not.toBeUndefined();
// });
it('client_state', async () => {
const res = await ibc.clientState('07-tendermint-0');
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
});

it('client_status', async () => {
const res = await ibc.clientStatus('07-tendermint-0');
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
});

// it('client_status', async () => {
// const res = await ibc.client_status('07-tendermint-0');
// expect(res).not.toBeNull();
// expect(res).not.toBeUndefined();
// });
it('consensus_states', async () => {
const res = await ibc.consensusStates('07-tendermint-0');
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
});

// it('consensus_states', async () => {
// const res = await ibc.consensus_states('07-tendermint-0');
// expect(res).not.toBeNull();
// expect(res).not.toBeUndefined();
// });
it('ica host paramaters', async () => {
const res = await ibc.interchainAccountHostParameters();
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
});

/*
it('ica controller paramaters', async () => {
const res = await ibc.interchainAccountControllerParameters();
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
});
*/

it('channels', async () => {
const [res, _] = await ibc.channels();
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
expect(res.length).toBeGreaterThan(0);
});

it('channels for a connection', async () => {
const [res, height, _] = await ibc.connectionChannels('connection-3');
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
expect(height).not.toBeNull();
expect(height).toBeInstanceOf(Height);
expect(res.length).toBeGreaterThan(0);
});

it('port', async () => {
const res = await ibc.port('channel-0', 'transfer');
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
expect(res).toHaveProperty('channel');
expect(res).toHaveProperty('proof');
expect(res).toHaveProperty('proof_height');
});

it('connections', async () => {
const [res, _] = await ibc.connections();
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
expect(res.length).toBeGreaterThan(0);
});

it('a connection', async () => {
const res = await ibc.connection('connection-0');
expect(res).not.toBeNull();
expect(res).not.toBeUndefined();
});
});
Loading