Created
February 8, 2018 09:03
-
-
Save anonymous/8d8fc490e91730b3e785a0c21b27fdbc to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.18+commit.9cf6e910.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.6; | |
contract arraysample { | |
address[] public intermediaryaddresses_; | |
function setaddress(address[] inter) { | |
intermediaryaddresses_= inter; | |
} | |
function getaddress() constant returns(uint){ | |
return (intermediaryaddresses_.length); | |
} | |
} | |
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.0; | |
contract Ballot { | |
struct Voter { | |
uint weight; | |
bool voted; | |
uint8 vote; | |
address delegate; | |
} | |
struct Proposal { | |
uint voteCount; | |
} | |
address chairperson; | |
mapping(address => Voter) voters; | |
Proposal[] proposals; | |
/// Create a new ballot with $(_numProposals) different proposals. | |
function Ballot(uint8 _numProposals) public { | |
chairperson = msg.sender; | |
voters[chairperson].weight = 1; | |
proposals.length = _numProposals; | |
} | |
/// Give $(toVoter) the right to vote on this ballot. | |
/// May only be called by $(chairperson). | |
function giveRightToVote(address toVoter) public { | |
if (msg.sender != chairperson || voters[toVoter].voted) return; | |
voters[toVoter].weight = 1; | |
} | |
/// Delegate your vote to the voter $(to). | |
function delegate(address to) public { | |
Voter storage sender = voters[msg.sender]; // assigns reference | |
if (sender.voted) return; | |
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender) | |
to = voters[to].delegate; | |
if (to == msg.sender) return; | |
sender.voted = true; | |
sender.delegate = to; | |
Voter storage delegateTo = voters[to]; | |
if (delegateTo.voted) | |
proposals[delegateTo.vote].voteCount += sender.weight; | |
else | |
delegateTo.weight += sender.weight; | |
} | |
/// Give a single vote to proposal $(toProposal). | |
function vote(uint8 toProposal) public { | |
Voter storage sender = voters[msg.sender]; | |
if (sender.voted || toProposal >= proposals.length) return; | |
sender.voted = true; | |
sender.vote = toProposal; | |
proposals[toProposal].voteCount += sender.weight; | |
} | |
function winningProposal() public constant returns (uint8 _winningProposal) { | |
uint256 winningVoteCount = 0; | |
for (uint8 prop = 0; prop < proposals.length; prop++) | |
if (proposals[prop].voteCount > winningVoteCount) { | |
winningVoteCount = proposals[prop].voteCount; | |
_winningProposal = prop; | |
} | |
} | |
} |
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 Bid { | |
// Declaring all variables | |
string businessname ; | |
string businessaddress ; | |
string industrytype; | |
string industrysubtype; | |
string description; | |
bytes32 public insurancedsign; | |
bytes32 public docslist; | |
string otherremarks; | |
address[] intermediaryaddresses; | |
address admin; | |
address public winner; | |
uint public winningbidamount; | |
// Creating a Struct for the bids | |
struct Bidstruct { | |
address bidder; | |
uint bidamount; | |
} | |
Bidstruct[] public bids; | |
// A constructor to pass all the bid details when an admin creates a bid | |
function Bid(string businessname_, | |
string businessaddress_, | |
string industrytype_, | |
string industrysubtype_, | |
string description_, | |
bytes32 insurancedesign_, | |
bytes32 docslist_, | |
address[] intermediaryaddresses_, | |
string otherremarks_) { | |
businessname = businessname_; | |
businessaddress = businessaddress_; | |
industrytype = industrytype_; | |
industrysubtype = industrysubtype_; | |
description = description_; | |
insurancedsign=insurancedesign_; | |
docslist =docslist_; | |
intermediaryaddresses=intermediaryaddresses_; | |
otherremarks=otherremarks_; | |
admin=msg.sender; | |
} | |
// A fuunction to get the admin who creates the bid | |
function getAdminAddress() constant returns (address) { | |
return msg.sender; | |
} | |
// A function to validate the intermediaries | |
function validIntermediary(address intermediary) constant returns (bool) { | |
for (uint i = 0; i < intermediaryaddresses.length; i++) { | |
if (intermediaryaddresses[i] == intermediary) { | |
return true; | |
} | |
} | |
return false; | |
} | |
// A function to Create a new bid | |
function submitBid(uint amount) constant returns (string){ | |
if(!validIntermediary(msg.sender)) return ("you are not allowed"); | |
Bidstruct memory biddata; | |
biddata.bidder=msg.sender; | |
biddata.bidamount=amount; | |
bids.push(biddata); | |
return ("success"); | |
} | |
// A function to reveal the bid winner | |
function revealBid() constant returns (string,uint,address,uint){ | |
if(admin!=msg.sender) return ("Not a valid Transaction",0,0,bids.length); | |
if(bids.length==0) return("no bids",0,0,bids.length); | |
Bidstruct tempbid=bids[0]; | |
uint temp_amount =tempbid.bidamount; | |
uint temp_index=0; | |
for (uint i=1; i< bids.length; i++) { | |
if(bids[i].bidamount < temp_amount) { | |
temp_amount = bids[i].bidamount; | |
temp_index=i; | |
} | |
} | |
winner=bids[temp_index].bidder; | |
winningbidamount=bids[temp_index].bidamount; | |
return("bid confirmed",winningbidamount,winner,bids.length); | |
} | |
// A function to get all the bid details | |
function getBids(uint i) constant returns(address,uint){ | |
return (bids[i].bidder,bids[i].bidamount); | |
} | |
// A function to get all the contract details | |
function getDetails () constant returns (string,string,string,string,string,bytes32,bytes32,address[]) { | |
return( businessname,businessaddress,industrytype,industrysubtype,description, | |
insurancedsign,docslist,intermediaryaddresses); | |
} | |
} |
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
contract Course { | |
struct Instructor { | |
uint age; | |
string fName; | |
string lName; | |
} | |
mapping (address => Instructor) instructors; | |
address[] public instructorAccts; | |
function setInstructor(address _address, uint _age, string _fName, string _lName) public { | |
var instructor = instructors[_address]; | |
instructor.age = _age; | |
instructor.fName = _fName; | |
instructor.lName = _lName; | |
instructorAccts.push(_address) -1; | |
} | |
function getInstructors() view public returns (address[]) { | |
return instructorAccts; | |
} | |
function getInstructor(address ins) view public returns (uint, string, string) { | |
return (instructors[ins].age, instructors[ins].fName, instructors[ins].lName); | |
} | |
function countInstructors() view public returns (uint) { | |
return instructorAccts.length; | |
} | |
} |
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 MigrantAid { | |
// Declare all input variables | |
struct Migrant { | |
string migrantname ; | |
string dob; | |
uint256 mobileno; | |
string permenantaddress; | |
string temporaryaddress; | |
uint256 emergencycontact; | |
bool maritialstatus; | |
string[] partnerdetails; | |
string[] kidsdetails; | |
string[] employmentdetails; | |
string[] educationaldetails; | |
bool aadharstatus; | |
uint256 aadharno; | |
uint256 bankaccountno; | |
string brokername; | |
} | |
mapping(address => Migrant[]) Migrants; | |
address migrantid; | |
uint migrantcount = 0; | |
function registerMigrant (string migrantname_, | |
string dob_, | |
uint mobileno_, | |
string permenantaddress_, | |
string temporaryaddress_, | |
uint emergencycontact_, | |
bool maritialstatus_, | |
string[] partnerdetails_, | |
string[] kidsdetails_, | |
string[] employmentdetails_, | |
string[] educationaldetails_, | |
bool aadharstatus_, | |
uint256 aadharno_, | |
uint256 bankaccountno_, | |
string brokername_) constant returns (string){ | |
Migrants[migrantid].push(Migrant({ | |
migrantname: migrantname_, | |
dob: dob_, | |
mobileno: mobileno_, | |
permenantaddress: permenantaddress_, | |
temporaryaddress: temporaryaddress_, | |
emergencycontact: emergencycontact_, | |
maritialstatus: maritialstatus_, | |
partnerdetails: partnerdetails_, | |
kidsdetails: kidsdetails_, | |
employmentdetails: employmentdetails_, | |
educationaldetails: educationaldetails_, | |
aadharstatus: aadharstatus_, | |
aadharno: aadharno_, | |
bankaccountno: bankaccountno_, | |
brokername: brokername_})); | |
// Migrants[migrantid] = Migrant(migrantname_,dob_,mobileno_,permenantaddress_,temporaryaddress_,emergencycontact_,maritialstatus_,partnerdetails_,kidsdetails_,employmentdetails_,educationaldetails_,aadharstatus_,aadharno_,bankaccountno_,brokername_); | |
migrantcount = migrantcount++; | |
return "Registration success"; | |
} | |
function getmigrantdetails (address migrantid) constant returns(string){ | |
return Migrants[migrantid].migrantname; | |
} | |
function generatemigrateid() constant returns (uint){ | |
uint random_number = uint(block.blockhash(block.number-1))%100 + 1; | |
return (random_number); | |
} | |
} |
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); | |
} | |
} | |
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 MyGoal { | |
// Declaring all the variables for My MyGoal | |
address manager; | |
address[] employeeaddress; | |
struct TaskStruct { | |
string taskname; | |
string taskcategory; | |
uint taskcomplexity; | |
uint credits; | |
uint deadline; | |
} | |
TaskStruct[] public tasks; | |
// A fuunction to get the Manager address who only has the permission to create task | |
function getAdminAddress() constant returns (address) { | |
return msg.sender; | |
} | |
// A function to validate the intermediaries | |
function validEmployee(address employee) constant returns (bool) { | |
for (uint i = 0; i < employeeaddress.length; i++) { | |
if (employeeaddress[i] == employee) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function MyGoal (address[] employee_) { | |
employeeaddress = employee_; | |
manager = msg.sender; | |
} | |
function createTask (string taskname, string taskcategory,uint taskcomplexity,uint credits,uint deadline) constant returns(bool,string) { | |
if(manager!=msg.sender) return (false,"Only Project Manager is allowed to create a task "); | |
tasks.push(TaskStruct({taskname:taskname, taskcategory:taskcategory,taskcomplexity:taskcomplexity,credits:credits,deadline:deadline})); | |
return (true,"task created successfully"); | |
} | |
// A function to get all the bid details | |
function tasklength() public constant returns(uint){ | |
return (tasks.length); | |
} | |
function displaytasks () constant returns (string,string,uint,uint,uint) { | |
for(uint i=0;i<tasks.length;i++) { | |
return(tasks[i].taskname,tasks[i].taskcategory,tasks[i].taskcomplexity,tasks[i].credits,tasks[i].deadline); | |
} | |
} | |
} |
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.6; | |
contract Reference { | |
struct NumberStruct { | |
uint number; | |
bool isCurrent; | |
} | |
NumberStruct[] nums; | |
function Reference() { | |
NumberStruct memory numberStruct; | |
nums.push(numberStruct); | |
} | |
function setTwo(uint no,bool val) { | |
var aNumberStruct = nums[0]; | |
// these references are writing to nums[] | |
aNumberStruct.number = no; | |
aNumberStruct.isCurrent = val; | |
} | |
function getlength() constant returns(uint){ | |
return(nums.length); | |
} | |
} |
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.11; | |
contract samplestruct { | |
struct Bidstruct { | |
string bidder; | |
uint bidamount; | |
} | |
Bidstruct[] public bids; | |
function submitBid(string name,uint amount) { | |
bids.push(Bidstruct({bidder:name, bidamount:amount})); | |
} | |
function getDetails () constant returns (string,uint){ | |
return ("success",bids.length); | |
} | |
} | |
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 test { | |
address public migrantaddress; | |
struct amigrant { | |
string migrantname; | |
bytes32 mobilenumber; | |
} | |
/*uint migrantcount; | |
mapping(address => amigrant[]) public migrants; | |
function setmigrantdetail (string migrantname_,bytes32 mobilenumber_) public returns(bool success){ | |
migrantaddress = msg.sender; | |
migrants[migrantaddress].push(amigrant({ | |
migrantname: migrantname_, | |
mobilenumber: mobilenumber_ | |
})); | |
return true; | |
} | |
*/ | |
mapping(address =>amigrant) public migrants; | |
address[] public migrantsaccounts; | |
function setmigrantdetail(string name,bytes32 number) constant public returns(bool success){ | |
migrantaddress = msg.sender; | |
migrants[migrantaddress].migrantname = name; | |
migrants[migrantaddress].mobilenumber = number; | |
return true; | |
} | |
function getmigrantdetail(address migrantaddress) constant public returns(string name,bytes32 no){ | |
return (migrants[migrantaddress].migrantname,migrants[migrantaddress].mobilenumber); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment