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
• 27,620 points
62 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,040 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 59 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 2, 2018 in Blockchain by Christine
• 15,790 points
37 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
• 65,850 points
40 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 24, 2018 in Blockchain by Shashank
• 10,330 points
37 views
0 votes
1 answer
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
• 27,620 points
62 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
• 27,620 points
41 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 29, 2018 in Blockchain by slayer
• 29,040 points
34 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.