Multi-threading on Ethereum walelts transactions

I am writing a code on Ethereum transactions between couple of wallets. My goal is to make an animation to show that how the transactions are being done between these wallets. So I gave each wallet an X-Y coordination and I wrote a code which shows how the transaction is directed from a wallet to another one. My code works fine when I do that for one transaction at a time , but the problem is when I want to make some of the wallets to make transactions at the same time(as in real world it can happen ), the program doesn’t work. I pasted my code here. I will be glad if you guys can help me.

Table table;             // Table object
float beginX;
float beginY;
float endX;
float endY;
float distX;`Preformatted text`
float distY;
float exponent = 4;   // Determines the curve
float xDots = 0.0;        // Current x-coordinate
float yDots = 0.0;        // Current y-coordinate
float step = 0.01;    // Size of each step along the path
float pct = 0.01;      // Percentage traveled (0.0 to 1.0)
int p = 0;
int iteration = 0;
int multiplier;

void setup() {
  size(1920, 1580);     // HD size
  background(255);      // White background; black=(0)
  frameRate(30);
  //loadData();
  // =IF(F3=F2,L2,RANDBETWEEN(1,1919)) =IF(F3=F2,L2,RANDBETWEEN(1,1079))
}

void draw() {    // Load CSV file into a Table object. "header" option indicates file has header row; loadData
  table = loadTable("Data_First1000B.csv", "header");

  for (int p = 2; p<table.getRowCount(); p++) { //p<883;  p<table.getRowCount()
    TableRow row = table.getRow(p);
    // You can access the fields via their column name (or index)
    float x  = row.getFloat("from_x");
    float y  = row.getFloat("from_y");
    float w  = row.getFloat("to_x");
    float z  = row.getFloat("to_y");
    int rowz  = row.getInt("row");
    beginX = x;                      // Initial x-coordinate
    beginY = y;                      // Initial y-coordinate
    endX = w;                        // Final x-coordinate
    endY = z;                       // Final y-coordinate
    distX = endX - beginX;          // X-axis distance to move
    distY = endY - beginY;          // Y-axis distance to move

    pct=0;
    while (pct < 1.0) {
      println(rowz);
      println(distX);
      println(distY);
      xDots = beginX + (pct * distX);
      yDots = beginY + (pow(pct, exponent) * distY);
      println(x, y, w, z);
      println(pct);
      println(xDots);
      println(yDots);
      fill(0, 255, 0); //green starting wallet
      ellipse(beginX, beginY, 10, 10);        
      fill(255*pct, 0, 0); // red flow, starts tiny grows bigger
      ellipse(xDots, yDots, pct*10, pct*10);
      fill(0, 0, 255); // blue ending wallet
      ellipse(endX, endY, 10, 10);  
      multiplier = round(pct*100000);

      if (pct <= 0) {
        if (p < 10) {
          save("00000" + p + "_" + multiplier + "00000.png");
        } else if (p < 100) {
          save("0000" + p + "_" + multiplier + "00000.png");
        } else {
          save("000" + p + "_" + multiplier + "00000.png");
        }
      } else if (p < 10) {
        if (multiplier < 10000) {
          save("00000" + p + "_" + "00" + multiplier + ".png");
        } else if (multiplier < 100000) {
          save("00000" + p + "_" + "0" + multiplier + ".png");
        } else {
          save("00000" + p + "_" + multiplier + ".png");
        }
      } else if (p < 100) {
        if (multiplier < 10000) {
          save("0000" + p + "_" + "00" + multiplier + ".png");
        } else if (multiplier < 100000) {
          save("0000" + p + "_" + "0" + multiplier + ".png");
        } else {
          save("0000" + p + "_" + multiplier + ".png");
        }
      } else if (p < 1000) {
        if (multiplier < 10000) {
          save("000" + p + "_" + "00" + multiplier + ".png");
        } else if (multiplier < 100000) {
          save("000" + p + "_" + "0" + multiplier + ".png");
        } else {
          save("000" + p + "_" + multiplier + ".png");
        }
      }
      pct += step;
    }
  }
}

Hey,

First of all, you need to format your code.

  • In the Processing IDE code editor, press Ctrl+T to auto-format
  • In the message editor in the forum, use the </> button
1 Like

You can modify your previous post and make sure that you select all your code and press the </> button.

Done thanks. Do you have any suggestion on the code?

First, you shouldn’t load your .csv table each time in the draw() function because it’s not efficient.
You can assign table in the setup() function so it is only loading once.

Can you give us your .csv file via the upload button? (so we can try your code)

1 Like

It seems that the upload button only works for JPG files and I am not authorized to upload a .csv
can you give me an email address so that I can mail it to you maybe?

Yes you are right, it’s something to improve in the future.
Here you are : joseph.henry@ensci.com

I got your file, thanks.
I don’t understant what is the problem, do you want to make an animation?

You mean : animating them in real time?

Right now, the animation has one stream of dots at any given time. The
“problem” is that multiple transactions happen at the same time (in the
same “block”). And I want to figure out how to
have multiple streams at the same time for all the transactions in the
same block.

