Created
May 10, 2018 14:57
-
-
Save sardap/d536e45f412ba827bed68b41e3696493 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=true&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
pragma solidity ^0.4.11; | |
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 ProtoypeEmpData(string data, bytes hash, address student) public { | |
_data = data; | |
_hash = hash; | |
_creator = msg.sender; | |
_student = student; | |
} | |
function char(byte b) constant private returns (byte c) { | |
if (b < 10) return byte(uint8(b) + 0x30); | |
else return byte(uint8(b) + 0x57); | |
} | |
function toString(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 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 getShareRecords() constant public returns (string) | |
{ | |
string result ; | |
for(uint256 i = 0; i < _sharedAdresses.length; i++) | |
{ | |
if(_sharedAdresses[i].state == 0) | |
{ | |
//result += toString(_sharedAdresses[i].sharedAddress); | |
} | |
} | |
} | |
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