尝试计算trades

This commit is contained in:
zhangdongxue
2021-09-29 21:37:55 +08:00
parent 33dc44c4c7
commit 4b2ce62cea
9 changed files with 103 additions and 13 deletions

View File

@@ -13,6 +13,7 @@
"@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,3 +1,3 @@
import Chain33Rpc from '@33cn/chain33-rpc-api'
export default new Chain33Rpc('http://47.100.214.15:8080/api', null)
export default new Chain33Rpc('https://explorer.lianshang.vip/api', null)

View File

@@ -6,6 +6,7 @@ import { onBeforeRouteLeave } from 'vue-router'
export default () => {
const maxHeight = computed(() => vuex.getters.maxHeight)
const lastHash = computed(() => vuex.getters.lastHash)
// eslint-disable-next-line no-undef
const interval = ref<NodeJS.Timeout | null>()
@@ -26,6 +27,7 @@ export default () => {
})
} else if (maxHeight.value !== res.result.height) {
vuex.dispatch('setMaxHeight', res.result.height).then()
vuex.dispatch('setLastHash', res.result.hash).then()
}
})
}
@@ -35,6 +37,7 @@ export default () => {
})
return {
maxHeight
maxHeight,
lastHash
}
}

View File

@@ -17,6 +17,7 @@ export interface State {
openId: string
loginAt: number
maxHeight: number
lastHash: string
user: BaseInfo
auth?: AuthState
refresh?: RefreshState
@@ -31,6 +32,7 @@ export default createStore<State>({
openId: '',
loginAt: 0,
maxHeight: 0,
lastHash: '',
user: {} as BaseInfo
},
getters: {
@@ -48,6 +50,9 @@ export default createStore<State>({
},
symbol: (): string => {
return process.env.VUE_APP_MAIN_COIN_SYMBOL as string
},
lastHash: (state: State): string => {
return state.lastHash
}
},
mutations: {
@@ -74,17 +79,23 @@ export default createStore<State>({
},
setMaxHeight: (state: State, height: number): void => {
state.maxHeight = height
},
setLastHash: (state: State, hash: string): void => {
state.lastHash = hash
}
},
actions: {
setUserInfo: ({ commit }, info: BaseInfo): void => {
setUserInfo: ({commit}, info: BaseInfo): void => {
commit('setUserInfo', info)
},
setOpenId: ({ commit }, openId: string): void => {
setOpenId: ({commit}, openId: string): void => {
commit('setOpenId', openId)
},
setMaxHeight: ({ commit }, height: number): void => {
setMaxHeight: ({commit}, height: number): void => {
commit('setMaxHeight', height)
},
setLastHash: ({commit}, hash: string): void => {
commit('setLastHash', hash)
}
},
modules: {

11
src/types/block.d.ts vendored
View File

@@ -95,3 +95,14 @@ export declare type BlockDetail = {
tyName: string
}
}
export declare type TradeItem = {
txHash: string
blockTime: number
fromAddr: string
amount: number
assets: any
tx: {
to: string
}
}

View File

@@ -28,3 +28,35 @@ export const timestampToTime = (timestamp: number) => {
const s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
return Y + M + D + h + m + s
}
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);
console.log(ret)
} else {
ret += encodeURIComponent(str.charAt(i)).replace(/%/g, '');
}
}
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;
}
}
return ret;
}

View File

@@ -80,7 +80,7 @@ export default {
import { block } from '@/api'
import { Banner, TimeFormat } from '@/components'
import useGetMaxHeight from '@/hooks/useGetMaxHeight'
import { BlockItem } from '@/types/block'
import { BlockItem, TradeItem } from '@/types/block'
import { filterHash, parseSymbol } from '@/utils/filters'
import { onMounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
@@ -103,20 +103,36 @@ watch(maxHeight, (newValue, oldValue) => {
})
const blockList = ref<BlockItem[]>([])
const tradeList = ref([])
const tradeList = ref<TradeItem[]>([])
if (blockList.value.length === 0) {
let initBlock = {
const initBlock = {
height: 0,
hash: 'x',
hash: ' ',
txCount: 0,
blockTime: 0
}
} as BlockItem
for (let i = 0; i < 6; i++) {
blockList.value.push(initBlock)
}
}
if (tradeList.value.length === 0) {
const initTrade = {
txHash: ' ',
blockTime: 0,
fromAddr: ' ',
amount: 0,
assets: null,
tx: {
to: ' '
}
} as TradeItem
for (let i = 0; i < 6; i++) {
tradeList.value.push(initTrade)
}
}
const getBlockList = () => {
const start = maxHeight.value - pageSize + 1 > 0 ? maxHeight.value - pageSize + 1 : 0

View File

@@ -25,11 +25,22 @@
<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'
const currentPage = ref<number>(1)
const pageSize = ref<number>(20)
const {lastHash, maxHeight} = useGetMaxHeight()
const keys: string = encode('TotalFeeKey:' + hex2bin(lastHash.value.replace('0x', '')))
// 获取全部交易的数据量,但是接口不返回不知道什么问题,可能是因为节点没有seed
block.queryTotalFee([keys]).then(res => {
console.log('queryTotalFee', res.result)
})
const pageSize = Number(process.env.VUE_APP_BLOCK_LIST_SIZE)
const handleCurrentChange = (e: number) => {
console.log(e)
}

View File

@@ -5483,6 +5483,11 @@ 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"