Magickbase / ckb-explorer-public-issues

CKB Explorer Issues
https://explorer.nervos.org/
3 stars 2 forks source link

Add a chart for history of knowledge size #797

Open Keith-CY opened 5 days ago

Keith-CY commented 5 days ago

Is your feature request related to a problem? Please describe.

The knowledge size is the size occupied by on-chain data, not the declared size of cells. It reveals how many resources are used to share common knowledge, which is an important index for users.

Describe the solution you'd like The current knowledge size can be calculated as described in https://talk.nervos.org/t/how-to-get-the-average-occupied-bytes-per-live-cell-in-ckb/7138/2?u=keith

And here is the code

const EXCLUDE = BigNumber('504000000000000000')
const getKnowledgeSize = async (nodeUrl: string) => {
  const header = await fetch(nodeUrl, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      id: 1,
      jsonrpc: '2.0',
      method: 'get_tip_header',
      params: [],
    }),
  })
    .then(res => res.json())
    .then(res => res.result)
  const { dao } = header

  const [, , , u] = dao
    .slice(2)
    .match(/\w{16}/g)
    .map((i: string) => i.match(/\w{2}/g)?.reverse().join('') ?? '')
  const total = BigNumber(`0x${u}`).minus(EXCLUDE).toFormat()
  return total
}

A chart of its history can be added in the explorer so we can see how it grew in the past.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

rabbitz commented 2 days ago

PR: https://github.com/nervosnetwork/ckb-explorer/pull/2302/commits/de6f7d419c466b882fc5fd98f465ce015a65feea

curl 'https://ckb-explorer-api-staging.magickbase.com/api/v1/daily_statistics/knowledge_size' \
  -H 'accept: application/vnd.api+json' \
  -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8,sa;q=0.7' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/vnd.api+json'