Skip to content

Commit

Permalink
chore: not save ibc channels when cannot get saved ibc channels data (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nrsirapop authored Sep 25, 2024
1 parent 7239031 commit 71c6a66
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 23 deletions.
4 changes: 3 additions & 1 deletion methods/tvl/getTVL.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const { getBalance, getTokenSupply } = require('../../utils/chain/evm');
const { getCosmosBalance, getIBCSupply } = require('../../utils/chain/cosmos');
const { IBC_CHANNEL_COLLECTION, TVL_COLLECTION, getChainsList, getChainData, getAxelarConfig, getAssetsList, getAssetData, getITSAssetsList, getITSAssetData, getContracts, getTVLConfig, getCustomTVLConfig } = require('../../utils/config');
const { toHash, getAddress, split, toArray } = require('../../utils/parser');
const { sleep } = require('../../utils/operator');
const { isString, lastString } = require('../../utils/string');
const { isNumber, toNumber } = require('../../utils/number');
const { timeDiff } = require('../../utils/time');
Expand Down Expand Up @@ -189,7 +190,8 @@ module.exports = async params => {
source_escrow_addresses = toArray(toArray(ibc_channels).map(d => d.counterparty?.escrow_address));
break;
}
else await saveIBCChannels();
else if (data) await saveIBCChannels();
await sleep(3000);
}
}

Expand Down
34 changes: 18 additions & 16 deletions methods/tvl/saveIBCChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,26 @@ module.exports = async () => {
}

const { data } = { ...await read(IBC_CHANNEL_COLLECTION, { match_all: {} }, { size: 1000 }) };
allChannels = toArray(allChannels).map(d => { return { ...toArray(data).find(_d => _d.channel_id === d.channel_id), ...d }; });
allChannels = toArray(allChannels).map(d => ({ ...toArray(data).find(_d => _d.channel_id === d.channel_id), ...d }));

await Promise.all(allChannels.map(channel => new Promise(async resolve => {
const { channel_id, port_id, version, counterparty, updated_at } = { ...channel };
let { chain_id, escrow_address } = { ...channel };
if (data) {
await Promise.all(allChannels.map(channel => new Promise(async resolve => {
const { channel_id, port_id, version, counterparty, updated_at } = { ...channel };
let { chain_id, escrow_address } = { ...channel };

if (!chain_id || !escrow_address || (counterparty && !counterparty.escrow_address) || timeDiff(updated_at * 1000, 'minutes') > 240) {
const response = await request(createInstance(getLCD(), { gzip: true }), { path: `/ibc/core/channel/v1/channels/${channel_id}/ports/${port_id}/client_state` });
const { client_state } = { ...response?.identified_client_state };
chain_id = client_state?.chain_id || chain_id;
if (!chain_id || !escrow_address || (counterparty && !counterparty.escrow_address) || timeDiff(updated_at * 1000, 'minutes') > 240) {
const response = await request(createInstance(getLCD(), { gzip: true }), { path: `/ibc/core/channel/v1/channels/${channel_id}/ports/${port_id}/client_state` });
const { client_state } = { ...response?.identified_client_state };
chain_id = client_state?.chain_id || chain_id;

if (chain_id) {
escrow_address = getAddress(`${version}\x00${port_id}/${channel_id}`) || escrow_address;
const { prefix_address } = { ...getChainData(chain_id, 'cosmos') };
if (counterparty && prefix_address) counterparty.escrow_address = getAddress(`${version}\x00${counterparty.port_id}/${counterparty.channel_id}`, prefix_address);
await write(IBC_CHANNEL_COLLECTION, channel_id, { ...channel, chain_id, counterparty, escrow_address, latest_height: isNumber(client_state?.latest_height?.revision_height) ? toNumber(client_state.latest_height.revision_height) : undefined, updated_at: moment().unix() }, false, false);
if (chain_id) {
escrow_address = getAddress(`${version}\x00${port_id}/${channel_id}`) || escrow_address;
const { prefix_address } = { ...getChainData(chain_id, 'cosmos') };
if (counterparty && prefix_address) counterparty.escrow_address = getAddress(`${version}\x00${counterparty.port_id}/${counterparty.channel_id}`, prefix_address);
await write(IBC_CHANNEL_COLLECTION, channel_id, { ...channel, chain_id, counterparty, escrow_address, latest_height: isNumber(client_state?.latest_height?.revision_height) ? toNumber(client_state.latest_height.revision_height) : undefined, updated_at: moment().unix() }, false, false);
}
}
}
resolve();
})));
resolve();
})));
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "axelarscan-api",
"version": "0.0.85",
"version": "0.0.86",
"description": "Axelarscan API",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion terraform/devnet-amplifier/variables.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "log_level" {

variable "app_version" {
description = "App version, same as docker image version"
default = "0.0.85"
default = "0.0.86"
validation {
error_message = "Must be valid semantic version. $Major.$Minor.$Patch"
condition = can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.app_version))
Expand Down
2 changes: 1 addition & 1 deletion terraform/devnet-verifiers/variables.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "log_level" {

variable "app_version" {
description = "App version, same as docker image version"
default = "0.0.85"
default = "0.0.86"
validation {
error_message = "Must be valid semantic version. $Major.$Minor.$Patch"
condition = can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.app_version))
Expand Down
2 changes: 1 addition & 1 deletion terraform/mainnet/variables.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "log_level" {

variable "app_version" {
description = "App version, same as docker image version"
default = "0.0.85"
default = "0.0.86"
validation {
error_message = "Must be valid semantic version. $Major.$Minor.$Patch"
condition = can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.app_version))
Expand Down
2 changes: 1 addition & 1 deletion terraform/stagenet/variables.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "log_level" {

variable "app_version" {
description = "App version, same as docker image version"
default = "0.0.85"
default = "0.0.86"
validation {
error_message = "Must be valid semantic version. $Major.$Minor.$Patch"
condition = can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.app_version))
Expand Down
2 changes: 1 addition & 1 deletion terraform/testnet/variables.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "log_level" {

variable "app_version" {
description = "App version, same as docker image version"
default = "0.0.85"
default = "0.0.86"
validation {
error_message = "Must be valid semantic version. $Major.$Minor.$Patch"
condition = can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.app_version))
Expand Down

0 comments on commit 71c6a66

Please sign in to comment.