Skip to content

Commit 9e3f190

Browse files
committed
use basetore blocktime, eliminate redundant block fetching
1 parent 1bfc76c commit 9e3f190

File tree

6 files changed

+222
-78
lines changed

6 files changed

+222
-78
lines changed

chains/mainnet/xion.json

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
{
2+
"chain_name": "xion",
3+
"registry_name": "xion",
4+
"coingecko": "xion",
5+
"network_type": "mainnet",
6+
"rpc": [
7+
{
8+
"address": "https://rpc.xion-mainnet-1.burnt.com",
9+
"provider": "🔥BurntLabs🔥"
10+
},
11+
{
12+
"address": "https://rpc-burnt.imperator.co/",
13+
"provider": "Imperator.co"
14+
},
15+
{
16+
"address": "https://xion-rpc.polkachu.com",
17+
"provider": "Polkachu"
18+
}
19+
],
20+
"api": [
21+
{
22+
"address": "https://api.xion-mainnet-1.burnt.com",
23+
"provider": "🔥BurntLabs🔥"
24+
},
25+
{
26+
"address": "https://lcd-burnt.imperator.co/",
27+
"provider": "Imperator.co"
28+
},
29+
{
30+
"address": "https://xion-api.polkachu.com",
31+
"provider": "Polkachu"
32+
}
33+
],
34+
"snapshot_provider": "",
35+
"sdk_version": "0.50.13",
36+
"coin_type": "118",
37+
"min_tx_fee": "100",
38+
"addr_prefix": "xion",
39+
"theme_color": "#96b325",
40+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/xion/images/burnt-round.png",
41+
"assets": [
42+
{
43+
"base": "uxion",
44+
"symbol": "XION",
45+
"exponent": "6",
46+
"coingecko_id": "xion-2",
47+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/xion/images/burnt-round.png"
48+
},
49+
{
50+
"base": "ibc/0471F1C4E7AFD3F07702BEF6DC365268D64570F7C1FDC98EA6098DD6DE59817B",
51+
"symbol": "OSMO",
52+
"exponent": "6",
53+
"coingecko_id": "osmosis",
54+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png"
55+
},
56+
{
57+
"base": "ibc/F082B65C88E4B6D5EF1DB243CDA1D331D002759E938A0F5CD3FFDC5D53B3E349",
58+
"symbol": "USDC",
59+
"exponent": "6",
60+
"coingecko_id": "usd-coin",
61+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/noble/images/USDCoin.png"
62+
},
63+
{
64+
"base": "ibc/CC7B293B3F08EA7DB96AFD4765BD0C7F95ABD7ECEAF21C74F3ACCBF7CEFB6591",
65+
"symbol": "OSMO",
66+
"exponent": "6",
67+
"coingecko_id": "osmosis",
68+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/images/osmo.png"
69+
},
70+
{
71+
"base": "ibc/9463E39D230614B313B487836D13A392BD1731928713D4C8427A083627048DB3",
72+
"symbol": "AXL",
73+
"exponent": "6",
74+
"coingecko_id": "axelar",
75+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axl.png"
76+
},
77+
{
78+
"base": "ibc/6490A7EAB61059BFC1CDDEB05917DD70BDF3A611654162A1A47DB930D40D8AF4",
79+
"symbol": "axlUSDC",
80+
"exponent": "6",
81+
"coingecko_id": "usd-coin",
82+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axlusdc.png"
83+
},
84+
{
85+
"base": "ibc/0000000000000000000000000000000000000000000000000000000000000000",
86+
"symbol": "axlUSDT",
87+
"exponent": "6",
88+
"coingecko_id": "tether",
89+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axlusdc.png"
90+
},
91+
{
92+
"base": "ibc/0000000000000000000000000000000000000000000000000000000000000000",
93+
"symbol": "axlDAI",
94+
"exponent": "18",
95+
"coingecko_id": "dai",
96+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axldai.png"
97+
},
98+
{
99+
"base": "ibc/0000000000000000000000000000000000000000000000000000000000000000",
100+
"symbol": "axlFRAX",
101+
"exponent": "6",
102+
"coingecko_id": "frax",
103+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/axlfrax.png"
104+
},
105+
{
106+
"base": "ibc/AAD7136DD626569C3DDE7C5F764968BB2E939875EFC568AE5712B62081850814",
107+
"symbol": "axlWETH",
108+
"exponent": "18",
109+
"coingecko_id": "axlweth",
110+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/axelar/images/weth.png"
111+
},
112+
{
113+
"base": "ibc/056EA54C3D9B49B3C0418955A27980A91DD4F210914BFE240A1DB19E27895ECA",
114+
"symbol": "KYVE",
115+
"exponent": "6",
116+
"coingecko_id": "kyve-network",
117+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/kyve/images/kyve-token.png"
118+
},
119+
{
120+
"base": "ibc/DBE9697AC1044255A305A2034AD360B4152632BFBFB5785234731F60196B9645",
121+
"symbol": "ELYS",
122+
"exponent": "6",
123+
"coingecko_id": "elys",
124+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/elys/images/elys.png"
125+
},
126+
{
127+
"base": "ibc/E706A0C6CACB374ADC2BCF6A74FE1B260840FC822E45DCB776DEA962A57FED30",
128+
"symbol": "axlARB",
129+
"exponent": "18",
130+
"coingecko_id": "arb",
131+
"logo": "https://raw.githubusercontent.com/cosmos/chain-registry/master/_non-cosmos/arbitrum/images/arb.png"
132+
}
133+
],
134+
"features": [
135+
"dashboard",
136+
"governance",
137+
"staking",
138+
"blocks",
139+
"tx",
140+
"uptime",
141+
"ibc",
142+
"supply",
143+
"parameters",
144+
"consensus",
145+
"cosmwasm",
146+
"account"
147+
],
148+
"keplr_features": ["ibc-go", "ibc-transfer", "no-legacy-stdTx"]
149+
}

