Efficiently sorting Ethereum blockchain

0 votes

I am trying to sort the whole Ethereum blockchain, trying to loop and sort a large number of data.

I am using the following code to do it:

        var txs = {};
var i = 0;
// Loop over blocks
(function loop () {
setTimeout(function () {
  // Get current block
  var block = web3.eth.getBlock(i, true, (error, block) => {
    // debugger;
    // Loop over transactions in block
    for(var j = 0; j < block.transactions.length; j++) {
      // debugger;
      if(txs[block.transactions[j].to]) {
        txs[block.transactions[j].to].transactions.push(block.transactions[j]);
      } else if (txs[block.transactions[j].to]) {
        txs[block.transactions[j].from].transactions.push(block.transactions[j]);
      } else {
        txs[block.transactions[j].to] = {
          transactions: [block.transactions[j]]
        }
        txs[block.transactions[j].from] = {
          transactions: [block.transactions[j]]
        }
      }
    }
  });
  i++
  if (i < highestBlock) {
    loop();
  }
 }, 50);
})();

Is there an efficient way to do it compared to the method I am trying?

Jul 25, 2018 in Blockchain by digger
• 26,740 points
761 views

1 answer to this question.

0 votes

What you are trying to do is a very intensive process. You are trying to create a record of all transactions for every address. Your code seems to have an error at the “else-if” point. You should use the txs[block.transactions[j].from] property and not the txs[block.transactions[j].to]. You could also use a recursive pattern by using setImmediate function or the process.nextTick method and use a Map instead of the Object.

answered Jul 25, 2018 by slayer
• 29,350 points

Related Questions In Blockchain

0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 1,354 views
+1 vote
1 answer

What is Ethereum Blockchain? Where is it being used?

Blockchain is a decentralized distributed database of immutable records, ...READ MORE

answered Apr 3, 2018 in Blockchain by Christine
• 15,790 points
767 views
+1 vote
2 answers

What is a blockchain and ethereum?

Some of the use-cases are: Healthcare Medical records are ...READ MORE

answered Aug 9, 2018 in Blockchain by Omkar
• 69,210 points
587 views
+1 vote
1 answer

How to store state data in Ethereum blockchain?

You won't have to overwrite the whole ...READ MORE

answered Apr 25, 2018 in Blockchain by Shashank
• 10,400 points
717 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,215 views
0 votes
1 answer

How to create a Genesis Block in a Private Network?

{     "nonce": "0x0000000000000042",     "difficulty": "0x000000100",     "alloc": {     },     "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",     "coinbase": "0x0000000000000000000000000000000000000000",     "timestamp": "0x00",     "parentHash": ...READ MORE

answered Jul 12, 2018 in Blockchain by digger
• 26,740 points
1,797 views
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,740 points
708 views
0 votes
1 answer
0 votes
1 answer

How to extract Ethereum Blockchain data?

You are using web3.eth.getTransaction(txHash) web3.eth.getTransaction(txHash) will only return info ...READ MORE

answered Jul 30, 2018 in Blockchain by slayer
• 29,350 points
1,396 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP