Would have been much easier with an ethereum smart contract. No gimmicky address list, it's a crowdsourced picture in the blockchain. contract Place { struct Pixel { bytes3 color; uint lastPayment; } Pixel[10000][10000] board; modifier onBoard(uint x, uint y) { if (x > 10000 || y > 10000) { throw; } _; } // Accepts funds, if the funds sent are greater than funds for that pixel last, change the color. function colorPi…
This code suffers from Recursive calling vulnerability (same bug which caused the DAO to be hacked).
You're sending the money BEFORE you're updating the balances.
There is a better way to write the payment code (and also wouldn't take you more than 5 minutes to write).
Here is one way to do it:
function colorPixel(uint x, uint y, bytes3 color) payable onBoard(x, y) {
Pixel p = board[x][y];
lastPayment = p.lastPayment;
p.lastPayment = msg.value;
if (msg.value > lastPayment) {
if(!msg.sender.send(lastPayment)) throw; // refund previous price of pixel
p.color = color; // set the color
} else {
throw;
}
}
Another shorter way: function colorPixel(uint x, uint y, bytes3 color) payable onBoard(x, y) {
Pixel p = board[x][y];
require(msg.value > p.lastPayment);
if(!msg.sender.send(p.lastPayment)) throw; // refund previous price of pixel
p.color = color; // set the color
p.lastPayment = msg.value; // set new cost to whatever the person sent in
}