Skip to content

Instantly share code, notes, and snippets.

@moinuddin14
Created July 13, 2018 12:22
Show Gist options
  • Save moinuddin14/5e4d880a71a58d2a1902e3ce34e5aa0b to your computer and use it in GitHub Desktop.
Save moinuddin14/5e4d880a71a58d2a1902e3ce34e5aa0b 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.24+commit.e67f0147.js&optimize=false&gist=
pragma solidity ^0.4.20;
interface AbstractMultiSig {
/*
* This function should return the onwer of this contract or whoever you
* want to receive the Gyaan Tokens reward if it's coded correctly.
*/
function owner() external returns(address);
/*
* This event should be dispatched whenever the contract receives
* any contribution.
*/
event ReceivedContribution(address indexed _contributor, uint _valueInWei);
/*
* When this contract is initially created, it's in the state
* "Accepting contributions". No proposals can be sent, no withdraw
* and no vote can be made while in this state. After this function
* is called, the contract state changes to "Active" in which it will
* not accept contributions anymore and will accept all other functions
* (submit proposal, vote, withdraw)
*/
function endContributionPeriod() external;
/*
* Sends a withdraw proposal to the contract. The beneficiary would
* be "_beneficiary" and if approved, this address will be able to
* withdraw "value" Ethers.
*
* This contract should be able to handle many proposals at once.
*/
function submitProposal(uint _valueInWei) external;
event ProposalSubmitted(address indexed _beneficiary, uint _valueInWei);
/*
* Returns a list of beneficiaries for the open proposals. Open
* proposal is the one in which the majority of voters have not
* voted yet.
*/
function listOpenBeneficiariesProposals() external view returns (address[]);
/*
* Returns the value requested by the given beneficiary in his proposal.
*/
function getBeneficiaryProposal(address _beneficiary) external view returns (uint);
/*
* List the addresses of the contributors, which are people that sent
* Ether to this contract.
*/
function listContributors() external view returns (address[]);
/*
* Returns the amount sent by the given contributor in Wei.
*/
function getContributorAmount(address _contributor) external view returns (uint);
/*
* Approve the proposal for the given beneficiary
*/
function approve(address _beneficiary) external;
event ProposalApproved(address indexed _approver, address indexed _beneficiary, uint _valueInWei);
/*
* Reject the proposal of the given beneficiary
*/
function reject(address _beneficiary) external;
event ProposalRejected(address indexed _rejecter, address indexed _beneficiary, uint _valueInWei);
/*
* Withdraw the specified value in Wei from the wallet.
* The beneficiary can withdraw any value less than or equal the value
* he/she proposed. If he/she wants to withdraw more, a new proposal
* should be sent.
*
*/
function withdraw(uint _valueInWei) external;
event WithdrawPerformed(address indexed _beneficiary, uint _valueInWei);
/*
* Returns whether a given signer has voted in the given proposal and if so,
* what was his/her vote.
*
* @returns 0: if signer has not voted yet in this proposal, 1: if signer
* has voted YES in this proposal, 2: if signer has voted NO in this proposal
*/
function getSignerVote(address _signer, address _beneficiary) view external returns(uint);
}
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;
}
}
}
pragma solidity ^0.4.24;
contract KHAJA {
address public _owner;
uint _totalSupply = 1000000 * 10 ** uint(_decimals);
//uint _totalSupply = 1000;
string _name = "KHAJA";
string _symbol = "KMM";
uint8 _decimals = 2;
mapping (address => uint) _balanceOf;
mapping(address => mapping (address => uint)) _allowance;
uint _tokensIssued;
event Transfer(address indexed _to, uint value);
event Transfer(address indexed _from, address indexed _to, uint value);
event Approval(address indexed _owner, address indexed _spender, uint value);
modifier isOwner() {
require(msg.sender == _owner);
_;
}
constructor() public payable {
_owner = msg.sender;
//_balanceOf[msg.sender] = _totalSupply;
}
function name() view public returns (string) {
return _name;
}
function symbol() view public returns (string) {
return _symbol;
}
function decimals() view public returns (uint8) {
return _decimals;
}
function totalSupply() view public returns (uint) {
return _totalSupply;
}
function balanceOf(address _addr) view public returns (uint) {
return _balanceOf[_addr];
}
// Write a function to purchase the tokens with first half 50% and second half 1 ether = 1 token
function() public payable {
require(msg.value != 0 ether);
require(_tokensIssued < _totalSupply);
uint tokensToTransfer;
//uint extraEth;
uint tokenPrice;
if(_tokensIssued <= _totalSupply/2) {
tokenPrice = 0.5 ether;
tokensToTransfer =(msg.value * 2);
//extraEth = msg.value - (tokensToTransfer * tokenPrice);
if(_balanceOf[msg.sender]>0) {
_balanceOf[msg.sender] += tokensToTransfer;
}else {
_balanceOf[msg.sender] = tokensToTransfer;
}
_tokensIssued += tokensToTransfer;
}else {
tokenPrice = 1 ether;
// tokensToTransfer = msg.value * tokenPrice;
tokensToTransfer = msg.value;
//extraEth = msg.value - (tokensToTransfer * tokenPrice);
if(_balanceOf[msg.sender]>0) {
_balanceOf[msg.sender] += tokensToTransfer;
}else {
_balanceOf[msg.sender] = tokensToTransfer;
}
_tokensIssued += tokensToTransfer;
}
// if(extraEth > 0) {
// msg.sender.transfer(extraEth);
// }
}
function withDraw() isOwner public {
_owner.transfer(address(this).balance);
}
function transfer(address _to ,uint value) public returns (bool) {
bool flag = false;
if(_balanceOf[_to] > 0) {
_balanceOf[msg.sender] -= value;
_balanceOf[_to] += value;
flag = true;
_allowance[msg.sender][_to] = value;
emit Transfer(_to, value);
} else {
_balanceOf[msg.sender] -= value;
_balanceOf[_to] = value;
flag = true;
emit Transfer(_to, value);
}
return flag;
}
function transferFrom(address _from, address _to, uint value) public {
require(_balanceOf[_from] > 0);
require(approve(_from, value));
_allowance[_from][_to] = value;
_balanceOf[_from] -= value;
_balanceOf[_to] += value;
emit Transfer(_from, _to, value);
}
function approve(address _spender, uint value) public returns (bool) {
require(_balanceOf[_spender] >= value);
emit Approval(_owner, _spender, value);
return true;
}
function allowance(address owner, address _spender) view public returns (uint) {
return _allowance[owner][_spender];
}
function getContractBalance() view public returns(uint) {
return address(this).balance;
}
}
pragma solidity ^0.4.20;
//import "./AbstractMultiSig.sol";
contract MultiSig {
address public _owner = msg.sender;
uint public state;
uint private indexToBeDeleted;
struct contributor {
uint amount;
uint index;
}
mapping (address => contributor) Contributions;
address[] private contributorIndex;
struct proposal {
uint amount;
uint8 status; //0 initialization,1 pending, 2 Approved, 3 Rejected, 4 withdrawn
uint8 approvers;
uint8 rejectors;
uint index;
}
//address[] signers= [0xfA3C6a1d480A14c546F12cdBB6d1BaCBf02A1610,0x2f47343208d8Db38A64f49d7384Ce70367FC98c0, 0x7c0e7b2418141F492653C6bF9ceD144c338Ba740];
address[] signers= [0x14723A09ACff6D2A60DcdF7aA4AFf308FDDC160C,0x2f47343208d8Db38A64f49d7384Ce70367FC98c0, 0x7c0e7b2418141F492653C6bF9ceD144c338Ba740];
address a = 0x14723a09acff6d2a60dcdf7aa4aff308fddc160c;
//uint signers = 3;
mapping (address => proposal) subProposals;
address[] OpenBeneficiaries;
address[] ApprovedBeneficiaries;
event ReceivedContribution(address indexed _contributor, uint value);
event ProposalSubmitted(address indexed _beneficiary, uint _value);
event ProposalApproved(address indexed _approver, address indexed _beneficiary, uint _value);
event ProposalRejected(address indexed _approver, address indexed _beneficiary, uint _value);
event WithdrawPerformed(address indexed beneficiary, uint _value);
modifier isowner() {
require(msg.sender == _owner,"Not Authorized");
_;
}
// This needs to be modified
modifier isValidOwner() {
for(uint index = 0; index < signers.length; index++){
if(signers[index]==msg.sender){
require(msg.sender == _owner || signers[index]==msg.sender, "Not Authorized");
_;
return;
}
}
revert();
}
function addSigner(address signer) isowner public {
for(uint index = 0; index < signers.length; index++){
if(signers[index]==signer){
assert(signers[index] != signer);
}
}
signers.push(signer);
}
// This is only a work around, needs to permenantly delete the signer from the dynamic array
function remove(address signer) private isowner returns(address[]) {
for (uint i = 0; i<signers.length; i++){
if(signers[i] == signer) {
delete signers[i];
}
}
return signers;
}
function removeSigner(address signer) isowner public {
remove(signer);
}
function listOfSigners() view public returns(address[]) {
return signers;
}
function isContributor(address _contributor) public view returns(bool) {
if(contributorIndex.length == 0) {return false;}
return (contributorIndex[Contributions[_contributor].index] == _contributor);
}
function Contribute() public payable {
require(state == 0,"Contract is active");
require(msg.value > 0,"value should be more than 0");
// Signers cannot contribute
for(uint index = 0; index < signers.length; index++){
require(signers[index] != msg.sender);
}
if(isContributor(msg.sender)){
Contributions[msg.sender].amount += msg.value;
}
else{
Contributions[msg.sender].amount = msg.value;
Contributions[msg.sender].index = contributorIndex.push(msg.sender) - 1;
}
emit ReceivedContribution(msg.sender, msg.value);
}
function endContribution() external isValidOwner {
state = 1;
}
function listContributors() external view returns (address[]){
return contributorIndex;
}
function getContributorAmount(address _contributor) external view returns (uint){
return Contributions[_contributor].amount;
}
function getContractbalance() public view returns (uint) {
return address(this).balance;
}
function submitProposal(uint _value) external {
//proposal memory Prop;
require(state == 1,"Contract is not active yet");
require(isContributor(msg.sender),"Invalid, not a contributor");
require(_value <= (address(this).balance)/10 ether,"Cant withdraw more than 10% of contract balance");
require(_value <= Contributions[msg.sender].amount,"cant withdraw more than your contribution");
require(subProposals[msg.sender].status != 1 && subProposals[msg.sender].status != 2, "Request Already in Queue");
subProposals[msg.sender].amount = _value ;
subProposals[msg.sender].status = 1 ;
subProposals[msg.sender].index = OpenBeneficiaries.push(msg.sender)-1;
emit ProposalSubmitted(msg.sender, _value);
}
function listOpenBeneficiariesProposals() external view returns (address[]){
return OpenBeneficiaries;
}
function listApprovedBenef() external view returns(address[]){
return ApprovedBeneficiaries;
}
function getBeneficiaryProposal(address _beneficiary) external view returns (uint){
return subProposals[_beneficiary].amount;
}
function approve(address _beneficiary) external {
require(state == 1, "Contract is not active yet");
require(OpenBeneficiaries[subProposals[_beneficiary].index] == _beneficiary,"No open request ");
require(_beneficiary != address(0),"should not be zero address");
subProposals[_beneficiary].approvers += 1;
if(subProposals[_beneficiary].approvers > signers.length/2){
subProposals[_beneficiary].status = 2;
address movingbenef = OpenBeneficiaries[subProposals[_beneficiary].index];
delete OpenBeneficiaries[subProposals[_beneficiary].index];
subProposals[_beneficiary].index = ApprovedBeneficiaries.push(movingbenef)-1;
emit ProposalApproved(msg.sender, _beneficiary, subProposals[_beneficiary].amount);
}
}
function reject(address _beneficiary) external{
require(state == 1, "Contract is not active yet" );
require(OpenBeneficiaries[subProposals[_beneficiary].index] == _beneficiary,"No open request ");
require(_beneficiary != address(0),"should not be zero address");
subProposals[_beneficiary].rejectors += 1;
if(subProposals[_beneficiary].rejectors > signers.length/2){
subProposals[_beneficiary].status = 3;
//address movingbenef = OpenBeneficiaries[subProposals[_beneficiary].index];
delete OpenBeneficiaries[subProposals[_beneficiary].index];
//subProposals[_beneficiary].index = ApprovedBeneficiaries.push(movingbenef)-1;
emit ProposalRejected(msg.sender, _beneficiary, subProposals[_beneficiary].amount);
}
}
function withdraw(uint _value) external {
require(state == 1,"Contract is not active yet");
require(_value <= subProposals[msg.sender].amount,"value should be less than approved amount" );
require(ApprovedBeneficiaries[subProposals[msg.sender].index] == msg.sender,"Not in ApprovedBeneficiaries");
//require(subProposals[msg.sender].amount > 0,"");
subProposals[msg.sender].amount -= _value;
Contributions[msg.sender].amount -= _value;
if (subProposals[msg.sender].amount == 0){
delete ApprovedBeneficiaries[subProposals[msg.sender].index];
subProposals[msg.sender].status = 4;
}
uint val = _value * 1000000000000000000 wei;
msg.sender.transfer(val);
emit WithdrawPerformed(msg.sender, _value);
}
}
pragma solidity ^0.4.24;
import "./AbstractMultiSig.sol";
contract MultiSigUpdated is AbstractMultiSig {
address _owner;
uint state;
struct contributor {
uint amount;
uint index;
}
mapping (address => contributor) Contributions;
address[] private contributorIndex;
struct proposal {
uint amount;
uint8 status;
uint8 approvers;
uint8 rejectors;
mapping (address => uint8) signed;
uint index;
}
address[] signers= [
0xfA3C6a1d480A14c546F12cdBB6d1BaCBf02A1610,
0x2f47343208d8Db38A64f49d7384Ce70367FC98c0,
0x7c0e7b2418141F492653C6bF9ceD144c338Ba740
];
mapping (address => proposal) subProposals;
address[] OpenBeneficiaries;
address[] ApprovedBeneficiaries;
event ReceivedContribution(address indexed _contributor, uint _valueInWei);
event ProposalSubmitted(address indexed _beneficiary, uint _valueInWei);
event ProposalApproved(address indexed _approver, address indexed _beneficiary, uint _valueInWei);
event ProposalRejected(address indexed _rejecter, address indexed _beneficiary, uint _valueInWei);
event WithdrawPerformed(address indexed _beneficiary, uint _valueInWei);
constructor () public {
_owner = msg.sender;
}
modifier isowner() {
require(_owner==msg.sender);
_;
}
function owner() external returns(address){
return _owner;
}
function isSigner(address _sigaddr) public view returns(bool){
for (uint i = 0; i < signers.length; i++){
if(signers[i]==_sigaddr){
return true;
}
}
return false;
}
function isContributor(address _contributor) public view returns(bool) {
if(contributorIndex.length == 0) {return false;}
return (contributorIndex[Contributions[_contributor].index] == _contributor);
}
function() public payable {
require(state == 0);
require(msg.value > 0);
if(isContributor(msg.sender)){
Contributions[msg.sender].amount += msg.value;
}
else{
Contributions[msg.sender].amount = msg.value;
Contributions[msg.sender].index = contributorIndex.push(msg.sender) - 1;
}
emit ReceivedContribution(msg.sender, msg.value);
}
function endContributionPeriod() external isowner {
state = 1;
}
function listContributors() external view returns (address[]){
return contributorIndex;
}
function getContributorAmount(address _contributor) external view returns (uint){
return Contributions[_contributor].amount;
}
function getContractbalance() public view returns (uint) {
return address(this).balance;
}
function submitProposal(uint _valueInWei) external{
require(state == 1);
require(isContributor(msg.sender));
require(_valueInWei <= Contributions[msg.sender].amount);
require(_valueInWei <= address(this).balance/10);
require(subProposals[msg.sender].status != 1 && subProposals[msg.sender].status != 2);
subProposals[msg.sender].amount = _valueInWei;
subProposals[msg.sender].status = 1;
subProposals[msg.sender].index = OpenBeneficiaries.push(msg.sender)-1;
emit ProposalSubmitted(msg.sender, _valueInWei);
}
function listOpenBeneficiariesProposals() external view returns (address[]){
return OpenBeneficiaries;
}
function listApprovedBenef() external view returns(address[]){
return ApprovedBeneficiaries;
}
function getBeneficiaryProposal(address _beneficiary) external view returns (uint){
return subProposals[_beneficiary].amount;
}
function getSignerVote(address _signer_addr, address _beneficiary) external view returns (uint){
return subProposals[_beneficiary].signed[_signer_addr];
}
function approve(address _beneficiary) external{
require(state == 1);
require(isSigner(msg.sender) == true);
require(subProposals[_beneficiary].signed[msg.sender] != 0);
require(OpenBeneficiaries[subProposals[_beneficiary].index] == _beneficiary);
require(_beneficiary != address(0));
subProposals[_beneficiary].approvers += 1;
subProposals[_beneficiary].signed[msg.sender] = 1;
if(subProposals[_beneficiary].approvers > signers.length/2){
subProposals[_beneficiary].status = 2;
address movingbenef = OpenBeneficiaries[subProposals[_beneficiary].index];
delete OpenBeneficiaries[subProposals[_beneficiary].index];
subProposals[_beneficiary].index = ApprovedBeneficiaries.push(movingbenef)-1;
}
emit ProposalApproved(msg.sender, _beneficiary, subProposals[_beneficiary].amount);
}
function reject(address _beneficiary) external{
require(state == 1);
require(isSigner(msg.sender) == true);
require(OpenBeneficiaries[subProposals[_beneficiary].index] == _beneficiary);
require(_beneficiary != address(0));
subProposals[_beneficiary].signed[msg.sender] = 2;
subProposals[_beneficiary].rejectors += 1;
emit ProposalRejected(msg.sender, _beneficiary, subProposals[_beneficiary].amount);
if(subProposals[_beneficiary].rejectors > signers.length/2){
subProposals[_beneficiary].status = 3;
delete OpenBeneficiaries[subProposals[_beneficiary].index];
}
}
function withdraw(uint _valueInWei) external {
require(state == 1);
require(_valueInWei <= subProposals[msg.sender].amount);
require(ApprovedBeneficiaries[subProposals[msg.sender].index] == msg.sender);
//uint val = _value * 1000000000000000000 wei;
subProposals[msg.sender].amount -= _valueInWei;
Contributions[msg.sender].amount -= _valueInWei;
if (subProposals[msg.sender].amount == 0){
delete ApprovedBeneficiaries[subProposals[msg.sender].index];
subProposals[msg.sender].status = 4;
}
emit WithdrawPerformed(msg.sender, _valueInWei);
msg.sender.transfer(_valueInWei);
}
}
pragma solidity ^0.4.24;
contract QuoteRegistry {
address owner;
mapping (string => address) register;
uint balance;
constructor() {
owner = msg.sender;
}
modifier isOwner {
require(msg.sender == owner);
_;
}
function register(string _quote) public {
register[_quote] = msg.sender;
}
function ownership(string _quote) public returns (address) {
return register[_quote];
}
function transfer(string _quote, address _newOwner) {
balance = msg.balance;
if(msg.balance >= 0.5 & register[_quote] != "") {
_newOwner.balance = _newOwner.balance - 0.5;
register[_quote].balance = register[_quote].balance + 0.5;
register[_quote] = _newOwner;
}
}
function owner() returns (address) {
return owner;
}
}
pragma solidity ^0.4.24;
contract RoamwareAgreement {
address _owner;
struct _subscriberDetails {
// Mapping IMEI Number to ROAMToken Address
mapping(uint => address) _subscriber;
}
// Name to address to bool mapping
mapping (bytes32 => address) _operator;
modifier isOwner() {
require(msg.sender == _owner);
_;
}
constructor() public {
_owner = msg.sender;
}
modifier isOperator(bytes32 operatorName) {
require(msg.sender == _operator[operatorName]);
_;
}
function getOperatorAddress(bytes32 operatorName) public view returns(address) {
return _operator[operatorName];
}
function isAgreed() public view returns(uint8) {
}
function agreement() public {
}
}
pragma solidity ^0.4.24;
contract RoamwareSubscriberSource {
address _owner;
struct _servicesDetails {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment