Created
November 23, 2017 12:55
-
-
Save anonymous/d730b55d9f46029072561323a210edf3 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=undefined&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.2; | |
contract AddressArray { | |
address admin; | |
string businessName ; | |
string businessAddress ; | |
string industryType; | |
string industrySubType; | |
address[] intermediaryaddresses; | |
Bid[] public bids; | |
address public winner; | |
uint public winningbidamout; | |
bytes32[] fire; | |
struct Bid { | |
address bidder; | |
uint bidamount; | |
} | |
function AddressArray(string businessNam,string businessAddres,string industryTyp,address[] addresses_) { | |
businessName = businessNam; | |
businessAddress = businessAddres; | |
industryType = industryTyp; | |
intermediaryaddresses=addresses_; | |
admin=msg.sender; | |
} | |
function getNumberOfAddresses() constant returns (uint) { | |
return intermediaryaddresses.length; | |
} | |
function submitBid(uint amount) returns (string){ | |
if(!validIntermediary(msg.sender)) | |
return ("you are not allowed"); | |
bids.push(Bid({bidder:msg.sender, bidamount:amount})); | |
return ("success"); | |
} | |
function revealBid() returns (string,uint,address){ | |
if(admin!=msg.sender) return ("0",0,0); | |
if(bids.length==0) return("no bids",0,0); | |
Bid 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; | |
winningbidamout=bids[temp_index].bidamount; | |
return("bid confirmed",winningbidamout,winner); | |
} | |
function getAddress(uint i) constant returns (address) { | |
return intermediaryaddresses[i]; | |
} | |
function validIntermediary(address intermediary) constant returns (bool) { | |
for (uint i = 0; i < intermediaryaddresses.length; i++) { | |
if (intermediaryaddresses[i] == intermediary) { | |
return true; | |
} | |
} | |
return false; | |
} | |
} |
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; | |
Bidstruct[] public bids; | |
// Creating a Struct for the bids | |
struct Bidstruct { | |
address bidder; | |
uint bidamount; | |
} | |
// 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) returns (string){ | |
if(!validIntermediary(msg.sender)) return ("you are not allowed"); | |
bids.push(Bidstruct({bidder:msg.sender, bidamount:amount})); | |
return ("success"); | |
} | |
// A function to reveal the bid winner | |
function revealBid() returns (string,uint,address){ | |
if(admin!=msg.sender) return ("Not a valid Transaction",0,0); | |
if(bids.length==0) return("no bids",0,0); | |
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); | |
} | |
// A function to get all the bid details | |
function getDetails () constant return () | |
} |
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 someContract { | |
uint someVar; | |
function getVar() constant returns(string, uint) { | |
if(someVar > 2) { | |
return ("Greater than two", someVar); | |
} else if(someVar == 2) { | |
return ("Exactly two", someVar); | |
} else { | |
return ("Smaller than two", someVar); | |
} | |
} | |
function setVar(uint num) { | |
someVar = num; | |
} | |
function getWhile() constant returns(uint){ | |
uint i=1; | |
while (i < 5) { | |
someVar= i++; | |
} | |
return someVar; | |
} | |
} |
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 consample { | |
string businessName ; | |
string businessAddress ; | |
string industryType; | |
string industrySubType; | |
string description; | |
uint256 firePerilsSum; | |
uint256 businessInteruptionSum; | |
uint256 workmansCompSum; | |
uint256 moneyInsuranceSum; | |
uint256 fidelityInsuranceSum; | |
uint256 publicLiabilitySum; | |
uint256 machineryBreakdownSum; | |
uint256 electronicEquipSum; | |
uint256 boilerExplosionSum; | |
string comments; | |
string intermediary; | |
function consample (string businessNam, | |
string businessAddres, | |
string industryTyp, | |
string industrySubTyp, | |
string desc, | |
uint256 firePerilSum, | |
uint256 businessInteruptionSum, | |
uint256 workmansCompSum, | |
uint256 moneyInsuranceSum, | |
uint256 fidelityInsuranceSum, | |
uint256 publicLiabilitySum, | |
uint256 machineryBreakdownSum, | |
uint256 electronicEquipSum, | |
uint256 boilerExplosionSum, | |
string comments, | |
string intermediary) { | |
businessName = businessNam ; | |
businessAddress ; | |
string industryType; | |
string industrySubType; | |
string description; | |
uint256 firePerilsSum; | |
uint256 businessInteruptionSum; | |
uint256 workmansCompSum; | |
uint256 moneyInsuranceSum; | |
uint256 fidelityInsuranceSum; | |
uint256 publicLiabilitySum; | |
uint256 machineryBreakdownSum; | |
uint256 electronicEquipSum; | |
uint256 boilerExplosionSum; | |
string comments; | |
string intermediary; | |
} | |
} |
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 MyContract { | |
address creator; | |
uint256 myNumber; | |
function MyContract() { | |
creator = msg.sender; | |
myNumber = 5; | |
} | |
function getCreator() constant returns (address) { | |
return creator; | |
} | |
function getNumber() constant returns (uint256) { | |
return myNumber; | |
} | |
function setNumber(uint256 num){ | |
myNumber = num; | |
} | |
function kill() { | |
if(msg.sender == creator) { | |
suicide(creator); | |
} | |
} | |
} |
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 someContract { | |
uint public someVar; | |
function getVar() constant returns(string, uint) { | |
if(someVar > 2) { | |
return ("Greater than two", someVar); | |
} else if(someVar == 2) { | |
return ("Exactly two", someVar); | |
} else { | |
return ("Smaller than two", someVar); | |
} | |
} | |
function someContract(uint num) { | |
someVar = num; | |
} | |
function getWhile() constant returns(uint){ | |
uint i=1; | |
while (i < 5) { | |
someVar= i++; | |
} | |
return someVar; | |
} | |
} |
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 hextest { | |
bytes32 public insurancedesign; | |
function hextest (bytes32 insurance) { | |
insurancedesign = insurance; | |
} | |
} |
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 owned { | |
function owned() { owner = msg.sender; } | |
address owner; | |
} | |
// Use "is" to derive from another contract. Derived | |
// contracts can access all non-private members including | |
// internal functions and state variables. These cannot be | |
// accessed externally via `this`, though. | |
contract mortal is owned { | |
function kill() { | |
if (msg.sender == owner) selfdestruct(owner); | |
} | |
} | |
// These abstract contracts are only provided to make the | |
// interface known to the compiler. Note the function | |
// without body. If a contract does not implement all | |
// functions it can only be used as an interface. | |
contract Config { | |
function lookup(uint id) returns (address adr); | |
} | |
contract NameReg { | |
function register(bytes32 name); | |
function unregister(); | |
} | |
// Multiple inheritance is possible. Note that "owned" is | |
// also a base class of "mortal", yet there is only a single | |
// instance of "owned" (as for virtual inheritance in C++). | |
contract named is owned, mortal { | |
function named(bytes32 name) { | |
Config config = Config(0xd5f9d8d94886e70b06e474c3fb14fd43e2f23970); | |
NameReg(config.lookup(1)).register(name); | |
} | |
// Functions can be overridden by another function with the same name and | |
// the same number/types of inputs. If the overriding function has different | |
// types of output parameters, that causes an error. | |
// Both local and message-based function calls take these overrides | |
// into account. | |
function kill() { | |
if (msg.sender == owner) { | |
Config config = Config(0xd5f9d8d94886e70b06e474c3fb14fd43e2f23970); | |
NameReg(config.lookup(1)).unregister(); | |
// It is still possible to call a specific | |
// overridden function. | |
mortal.kill(); | |
} | |
} | |
} | |
// If a constructor takes an argument, it needs to be | |
// provided in the header (or modifier-invocation-style at | |
// the constructor of the derived contract (see below)). | |
contract PriceFeed is owned, mortal, named("GoldFeed") { | |
function updateInfo(uint newInfo) { | |
if (msg.sender == owner) info = newInfo; | |
} | |
function get() constant returns(uint r) { return info; } | |
uint info; | |
} |
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 owned { | |
function owned() { owner = msg.sender; } | |
address owner; | |
} | |
contract mortal is owned { | |
function kill() { | |
if (msg.sender == owner) selfdestruct(owner); | |
} | |
} | |
contract Base1 is mortal { | |
function kill() { /* do cleanup 1 */ super.kill(); } | |
} | |
contract Base2 is mortal { | |
function kill() { /* do cleanup 2 */ | |
super.kill(); } | |
} | |
contract Final is Base2, Base1 { | |
} |
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 simpleDapp { | |
uint someVar; | |
function setSomeVar(uint myVar) { | |
someVar = myVar; | |
} | |
function getSomeVar() constant returns(uint){ | |
return someVar; | |
} | |
function setSomeVarFour(uint myVar) { | |
setSomeVar(4 * myVar); | |
} | |
} | |
contract someOtherSimpleDapp |
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 Sha { | |
bytes32 public insurancedesign; | |
function hextest (bytes32 insurance) { | |
insurancedesign = insurance; | |
} | |
} |
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 CrowdFunding { | |
// Defines a new type with two fields. | |
struct Funder { | |
address addr; | |
uint amount; | |
} | |
struct Campaign { | |
address beneficiary; | |
uint fundingGoal; | |
uint numFunders; | |
uint amount; | |
mapping (uint => Funder) funders; | |
} | |
uint numCampaigns; | |
mapping (uint => Campaign) campaigns; | |
function newCampaign(address beneficiary, uint goal) returns (uint campaignID) { | |
campaignID = numCampaigns++; // campaignID is return variable | |
// Creates new struct and saves in storage. We leave out the mapping type. | |
campaigns[campaignID] = Campaign(beneficiary, goal, 0, 0); | |
} | |
function contribute(uint campaignID) payable { | |
Campaign storage c = campaigns[campaignID]; | |
// Creates a new temporary memory struct, initialised with the given values | |
// and copies it over to storage. | |
// Note that you can also use Funder(msg.sender, msg.value) to initialise. | |
c.funders[c.numFunders++] = Funder({addr: msg.sender, amount: msg.value}); | |
c.amount += msg.value; | |
} | |
function checkGoalReached(uint campaignID) returns (bool reached) { | |
Campaign storage c = campaigns[campaignID]; | |
if (c.amount < c.fundingGoal) | |
return false; | |
uint amount = c.amount; | |
c.amount = 0; | |
c.beneficiary.transfer(amount); | |
return true; | |
} | |
} |
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 MyContract { | |
address creator; | |
uint256 myNumber; | |
function MyContract() { | |
creator = msg.sender; | |
myNumber = 5; | |
} | |
function getCreator() constant returns (address) { | |
return creator; | |
} | |
function getNumber() constant returns (uint256) { | |
return myNumber; | |
} | |
function setNumber(uint256 num){ | |
myNumber = num; | |
} | |
function kill() { | |
if(msg.sender == creator) { | |
suicide(creator); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment