Sorting data into appropriate key in an object

0 votes

I'm trying to loop & sort a large number of data ( the whole ethereum blockchain lol )

I'm trying to create a record of all transactions for every address.

Obviously this is a very intensive process and I'm not sure how to make it more efficient beyond what I have (which isn't that efficient)

It starts out quick but I'm thinking now it has slowed because of the lookup for the address in the txs object.

Any help opinions / help is greatly appreciated.

https://giphy.com/gifs/3o6fJ7KWqxESY9okk8

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);
})();
Jul 17, 2018 in Blockchain by charlie_brown
• 7,720 points
22 views

1 answer to this question.

0 votes

I think that your code has an error in it located at "else-if", it seems that you should use the txs[block.transactions[j].from] property instead of the txs[block.transactions[j].to]. If you simply want to accomplish a recursive pattern you could use the setImmediate function or the process.nextTick method. If you use node.js v6+ you could use a Map instead of the object

answered Jul 17, 2018 by ariaholic
• 7,340 points

Related Questions In Blockchain

0 votes
1 answer

How to track changes of an object in exonum?

You have to describe each component in ...READ MORE

answered Jul 23, 2018 in Blockchain by slayer
• 29,050 points
45 views
+1 vote
1 answer

Can a data be altered in a blockchain without changing its hash?

Yes, it should work. The authentication practice ...READ MORE

answered Apr 7, 2018 in Blockchain by Shashank
• 10,350 points
43 views
+1 vote
2 answers

Can I include real world data in a smart contract? If so, how?

You cant access/embed real world data using ...READ MORE

answered Jul 17, 2018 in Blockchain by sapan
57 views
+1 vote
1 answer

How is data retrieved in Ethereum?

Blockchain uses the concept of Merkle trees ...READ MORE

answered Apr 16, 2018 in Blockchain by Shashank
• 10,350 points
73 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
141 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to get notified when an event triggers on ethereum smart contract?

Here's a simple example for web3js 1.0.0.beta*: function handler ...READ MORE

answered Jun 8, 2018 in Blockchain by ariaholic
• 7,340 points
370 views