Compare commits

...

2 Commits

Author SHA1 Message Date
9ca6c78f66 打包不显示源码的配置,获取最新高度的机制更新 2021-09-30 11:57:30 +08:00
d4c4605d7e statsh 2021-09-30 09:14:12 +08:00
6 changed files with 73 additions and 39 deletions

View File

@@ -13,7 +13,6 @@
"@element-plus/icons": "^0.0.11",
"axios": "^0.21.4",
"element-plus": "^1.1.0-beta.16",
"js-base64": "^3.7.2",
"vue": "^3.2.11",
"vue-router": "^4.0.11",
"vuex": "^4.0.2",

View File

@@ -1,5 +1,6 @@
import { block } from '@/api'
import vuex from '@/store'
import { hexCharCodeToStr } from '@/utils/filters'
import { ElMessage } from 'element-plus'
import { computed, onMounted, ref } from 'vue'
import { onBeforeRouteLeave } from 'vue-router'
@@ -12,11 +13,16 @@ export default () => {
const interval = ref<NodeJS.Timeout | null>()
onMounted(() => {
getLastHeader()
console.log('开始轮询头信息')
interval.value = setInterval(() => {
getLastHeader()
}, 5000)
})
/**
* 获取最新的区块
*/
const getLastHeader = () => {
block.getLastHeader().then(res => {
if (res.error) {
@@ -26,18 +32,29 @@ export default () => {
offset: 300
})
} else if (maxHeight.value !== res.result.height) {
console.log('获取最新区块', res.result.height)
vuex.dispatch('setMaxHeight', res.result.height).then()
vuex.dispatch('setLastHash', res.result.hash).then()
}
})
}
/**
* 查询从交易量和交易费
*/
const queryTotalFee = () => {
return block.queryTotalFee(hexCharCodeToStr(lastHash.value))
}
onBeforeRouteLeave(() => {
console.log('结束轮询')
clearInterval(Number(interval.value))
})
return {
maxHeight,
lastHash
lastHash,
queryTotalFee
}
}

View File

@@ -18,7 +18,7 @@ export const parseSymbol = (assets?: AssetType[]): string => {
}
}
export const timestampToTime = (timestamp: number) => {
export const timestampToTime = (timestamp: number): string => {
const date = new Date(timestamp * 1000)
const Y = date.getFullYear() + '-'
const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'
@@ -29,34 +29,55 @@ export const timestampToTime = (timestamp: number) => {
return Y + M + D + h + m + s
}
export function bin2hex(str:string):string {
export function bin2hex (str: string): string {
let ret = ''
const r = /[0-9a-zA-Z_.~!*()]/
for (let i = 0, l = str.length; i < l; i++) {
if (r.test(str.charAt(i))) {
ret += str.charCodeAt(i).toString(16);
ret += str.charCodeAt(i).toString(16)
console.log(ret)
} else {
ret += encodeURIComponent(str.charAt(i)).replace(/%/g, '');
ret += encodeURIComponent(str.charAt(i)).replace(/%/g, '')
}
}
return ret;
return ret
}
export const hex2bin = (str: string): string => {
let ret = ''
let tmp = ''
for (let i = 0; i < str.length - 1; i += 2) {
const c = String.fromCharCode(parseInt(str.substr(i, 2), 16))
if (c.charCodeAt(1) > 127) {
tmp += '%' + str.substr(i, 2);
if (tmp.length == 9) {
ret += decodeURIComponent(tmp);
tmp = '';
}
} else {
ret += c;
}
export function hexCharCodeToStr (hexCharCodeStr: string): string[] {
const trimedStr = hexCharCodeStr.trim()
const rawStr = trimedStr.substr(0, 2).toLowerCase() === '0x' ? trimedStr.substr(2) : trimedStr
const len = rawStr.length
let curCharCode
const resultStr = []
for (let i = 0; i < len; i = i + 2) {
curCharCode = parseInt(rawStr.substr(i, 2), 16)
resultStr.push(String.fromCharCode(curCharCode))
}
return ret;
return [base64Encode(`TotalFeeKey:${resultStr.join('')}`)]
}
const base64Encode = (input: string): string => {
const _keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
let output = ''
let chr1, chr2, chr3, enc1, enc2, enc3, enc4
let i = 0
while (i < input.length) {
chr1 = input.charCodeAt(i++)
chr2 = input.charCodeAt(i++)
chr3 = input.charCodeAt(i++)
enc1 = chr1 >> 2
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4)
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6)
enc4 = chr3 & 63
if (isNaN(chr2)) {
enc3 = enc4 = 64
} else if (isNaN(chr3)) {
enc4 = 64
}
output = output +
_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
_keyStr.charAt(enc3) + _keyStr.charAt(enc4)
}
return output
}

View File

@@ -2,10 +2,9 @@
<div class="container">
<Breadcrumb :path="[{name: '全部数据'}]"/>
<Pagination
:length="maxHeight"
:title="`全部区块(` + maxHeight + `)`"
:length="txCount"
:title="`数据总数(` + txCount + `)`"
:page-size="pageSize"
@current-change="handleCurrentChange"
>
@@ -23,21 +22,23 @@
</div>
</template>
<script lang="ts">
export default {
name: 'Trade'
}
</script>
<script lang="ts" setup>
import { Breadcrumb, Pagination } from '@/components'
import { encode } from 'js-base64';
import { ref } from 'vue'
import useGetMaxHeight from '@/hooks/useGetMaxHeight'
import { block } from '@/api'
import { hex2bin } from '@/utils/filters'
import { ref } from 'vue'
const {lastHash, maxHeight} = useGetMaxHeight()
const { queryTotalFee } = useGetMaxHeight()
const keys: string = encode('TotalFeeKey:' + hex2bin(lastHash.value.replace('0x', '')))
const txCount = ref<number>(0)
// 获取全部交易的数据量,但是接口不返回不知道什么问题,可能是因为节点没有seed
block.queryTotalFee([keys]).then(res => {
console.log('queryTotalFee', res.result)
queryTotalFee().then(res => {
txCount.value = res.result.txCount
})
const pageSize = Number(process.env.VUE_APP_BLOCK_LIST_SIZE)

View File

@@ -5,6 +5,7 @@ function resolve (dir) {
}
module.exports = {
productionSourceMap: false,
configureWebpack: {
resolve: {
alias: {

View File

@@ -5483,11 +5483,6 @@ javascript-stringify@^2.0.1:
resolved "https://registry.nlark.com/javascript-stringify/download/javascript-stringify-2.1.0.tgz#27c76539be14d8bd128219a2d731b09337904e79"
integrity sha1-J8dlOb4U2L0Sghmi1zGwkzeQTnk=
js-base64@^3.7.2:
version "3.7.2"
resolved "https://registry.yarnpkg.com/js-base64/-/js-base64-3.7.2.tgz#816d11d81a8aff241603d19ce5761e13e41d7745"
integrity sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==
js-message@1.0.7:
version "1.0.7"
resolved "https://registry.nlark.com/js-message/download/js-message-1.0.7.tgz#fbddd053c7a47021871bb8b2c95397cc17c20e47"