Last active
May 13, 2018 12:05
-
-
Save sardap/ac14338b5c40ff095cea009652725fca 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.23+commit.124ca40d.js&optimize=false&gist=
This file contains 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
//"asdb", ["10", "10"], "0x14723a09acff6d2a60dcdf7aa4aff308fddc160c" | |
//"0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db" | |
contract ExampleContract { | |
struct ShareEntry | |
{ | |
address sharedAddress; | |
// 0 = No respone, 1 = Appoved, 2 = Rejected | |
int state; | |
} | |
string private _data; | |
bytes private _hash; | |
address private _creator; | |
address private _student; | |
ShareEntry[] private _sharedAdresses; | |
function ExampleContract(string data, bytes hash, address student) public { | |
_data = data; | |
_hash = hash; | |
_creator = msg.sender; | |
_student = student; | |
} | |
function ShareWithAddress(address shared) public returns (bool) | |
{ | |
if(msg.sender == _student) | |
{ | |
_sharedAdresses.push(ShareEntry(shared, 0)); | |
return true; | |
} | |
return false; | |
} | |
function RespondRequest(address appvoed, bool response) public returns (bool) | |
{ | |
for(uint256 i = 0; i < _sharedAdresses.length; i++) | |
{ | |
if(_sharedAdresses[i].sharedAddress == appvoed) | |
{ | |
if(response) | |
_sharedAdresses[i].state = 1; | |
else | |
_sharedAdresses[i].state = 2; | |
} | |
} | |
} | |
function char(byte b) constant private returns (byte c) { | |
if (b < 10) return byte(uint8(b) + 0x30); | |
else return byte(uint8(b) + 0x57); | |
} | |
function addressToString(address toConvert) constant public returns (string){ | |
bytes memory s = new bytes(40); | |
for (uint i = 0; i < 20; i++) { | |
byte b = byte(uint8(uint(toConvert) / (2**(8*(19 - i))))); | |
byte hi = byte(uint8(b) / 16); | |
byte lo = byte(uint8(b) - 16 * uint8(hi)); | |
s[2*i] = char(hi); | |
s[2*i+1] = char(lo); | |
} | |
return string(s); | |
} | |
function strConcat(string _a, string _b, string _c, string _d, string _e) constant internal returns (string){ | |
bytes memory _ba = bytes(_a); | |
bytes memory _bb = bytes(_b); | |
bytes memory _bc = bytes(_c); | |
bytes memory _bd = bytes(_d); | |
bytes memory _be = bytes(_e); | |
string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length); | |
bytes memory babcde = bytes(abcde); | |
uint k = 0; | |
for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i]; | |
for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i]; | |
for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i]; | |
for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i]; | |
for (i = 0; i < _be.length; i++) babcde[k++] = _be[i]; | |
return string(babcde); | |
} | |
function strConcat(string _a, string _b, string _c, string _d) constant internal returns (string) { | |
return strConcat(_a, _b, _c, _d, ""); | |
} | |
function strConcat(string _a, string _b, string _c) constant internal returns (string) { | |
return strConcat(_a, _b, _c, "", ""); | |
} | |
function strConcat(string _a, string _b) constant internal returns (string) { | |
return strConcat(_a, _b, "", "", ""); | |
} | |
function getShareRecords() constant public returns (string) | |
{ | |
string memory result; | |
for(uint256 i = 0; i < _sharedAdresses.length; i++) | |
{ | |
if(_sharedAdresses[i].state == 0) | |
{ | |
result = strConcat(result, addressToString(_sharedAdresses[i].sharedAddress)); | |
} | |
} | |
return result; | |
} | |
function getHash() constant public returns (bytes){ | |
return _hash; | |
} | |
function getData() constant public returns (string){ | |
return _data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment