Created
February 8, 2018 09:06
-
-
Save ayinot/1d16e9727b3bdfce4492257294a4f3be to your computer and use it in GitHub Desktop.
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.2; | |
contract MyFile { | |
uint public govtrail = 100000; | |
uint public agenttrail = 100000; | |
uint public migtrail = 100000; | |
mapping(address => Government) govdetails; | |
address[] public governmentaccounts; | |
mapping(address => Agent) agentdetails; | |
address[] public agentaccounts; | |
struct Government { | |
string state; | |
bytes32 mobilenumber; | |
} | |
struct Agent { | |
string state; | |
bytes32 mobilenumber; | |
string agentname; | |
} | |
function registergov(string state_, bytes32 mobilenumber_) public returns (string) { | |
var govcreator = msg.sender; | |
var agovernement= govdetails[govcreator]; | |
agovernement.state= state_; | |
agovernement.mobilenumber= mobilenumber_; | |
governmentaccounts.push(govcreator); | |
return ("success"); | |
} | |
function registeragent(string state_, string agentname_, bytes32 mobilenumber_) public returns (string) { | |
var agentcreator = msg.sender; | |
var agent= agentdetails[agentcreator]; | |
agent.state= state_; | |
agent.agentname= agentname_; | |
agent.mobilenumber= mobilenumber_; | |
agentaccounts.push(agentcreator); | |
return ("success"); | |
} | |
// Government get details starts | |
function getDetails(address ins) view public returns (string, bytes32) { | |
return (govdetails[ins].state, govdetails[ins].mobilenumber); | |
} | |
function getlength() public constant returns(uint){ | |
return governmentaccounts.length; | |
} | |
// Government get details ends | |
// Agent get details starts | |
function getagentDetails(address ins) view public returns (string, string, bytes32) { | |
return (agentdetails[ins].state, agentdetails[ins].agentname,agentdetails[ins].mobilenumber); | |
} | |
function getagentlength() public constant returns(uint){ | |
return agentaccounts.length; | |
} | |
// Agent get details ends | |
function generateid (string prefix) public constant returns(bytes32 id) { | |
if (keccak256(prefix) == keccak256("gov")){ | |
govtrail = govtrail++; | |
var govtrailid = uintToBytes(govtrail); | |
return (govtrailid); | |
} | |
} | |
function searchbystate (string ) { | |
} | |
function uintToBytes(uint v) constant returns (bytes32 ret) { | |
if (v == 0) { | |
ret = '0'; | |
} | |
else { | |
while (v > 0) { | |
ret = bytes32(uint(ret) / (2 ** 8)); | |
ret |= bytes32(((v % 10) + 48) * 2 ** (8 * 31)); | |
v /= 10; | |
} | |
} | |
return ret; | |
} | |
function bytes32ArrayToString (bytes32[] data)constant returns (string) { | |
bytes memory bytesString = new bytes(data.length * 32); | |
uint urlLength; | |
for (uint i=0; i<data.length; i++) { | |
for (uint j=0; j<32; j++) { | |
byte char = byte(bytes32(uint(data[i]) * 2 ** (8 * j))); | |
if (char != 0) { | |
bytesString[urlLength] = char; | |
urlLength += 1; | |
} | |
} | |
} | |
bytes memory bytesStringTrimmed = new bytes(urlLength); | |
for (i=0; i<urlLength; i++) { | |
bytesStringTrimmed[i] = bytesString[i]; | |
} | |
return string(bytesStringTrimmed); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment