Skip to content

Commit 20f6b0d

Browse files
committed
recursive camel case for search block and tx
1 parent 5c00129 commit 20f6b0d

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

libs/interchainjs/starship/__tests__/gov.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,24 @@ describe('Governance tests for osmosis', () => {
8383
directAddress = (await directSigner.getAccounts())[0].address;
8484
aminoAddress = (await aminoSigner.getAccounts())[0].address;
8585

86+
const signingClient = await CosmosSigningClient.connectWithSigner(
87+
await getRpcEndpoint(),
88+
new DirectGenericOfflineSigner(directSigner),
89+
);
90+
91+
//get status
92+
const status = await signingClient.getStatus();
93+
const latestBlockHeight = status.sync_info.latest_block_height;
94+
95+
expect(BigInt(latestBlockHeight)).toBeGreaterThan(0n);
96+
97+
const blocks = await signingClient.searchBlock({
98+
query: `block.height<=${latestBlockHeight}`,
99+
page: 1,
100+
perPage: 10,
101+
});
102+
expect(BigInt(blocks.totalCount)).toBeGreaterThan(0n);
103+
86104
// Transfer osmosis to address
87105
await creditFromFaucet(directAddress);
88106
await creditFromFaucet(aminoAddress);

networks/cosmos/src/signing-client.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import { toConverter, toEncoder } from './utils';
1717
import { TxBody, TxRaw } from '@interchainjs/cosmos-types/cosmos/tx/v1beta1/tx';
1818
import { TxRpc } from '@interchainjs/cosmos-types/types';
1919
import { BroadcastOptions, DeliverTxResponse, HttpEndpoint, SIGN_MODE, StdFee, TelescopeGeneratedCodec } from '@interchainjs/types';
20-
import { fromBase64 } from '@interchainjs/utils';
20+
import { fromBase64, camelCaseRecursive } from '@interchainjs/utils';
2121

2222
import {
2323
Block,
2424
BlockResponse,
2525
SearchBlockQuery,
26+
SearchBlockQueryObj,
2627
SearchTxQuery,
2728
SearchTxQueryObj,
2829
isSearchBlockQueryObj,
@@ -299,6 +300,12 @@ export class SigningClient {
299300
: this.queryClient.endpoint;
300301
}
301302

303+
async getStatus() {
304+
const data = await fetch(`${this.endpoint.url}/status`);
305+
const json = await data.json();
306+
return json['result'];
307+
}
308+
302309
async getTx(id: string): Promise<IndexedTx | null> {
303310
const data = await fetch(`${this.endpoint.url}/tx?hash=0x${id}`);
304311
const json = await data.json();
@@ -357,10 +364,10 @@ export class SigningClient {
357364

358365
const data = await fetch(`${this.endpoint.url}/tx_search?${params.toString()}`);
359366
const json = await data.json();
360-
return json['result'];
367+
return camelCaseRecursive(json['result']);
361368
}
362369

363-
async searchBlock(query: SearchBlockQuery): Promise<any> {
370+
async searchBlock(query: SearchBlockQuery | SearchBlockQueryObj): Promise<any> {
364371
let rawQuery: string;
365372
let page = 1;
366373
let perPage = 100;
@@ -394,7 +401,7 @@ export class SigningClient {
394401

395402
const data = await fetch(`${this.endpoint.url}/block_search?${params.toString()}`);
396403
const json = await data.json();
397-
return json['result'];
404+
return camelCaseRecursive(json['result']);
398405
}
399406

400407
async getBlock(height?: number): Promise<Block> {

packages/utils/src/case.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export function camelCaseRecursive(obj: any): any {
2+
if (Array.isArray(obj)) {
3+
return obj.map(camelCaseRecursive);
4+
} else if (typeof obj === 'object' && obj !== null) {
5+
return Object.fromEntries(
6+
Object.entries(obj).map(([key, value]) => [camel(key), camelCaseRecursive(value)])
7+
);
8+
}
9+
return obj;
10+
}
11+
12+
export function camel(str: string) {
13+
return str.substring(0, 1).toLowerCase()
14+
+ str.substring(1)
15+
.replace(/_([a-z])/g, function ($0: string, $1: string) { return $1.toUpperCase(); });
16+
};

packages/utils/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export * from "./typechecks";
99
export * from "./chain";
1010
export * from "./rpc";
1111
export * from "./logs";
12-
export * from "./events";
12+
export * from "./events";
13+
export * from "./case";

0 commit comments

Comments
 (0)