Skip to content

Commit

Permalink
Merge pull request #1815 from nervosnetwork/testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Nov 29, 2024
2 parents 2b7a0ce + 4506cd2 commit e740389
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/pages/Home/Banner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ const { BACKUP_NODES: backupNodes } = config

export default () => {
const { data: size } = useQuery(
['backup_nodes'],
['backnode_tip_header'],
async () => {
try {
if (backupNodes.length === 0) return null

const [size1, size2] = await Promise.race(backupNodes.map(getKnowledgeSize))
return size1 ?? size2
const size = await Promise.race(backupNodes.map(getKnowledgeSize))

return size
} catch {
return null
}
Expand Down
4 changes: 3 additions & 1 deletion src/pages/Home/Banner/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ckbDecimals } from '@ckb-lumos/bi'
import BigNumber from 'bignumber.js'

/**
* 6/10 of 7th output in the genesis should be excluded because they are expected to be burnt.
* ref: https://talk.nervos.org/t/how-to-get-the-average-occupied-bytes-per-live-cell-in-ckb/7138/2?u=keith
* */
const EXCLUDE = BigNumber('504000000000000000')
const CKB_DECIMAL = BigNumber(10).pow(ckbDecimals)

export const getKnowledgeSize = async (nodeUrl: string) => {
const header = await fetch(nodeUrl, {
Expand All @@ -25,6 +27,6 @@ export const getKnowledgeSize = async (nodeUrl: string) => {
.slice(2)
.match(/\w{16}/g)
.map((i: string) => i.match(/\w{2}/g)?.reverse().join('') ?? '')
const total = BigNumber(`0x${u}`).minus(EXCLUDE).toFormat()
const total = BigNumber(`0x${u}`).minus(EXCLUDE).div(CKB_DECIMAL).toNumber()
return total
}

0 comments on commit e740389

Please sign in to comment.