Skip to content

Commit

Permalink
feat: add chain service (tendermint query)
Browse files Browse the repository at this point in the history
  • Loading branch information
fly33499 committed Oct 20, 2021
1 parent 738cafc commit 38c57b4
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
29 changes: 29 additions & 0 deletions sdk/FirmaChainService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { FirmaConfig } from "./FirmaConfig";
import { FirmaUtil } from "./FirmaUtil";
import { TendermintQueryClient } from "./firmachain/common/TendermintQueryClient";

export class ChainService {
constructor(private readonly config: FirmaConfig) { }

async getChainStatus(): Promise<string> {
try {
const queryClient = new TendermintQueryClient(this.config.rpcAddress);
return await queryClient.queryChainHeight();

} catch (error) {
FirmaUtil.printLog(error);
throw error;
}
}

async getTransactionByHash(txHash: string): Promise<string> {
try {
const queryClient = new TendermintQueryClient(this.config.rpcAddress);
return await queryClient.queryTransactionHash(txHash);

} catch (error) {
FirmaUtil.printLog(error);
throw error;
}
}
}
5 changes: 3 additions & 2 deletions sdk/FirmaSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { IpfsService } from "./FirmaIpfsService";
import { FirmaWalletService } from "./FirmaWalletService";
import { FirmaUtil } from "./FirmaUtil";
import { FirmaGovService } from "./FirmaGovService";
//import config = FirmaUtil.config;
import { ChainService } from "./FirmaChainService";

export class FirmaSDK {
constructor(public Config: FirmaConfig,
Expand All @@ -21,7 +21,8 @@ export class FirmaSDK {
public Gov: FirmaGovService = new FirmaGovService(Config),
public Nft: NftService = new NftService(Config),
public Contract: ContractService = new ContractService(Config),
public Ipfs: IpfsService = new IpfsService(Config)) {
public Ipfs: IpfsService = new IpfsService(Config),
public BlockChain: ChainService = new ChainService(Config)) {

FirmaUtil.config = Config;
}
Expand Down
16 changes: 16 additions & 0 deletions sdk/firmachain/common/TendermintQueryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ export class TendermintQueryClient {

return Number.parseInt(jsonData.gas_info.gas_used);
}

async queryChainHeight(): Promise<string> {

const path = "/status";
const result = await this.axios.get(path);

return JSON.stringify(result.data.result);
}

async queryTransactionHash(txHash: string): Promise<string> {

const path = "/tx?hash=" + txHash;
const result = await this.axios.get(path);

return JSON.stringify(result.data.result);
}
}

// https://imperium-lcd.firmachain.org:26657/abci_query?path=%22app/simulate%22&data=0x0a9b010a8d010a1c2f636f736d6f732e62616e6b2e763162657461312e4d736753656e64126d0a2c6669726d6131747271796c65396d326e7679616663326e323566726b70776564323530347936617667667a72122c6669726d6131306e65336e77346b63666a36766a7a38346c326d33676a38767961637a66686d6135666636391a0f0a0475666374120731303030303030120974657374206d656d6f12670a510a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a21027b57273b1d23a87862c6a47f214d77b6144b552498c2dff9e9368551b4e08a8c12040a02080118e60412120a0c0a047566637412043230303010c09a0c1a40ce1072ff09660c80595b7ff2fec36062ebcf8fde88947f1fa3f6cb5ff808edba04fcf584f81ce52e5ec9be6724759fb58a411a17ed2816210f4df5b811117e4c
Expand Down

0 comments on commit 38c57b4

Please sign in to comment.