src/main.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import App from '@/App.vue';
33
import i18n from '@/plugins/i18n';
44
import '@/style.css';
5-
import { createApp, ref } from 'vue';
5+
import { createApp, ref, watch } from 'vue';
66
import { createPinia } from 'pinia';
77
import LazyLoad from 'lazy-load-vue3';
88

@@ -19,13 +19,32 @@ app.use(LazyLoad, { component: true });
1919
// Mount vue app
2020
app.mount('#app');
2121

22-
// fetch latest block every 6s
23-
const blockStore = useBaseStore();
22+
// fetch latest block every <blocktime> ms
23+
const baseStore = useBaseStore();
2424
const requestCounter = ref(0);
25-
setInterval(() => {
26-
requestCounter.value += 1;
27-
if (requestCounter.value < 5) {
28-
// max allowed request
29-
blockStore.fetchLatest().finally(() => (requestCounter.value -= 1));
25+
26+
let intervalId: NodeJS.Timeout;
27+
28+
const startInterval = () => {
29+
clearInterval(intervalId); // Clear any existing interval
30+
// console.log('Starting interval with blocktime:', baseStore.blocktime);
31+
32+
intervalId = setInterval(() => {
33+
requestCounter.value += 1;
34+
if (requestCounter.value < 5) {
35+
// max allowed request
36+
baseStore.fetchLatest().finally(() => (requestCounter.value -= 1));
37+
}
38+
}, baseStore.blocktime);
39+
};
40+
41+
// Call startInterval initially
42+
startInterval();
43+
44+
// Watch for changes to baseStore.blocktime
45+
watch(
46+
() => baseStore.blocktime,
47+
() => {
48+
startInterval(); // Restart the interval when baseStore.blocktime changes
3049
}
31-
}, 6000);
50+
);

src/modules/[chain]/block/block.ts

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,42 @@
11
import { defineStore } from 'pinia';
2-
import { decodeTxRaw, type DecodedTxRaw } from '@cosmjs/proto-signing';
3-
import { useBlockchain } from '@/stores';
4-
import { hashTx } from '@/libs';
5-
import type { Block } from '@/types';
2+
import { useBaseStore, useBlockchain } from '@/stores';
63

74
export const useBlockModule = defineStore('blockModule', {
8-
state: () => {
9-
return {
10-
latest: {} as Block,
11-
current: {} as Block,
12-
recents: [] as Block[],
13-
};
14-
},
155
getters: {
6+
baseStore() {
7+
return useBaseStore();
8+
},
169
blockchain() {
1710
return useBlockchain();
1811
},
1912
blocktime() {
20-
if (this.recents.length < 2) return 6000;
21-
return 6000; // todo later
13+
return useBaseStore().blocktime;
2214
},
2315
txsInRecents() {
24-
const txs = [] as { hash: string; tx: DecodedTxRaw }[];
25-
this.recents.forEach((x) =>
26-
x.block?.data?.txs.forEach((tx: Uint8Array) => {
27-
if (tx) {
28-
try {
29-
txs.push({
30-
hash: hashTx(tx),
31-
tx: decodeTxRaw(tx),
32-
});
33-
} catch (e) {}
34-
}
35-
})
36-
);
37-
return txs;
16+
return useBaseStore().txsInRecents;
17+
},
18+
latest(){
19+
return useBaseStore().latest;
3820
},
21+
earliest() {
22+
return useBaseStore().earlest;
23+
},
24+
recents() {
25+
return useBaseStore().recents;
26+
}
3927
},
4028
actions: {
4129
initial() {
4230
this.clearRecentBlocks();
43-
this.autoFetch();
4431
},
4532
async clearRecentBlocks() {
46-
this.recents = [];
47-
},
48-
autoFetch() {
49-
this.fetchLatest().then((x) => {
50-
const timer = this.autoFetch;
51-
this.latest = x;
52-
// if(this.recents.length >= 50) this.recents.pop()
53-
// this.recents.push(x)
54-
// setTimeout(timer, 6000)
55-
});
33+
return this.baseStore.clearRecentBlocks()
5634
},
5735
async fetchLatest() {
58-
this.latest = await this.blockchain.rpc?.getBaseBlockLatest();
59-
if (this.recents.length >= 50) this.recents.shift();
60-
this.recents.push(this.latest);
61-
return this.latest;
36+
return this.baseStore.fetchLatest()
6237
},
6338
async fetchBlock(height: string) {
64-
this.current = await this.blockchain.rpc?.getBaseBlockAt(height);
65-
return this.current;
39+
return this.baseStore.fetchBlock(height)
6640
},
6741
},
6842
});

src/modules/[chain]/consensus/index.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script lang="ts" setup>
22
import fetch from 'cross-fetch';
33
import { onMounted, ref, computed, onUnmounted } from 'vue';
4-
import { useBlockchain, useFormatter, useStakingStore } from '@/stores';
4+
import { useBlockchain, useFormatter, useStakingStore, useBaseStore } from '@/stores';
55
import { consensusPubkeyToHexAddress } from '@/libs';
66
77
const format = useFormatter();
88
const chainStore = useBlockchain();
99
const stakingStore = useStakingStore();
10+
const baseStore = useBaseStore();
1011
const rpcList = ref(chainStore.current?.endpoints?.rpc || [{ address: '', provider: '' }]);
1112
let rpc = ref('');
1213
const validators = ref(stakingStore.validators);
@@ -31,7 +32,7 @@ onMounted(async () => {
3132
clearTime();
3233
timer = setInterval(() => {
3334
update();
34-
}, 6000);
35+
}, Math.round(baseStore.blocktime / 2));
3536
});
3637
onUnmounted(() => {
3738
clearTime();
@@ -87,7 +88,7 @@ async function onChange() {
8788
update();
8889
timer = setInterval(() => {
8990
update();
90-
}, 6000);
91+
}, Math.round(baseStore.blocktime / 2));
9192
}
9293
9394
async function fetchPosition() {

0 commit comments

Comments
 (0)