Created
May 30, 2018 14:41
-
-
Save pheix/1019bb73bae33c8c4fd4794279cb4996 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.21; | |
contract BigBro { | |
struct Statistics { | |
uint id; | |
string referer; | |
string ip; | |
string useragent; | |
string resolution; | |
string page; | |
string country; | |
} | |
Statistics[] BigBroDB; | |
function set_by_id(uint _id, string _ref, string _ip, string _ua, string _res, string _pg, string _cntry) public returns (uint) { | |
if (_id > 0) { | |
for (uint i=0; i<BigBroDB.length; i++) { | |
if (BigBroDB[i].id == _id) { | |
bytes memory _ref_t = bytes(_ref); | |
bytes memory _ip_t = bytes(_ip); | |
bytes memory _ua_t = bytes(_ua); | |
bytes memory _res_t = bytes(_res); | |
bytes memory _pg_t = bytes(_pg); | |
bytes memory _cntry_t = bytes(_cntry); | |
if ( _ref_t.length > 0 ) { BigBroDB[i].referer = _ref; } | |
if ( _ip_t.length > 0) { BigBroDB[i].ip = _ip; } | |
if ( _ua_t.length > 0 ) { BigBroDB[i].useragent = _ua; } | |
if ( _res_t.length > 0 ) { BigBroDB[i].resolution = _res; } | |
if ( _pg_t.length > 0 ) { BigBroDB[i].page = _pg; } | |
if ( _cntry_t.length > 0 ) { BigBroDB[i].country = _cntry; } | |
return 1; | |
} | |
} | |
} | |
return 0; | |
} | |
function insert(uint _id, string _ref, string _ip, string _ua, string _res, string _pg, string _cntry) public { | |
BigBroDB.push(Statistics( _id, _ref, _ip, _ua, _res, _pg, _cntry ) ); | |
} | |
function get_count() public constant returns (uint256) { | |
return BigBroDB.length; | |
} | |
function get_by_id(uint _id) public constant returns (uint, string, string, string, string, string, string) { | |
if (_id > 0) { | |
for (uint i=0; i<BigBroDB.length; i++) { | |
if (BigBroDB[i].id == _id) { | |
return ( | |
BigBroDB[i].id, | |
BigBroDB[i].referer, | |
BigBroDB[i].ip, | |
BigBroDB[i].useragent, | |
BigBroDB[i].resolution, | |
BigBroDB[i].page, | |
BigBroDB[i].country | |
); | |
} | |
} | |
} | |
} | |
function get_by_index(uint index) public constant returns (uint, string, string, string, string, string, string) { | |
if (index >= 0 && index < BigBroDB.length) { | |
if (BigBroDB[index].id > 0) { | |
return ( | |
BigBroDB[index].id, | |
BigBroDB[index].referer, | |
BigBroDB[index].ip, | |
BigBroDB[index].useragent, | |
BigBroDB[index].resolution, | |
BigBroDB[index].page, | |
BigBroDB[index].country | |
); | |
} | |
} | |
return (0, "", "", "", "", "", ""); | |
} | |
function remove_by_id(uint _id) public returns (uint) { | |
uint rc = 0; | |
if (_id > 0) { | |
for (uint i=0; i<BigBroDB.length; i++) { | |
if (BigBroDB[i].id == _id) { | |
BigBroDB[i] = BigBroDB[BigBroDB.length-1]; | |
BigBroDB.length--; | |
rc = i; | |
break; | |
} | |
} | |
} | |
return rc; | |
} | |
function init_db() public { | |
insert(1, "goo.gl", "127.0.0.1", "Mozilla", "640*480", "index.html", "RU"); | |
insert(2, "twitter.com", "127.0.0.11", "IE", "1900*1280", "index2.html", "US"); | |
insert(3, "ya.ru", "127.0.0.12", "Opera", "1024*768", "index3.html", "BY"); | |
insert(4, "pheix.org", "127.0.0.111", "Safari", "100*200", "index4.html", "UA"); | |
insert(5, "foo.bar", "127.0.0.254", "Netscape", "1152*778", "index5.html", "RO"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment