Hacker News new | past | comments | ask | show | jobs | submit login

it's stored on the blockchain, inside the transaction that calls the payable function.

The setup is done in two steps:

1. you must pay for a rectangle area via the `buy` function (notice the `payable` specifier):

    function buy(uint _x, uint _y, uint _width, uint _height) payable returns (uint idx) {
2. then you can setup your ad via the publish function:

    function publish(uint _idx, string _link, string _image, string _title, bool _NSFW) {

~~~

For more details in 1:

* the cost of the area you're trying to buy is calculated as _width * _height * pixelsPerCell * weiPixelPrice

* with weiPixelPrice = 1000000000000000 and pixelsPerCell = 100

* The grid is defined as a double array of 100x100:

    bool[100][100] public grid;
* The for loop checks that none of these pixels are set to true, if any pixel is then `revert` reverts any changes to the state that happened during execution. Otherwise the relevant coordinates are all set to true.

* The space is reserved under the address that send the ether (`msg.sender`). To do that, an `Ad` struct is filled with the information and it is pushed unto the state.

   Ad memory ad = Ad(msg.sender, _x, _y, _width, _height, "", "", "", false, false);
   idx = ads.push(ad) - 1;
* It returns an index (`Idx`) that you can use to specify the details of your ad later.

~~~

For more details in 2:

* You must pass the `index` of your reserved space as argument to the function

* It will check that your address is indeed the address which reserved the space:

   require(msg.sender == ad.owner);
* It sets everything to the arguments of the function you're calling.

* An event is triggered, it is probably being listened to by the web app so that the web page can be updated live

   Publish(_idx, ad.link, ad.image, ad.title, ad.NSFW || ad.forceNSFW);

~~~

Notes:

* Looks like you can call the `publish` function over and over. Modifying your ad over and over.

* There is a `forceNSFW` function that the contract owner can use to force an ad to have the `NSFW` flag. But this can be re-modified again and again by the ad owner.

* But the owner of the contract can remove ownership of an Ad, so there's that.

* I just audited the contract and I couldn't find any vulnerability.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: