diff --git a/sdk/FirmaChainService.ts b/sdk/FirmaChainService.ts new file mode 100644 index 0000000..ee95d89 --- /dev/null +++ b/sdk/FirmaChainService.ts @@ -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 { + try { + const queryClient = new TendermintQueryClient(this.config.rpcAddress); + return await queryClient.queryChainHeight(); + + } catch (error) { + FirmaUtil.printLog(error); + throw error; + } + } + + async getTransactionByHash(txHash: string): Promise { + try { + const queryClient = new TendermintQueryClient(this.config.rpcAddress); + return await queryClient.queryTransactionHash(txHash); + + } catch (error) { + FirmaUtil.printLog(error); + throw error; + } + } +} \ No newline at end of file diff --git a/sdk/FirmaSDK.ts b/sdk/FirmaSDK.ts index 5cf74df..cf6f712 100644 --- a/sdk/FirmaSDK.ts +++ b/sdk/FirmaSDK.ts @@ -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, @@ -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; } diff --git a/sdk/firmachain/common/TendermintQueryClient.ts b/sdk/firmachain/common/TendermintQueryClient.ts index c433573..ccae142 100644 --- a/sdk/firmachain/common/TendermintQueryClient.ts +++ b/sdk/firmachain/common/TendermintQueryClient.ts @@ -25,6 +25,22 @@ export class TendermintQueryClient { return Number.parseInt(jsonData.gas_info.gas_used); } + + async queryChainHeight(): Promise { + + const path = "/status"; + const result = await this.axios.get(path); + + return JSON.stringify(result.data.result); + } + + async queryTransactionHash(txHash: string): Promise { + + 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