Browse Source

use new paginated blocks endpoint

readme
Mayank 5 years ago
parent
commit
81147bc881
No known key found for this signature in database GPG Key ID: D037D60476CE748C
  1. 10
      src/components/Blockchain.vue
  2. 64
      src/store/modules/bitcoin.js

10
src/components/Blockchain.vue

@ -61,8 +61,8 @@
<h6 class="mb-1 font-weight-normal">Block {{ block.height.toLocaleString() }}</h6>
<small
class="text-muted"
v-if="block.txs"
>{{ block.txs.toLocaleString() }} transactions</small>
v-if="block.numTransactions"
>{{ block.numTransactions.toLocaleString() }} transactions</small>
<!-- <small class="text-muted" v-if="block.txs"> -->
<!-- <status variant="muted" blink>Validating</status> -->
<!-- <status variant="success">Valid</status> -->
@ -73,9 +73,9 @@
<status variant="success" v-if="false">Valid</status>
<small
class="text-muted align-self-center text-right blockchain-block-timestamp"
v-if="block.timestamp"
:title="blockReadableTime(block.timestamp)"
>{{ blockTime(block.timestamp) }}</small>
v-if="block.time"
:title="blockReadableTime(block.time)"
>{{ blockTime(block.time) }}</small>
</div>
</li>
</transition-group>

64
src/store/modules/bitcoin.js

@ -236,70 +236,22 @@ const actions = {
//cache block height array of latest 3 blocks for loading view
const currentBlock = state.currentBlock;
//dont fetch blocks if no new block
//dont fetch blocks if no new block has been found
if (state.blocks.length && currentBlock === state.blocks[0]["height"]) {
return;
}
if (currentBlock < 4) {
return;
}
const blocks = [
{
height: currentBlock, //block height
txs: null,
timestamp: null,
size: null
},
{
height: currentBlock - 1, //block height
txs: null,
timestamp: null,
size: null
},
{
height: currentBlock - 2, //block number
txs: null,
timestamp: null,
size: null
}
];
// commit("setBlocks", blocks);
//fetch info per block;
const blocksWithInfo = [];
for (let block of blocks) {
//get hash
const blockHash = await API.get(
`${process.env.VUE_APP_API_URL}/v1/bitcoind/info/block?height=${block.height}`
);
if (!blockHash || !blockHash.hash) {
return;
}
//gete block info
const blockInfo = await API.get(
`${process.env.VUE_APP_API_URL}/v1/bitcoind/info/block?hash=${blockHash.hash}`
);
if (!blockInfo || !blockInfo.block) {
return;
}
//TODO: Fetch only new blocks
const latestThreeBlocks = await API.get(
`${process.env.VUE_APP_API_URL}/v1/bitcoind/info/blocks?from=${currentBlock - 2}&to=${currentBlock}`
);
blocksWithInfo.push({
height: blockInfo.height,
txs: blockInfo.transactions.length,
timestamp: blockInfo.blocktime,
size: blockInfo.size
});
if (!latestThreeBlocks.blocks) {
return;
}
// update blocks
commit("setBlocks", blocksWithInfo);
commit("setBlocks", latestThreeBlocks.blocks);
}
},

Loading…
Cancel
Save