If you look at the data, Block 5890000 has 67 transactions, then Block
5890001 has 60 transactions, and so on. That means, I need to figure
out how to have 67 streams of dots unfolding at the same time (like a
flower opening) for the first time period (Block 5890000), then 60
different streams all unfolding at the same time for the second time period and so on.

Is this what you are thinking about ?
(I refactored your code by changing the way you declare variables and adding a brightness to the circles)

Table table;             // Table object
float exponent = 4;   // Determines the curve
float step = 0.01;    // Size of each step along the path 
int multiplier;
int brightness = 120;//The brightness of the circles
int p = 0;

void setup() {
  fullScreen();     // Fullscreen
  background(255);      // White background; black=(0)
  noStroke();  //Remove the black stroke
  table = loadTable("Data_First1000B.csv", "header");
}

void draw() { 
  if (p<table.getRowCount()) {
    TableRow row = table.getRow(p);
    // You can access the fields via their column name (or index)
    float beginX  = row.getFloat("from_x");
    float beginY  = row.getFloat("from_y");
    float endX  = row.getFloat("to_x");
    float endY  = row.getFloat("to_y");
    float distX = endX - beginX;          // X-axis distance to move
    float distY = endY - beginY; 

    float pct=0;
    while (pct < 1.0) {
      float xDots = beginX + (pct * distX);
      float yDots = beginY + (pow(pct, exponent) * distY);       
      fill(255*pct, 0, 0, brightness); // red flow, starts tiny grows bigger
      ellipse(xDots, yDots, pct*10, pct*10); 
      pct += step;
    }

    //Blue circle
    fill(0, 0, 255);
    ellipse(endX, endY, 10, 10); 

    //Green circle
    fill(0, 255, 0);
    ellipse(beginX, beginY, 10, 10);
    p++;
  } else {
    //Stop the animation
    noLoop();
  }
}

You want to have many transaction animations happening at once.

You want many of a thing!
IMMEDIATELY YOU SHOULD WRITE A CLASS FOR THAT THING.

This is the whole idea. thank you your code is faster than me and I like it.
But the problem with your code is it goes line by line through all the transactions.
In the real world, multiple transactions can happen simultaneously.
What I want to do is,all the transactions in Block 5890000 happen at the same time, and then go to Block 5890001 which all the transactions within this block happen simultaneously and so on.
[/quote]

This is not the case?
It’s drawing all the transactions of the block 5890000 for example, then the block 5890001.

yeah. but can we make all the transactions in each block at the same time?

Yeah, but can we do all the transactions of each block at the same time?

I think this is the answer :
I am doing a while loop if the block is the same and I draw them all in once :slight_smile:

Table table;             // Table object
float exponent = 4;   // Determines the curve
float step = 0.01;    // Size of each step along the path 
int multiplier;
int brightness = 120;//The brightness of the circles
int p = 0;
int row_count;

void setup() {
  fullScreen();     // Fullscreen
  background(255);      // White background; black=(0)
  noStroke();  //Remove the black stroke
  table = loadTable("Data_First1000B.csv", "header");
  row_count = table.getRowCount();
}

void draw() { 
  if (p<row_count) {

    
    int init_block = table.getRow(p).getInt("tx_block_number");
    while (p<row_count && table.getRow(p).getInt("tx_block_number") == init_block) {
      // You can access the fields via their column name (or index)
      TableRow row = table.getRow(p);
      float beginX  = row.getFloat("from_x");
      float beginY  = row.getFloat("from_y");
      float endX  = row.getFloat("to_x");
      float endY  = row.getFloat("to_y");
      float distX = endX - beginX;          // X-axis distance to move
      float distY = endY - beginY; 

      float pct=0;
      while (pct < 1.0) {
        float xDots = beginX + (pct * distX);
        float yDots = beginY + (pow(pct, exponent) * distY);       
        fill(255*pct, 0, 0, brightness); // red flow, starts tiny grows bigger
        ellipse(xDots, yDots, pct*10, pct*10); 
        pct += step;
      }

      //Blue circle
      fill(0, 0, 255);
      ellipse(endX, endY, 10, 10); 

      //Green circle
      fill(0, 255, 0);
      ellipse(beginX, beginY, 10, 10);
      p++;
    }
  } else {
    //Stop the animation
    noLoop();
  }
}

Joseph, that is brilliant, I can’t thank you enough. I really appreciate that you are making time to help me with this. You successfully managed to show all the transactions in each block at once. However do you think is there any way that we can show all the transactions in each block are being done gradually at the same time? I mean for example there are about 60 transactions in the block 5890000, and I am wondering if we can see all of them going from (beginX,beginY) to (endX,endY) dot by dot.

1 Like

I think for now, you need to write your own code. :smiley:
You have to do the animation for a group of transactions (from the same block).
If you want to do this dot by dot, you have to draw one dot per draw() loop.

hey thank you very much, but my main problem was that I could not do that in the first place. As my code does show all the transactions at the same time even though with more delay, I was more looking to seek help for the dot by dot part. But thank you anyway, I really appreciate it.