Skip to content

Commit

Permalink
Merge pull request #9 from hoangdv2429/feat/customer_usage
Browse files Browse the repository at this point in the history
Feat/customer usage
  • Loading branch information
kaisbaccour authored Jan 18, 2024
2 parents 5e2e6fc + 27410ac commit e7baf10
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
15 changes: 10 additions & 5 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HttpBatchClient, Tendermint34Client } from "npm:@cosmjs/tendermint-rpc"
import * as promclient from "npm:prom-client";
import express from "npm:express@4.18.2";
import settings from "./settings.ts";
import { communityPoolFunds, getContractUsage, totalSupply } from "./queries.ts";
import { communityPoolFunds, getContractUsage, getIbcChannels, totalSupply } from "./queries.ts";

function printableCoin(coin: Coin): string {
if (coin.denom?.startsWith("u")) {
Expand All @@ -18,7 +18,7 @@ function printableCoin(coin: Coin): string {
}


function mapChannelToDescription(chainId: string,channelId: string): string {
function mapChannelToDescription(chainId: string, channelId: string): string {
// Default to a unknown if the channel is not found
return settings[chainId].mappingChannels[channelId] || "unknown-proxy";
}
Expand Down Expand Up @@ -125,17 +125,22 @@ if (import.meta.main) {
tmClient,
settings[chainId].gatewayAddr
);


// get an array of channels infos
const channelsInfo = await getIbcChannels(tmClient);

// array of customer data
for (const customer of contractState.customers) {
const description = mapChannelToDescription(chainId, customer.channel_id); // Implement this mapping function
const description = mapChannelToDescription(chainId, customer.channel_id);
const connection = channelsInfo.filter(channel => channel.channelId === customer.channel_id);

customerUsageGauge.set(
{
channel: customer.channel_id,
rpcEndpoint: rpcEndpoint,
chainId: chainId,
description: description,
address: customer.payment,
address: connection[0].counterparty?.portId?.slice(5)
},
customer.requested_beacons
);
Expand Down
14 changes: 14 additions & 0 deletions queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
QueryClient,
setupBankExtension,
setupDistributionExtension,
setupIbcExtension
} from "npm:@cosmjs/stargate";
import { setupWasmExtension } from "npm:@cosmjs/cosmwasm-stargate";

Expand Down Expand Up @@ -45,3 +46,16 @@ export async function getContractUsage(
}
return res;
}

export async function getIbcChannels(
tmClient: TendermintClient
) {
const queryClient = QueryClient.withExtensions(tmClient, setupIbcExtension);
let res, filteredChannels;
try {
res = await queryClient.ibc.channel.channels();
} catch (error) {
console.error(error);
}
return res.channels;
}

0 comments on commit e7baf10

Please # to comment.