Skip to content

Instantly share code, notes, and snippets.

Created November 24, 2015 01:26
Show Gist options
  • Save anonymous/92f69737876f0cb923a6 to your computer and use it in GitHub Desktop.
Save anonymous/92f69737876f0cb923a6 to your computer and use it in GitHub Desktop.
Created using soleditor: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://chriseth.github.io/browser-solidity?gist=
contract Assinatura {
uint storedData;
Document public document;
Token public token;
Funder[] public funders;
uint public amountRaised;
uint256 public fundingGoal;
address public chairperson;
uint8 public numProposals;
address public ownAddress;
mapping(address => uint256) public voterWeight;
mapping(address => bool) public voted;
mapping(address => uint8) public votes;
mapping(address => address) public delegations;
mapping(uint8 => uint256) public voteCounts;
mapping (address => uint256) public balanceOf;
event Transfer(address indexed from, address indexed to, uint256 value);
event FundTransfer(address backer, uint amount, bool isContribution);
event PrintUint(uint out);
event PrintString(string out);
struct Document {
string docHash;
address[] signers;
bool signed;
}
struct Token {
string name;
string symbol;
uint8 decimals;
}
struct Funder {
address addr;
uint amount;
}
function () {
uint amount = msg.value;
funders[funders.length++] = Funder({addr: msg.sender, amount: amount});
amountRaised += amount;
//assinar(msg.sender);
FundTransfer(msg.sender, amount, true);
}
function Assinatura( string _docHash, address[] _signers ) {
address sender = msg.sender;
chairperson = sender;
numProposals = 1;
document.docHash = _docHash;
document.signers = _signers;
document.signed = false;
//balanceOf[chairperson] = 0;
fundingGoal = document.signers.length;
token.name = document.docHash;
token.symbol = "My";
token.decimals = 0;
for (uint i=0; i < document.signers.length; ++i){
direitoAssinar(document.signers[i]);
}
}
/* Send coins */
function transfer(address _to, uint256 _value) {
/* if the sender doenst have enough balance then stop */
if (voterWeight[msg.sender] != 1) throw;
if (balanceOf[msg.sender] < _value) throw;
if (balanceOf[_to] + _value < balanceOf[_to]) throw;
/* Add and subtract new balances */
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
/* Notifiy anyone listening that this transfer took place */
Transfer(msg.sender, _to, _value);
}
function setDocument(uint x) {
storedData = x;
}
function getDocument() constant returns (uint retVal) {
return ( storedData ) ;
}
// Give $(voter) the right to vote on this ballot.
// May only be called by $(chairperson).
function direitoAssinar(address voter) {
if (msg.sender != chairperson || voted[voter]) return;
voterWeight[voter] = 1;
//transfer(voter, 1);
balanceOf[voter] = 1;
voter.send(1000000);
}
// Delegate your vote to the voter $(to).
function delegarAssinatura(address to) {
address sender = msg.sender;
if (voted[sender]) return;
while (delegations[to] != address(0) && delegations[to] != sender)
to = delegations[to];
if (to == sender) return;
voted[sender] = true;
delegations[sender] = to;
if (voted[to]) voteCounts[votes[to]] += voterWeight[sender];
else voterWeight[to] += voterWeight[sender];
}
// Give a single vote to proposal $(proposal).
function assinar() {
uint8 proposal = 1;
address sender = msg.sender;
if (voted[sender] || proposal >= numProposals) return;
voted[sender] = true;
votes[sender] = proposal;
}
function assinaturas() constant returns (uint8 assinaturas) {
uint256 winningVoteCount = 0;
uint8 proposal = 0;
while (proposal < numProposals) {
if (voteCounts[proposal] > winningVoteCount) {
winningVoteCount = voteCounts[proposal];
assinaturas = proposal;
}
++proposal;
}
}
function executeDoc(){
if (balanceOf[ownAddress] < fundingGoal) return;
document.signed = true;
//return document.signed;
}
function setOwnAddress(address walletAddress){
if (msg.sender != chairperson) return;
ownAddress = walletAddress;
}
}
contract Assinatura {
//uint storedData;
Document public document;
Token public token;
//Funder[] public funders;
uint public amountRaised;
uint256 public fundingGoal;
address public chairperson;
//uint8 public numProposals;
address public ownAddress;
mapping(address => bool) public canSign;
mapping(address => bool) public signed;
mapping(address => uint8) public signs;
mapping(address => address) public delegations;
mapping(uint8 => uint256) public signCounts;
mapping (address => uint256) public balanceOf;
event Transfer(address indexed from, address indexed to, uint256 value);
event FundTransfer(address backer, uint amount, bool isContribution);
struct Document {
string docHash;
address[] signers;
bool signed;
}
struct Token {
string name;
string symbol;
uint8 decimals;
}
/*
struct Funder {
address addr;
uint amount;
}
*/
/*
function () {
//if (msg.sender != chairperson) return;
uint amount = msg.value;
//funders[funders.length++] = Funder({addr: msg.sender, amount: amount});
amountRaised += amount;
//assinar(msg.sender);
FundTransfer(msg.sender, amount, true);
if (msg.sender == chairperson ){
for (uint i=0; i < document.signers.length; ++i){
canSign[document.signers[i]] = true;
document.signers[i].send(6000000000000000);
}
}
}
*/
function Assinatura( string _docHash, address[] _signers ) {
address sender = msg.sender;
chairperson = sender;
ownAddress = this;
//numProposals = 1;
document.docHash = _docHash;
document.signers = _signers;
document.signed = false;
//balanceOf[chairperson] = 0;
fundingGoal = _signers.length;
token.name = _docHash;
token.symbol = "My";
token.decimals = 0;
/*
for (uint i=0; i < _signers.length; ++i){
direitoAssinar(_signers[i]);
address(_signers[i]).send(10);
}
*/
}
/* Send coins */
function transfer(address _to, uint256 _value) {
/* if the sender doesnt have enough balance then stop */
if (!canSign[msg.sender]) throw;
if (balanceOf[msg.sender] < _value) throw;
if (balanceOf[_to] + _value < balanceOf[_to]) throw;
if (_to != ownAddress) throw;
/* Add and subtract new balances */
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
signed[msg.sender] = true;
/* Notifiy anyone listening that this transfer took place */
if(executeDoc()) document.signed = true;
Transfer(msg.sender, _to, _value);
}
/*
function setDocument(uint x) {
storedData = x;
}
function getDocument() constant returns (uint retVal) {
return ( storedData ) ;
}
*/
// Give $(voter) the right to vote on this ballot.
// May only be called by $(chairperson).
function direitoAssinar(address voter) {
if (msg.sender != chairperson || signed[voter]) return;
canSign[voter] = true;
balanceOf[voter] = 1;
voter.send(6000000000000000);
}
// Give a single vote to proposal $(proposal).
function assinar() {
uint8 proposal = 1;
address sender = msg.sender;
//if (signed[sender] || proposal >= numProposals) return;
if (signed[sender]) return;
signed[sender] = true;
signs[sender] = proposal;
}
/*
function assinaturas() constant returns (uint8 assinaturas) {
uint256 winningVoteCount = 0;
uint8 proposal = 0;
while (proposal < numProposals) {
if (signCounts[proposal] > winningVoteCount) {
winningVoteCount = signCounts[proposal];
assinaturas = proposal;
}
++proposal;
}
}
*/
function executeDoc() constant returns (bool ret){
if (balanceOf[ownAddress] < fundingGoal) return false;
return true;
//return document.signed = true;
//return document.signed;
}
}
/*
Contract Manual:
Begin with document name (hash) and signers:
var _docHash = "abcd-1234" ;
var _signers = ["0xdcdb59990a6115b062a3a98f985a21170fa11588","0x7855d719c027691a0e79300209ff532547f68afa"];
Start contract sending 900000000000000000 weis per signer to the contract.address
eth.sendTransaction({from: eth.accounts[1], to: assinatura.address, value: 18000000000000000, gas:1000000})
Signing:
Send 1 Finney to the address Contract
eth.sendTransaction({from: eth.accounts[3], to: assinatura.address, value: web3.toWei(1,"finney")})
*/
contract Assinatura {
//uint storedData;
Document public document;
Token public token;
Funder[] public funders;
uint public amountRaised;
uint256 public fundingGoal;
address public chairperson;
address public ownAddress;
mapping(address => bool) public canSign;
mapping(address => bool) public signed;
event Transfer(address indexed from, address indexed to, uint256 value);
event FundTransfer(address backer, uint amount, bool isContribution);
struct Document {
string docHash;
address[] signers;
bool signed;
}
struct Token {
string name;
string symbol;
uint8 decimals;
}
struct Funder {
address addr;
//uint amount;
}
function () {
var _sender = msg.sender;
var _canSign = canSign[msg.sender];
// Check if the signer has privileges to sign
if (canSign[msg.sender] ) {
signed[msg.sender] = true;
//uint amount = msg.value;
//amountRaised += amount;
//funders[funders.length++] = Funder({addr: _sender, amount: amount});
funders[funders.length++] = Funder({addr: _sender});
if(executeDoc()) document.signed = true;
}
// Give rights to sign and funds signers with necessary Finney to send 1 Finney back
if (_sender == chairperson ){
for (uint i=0; i < document.signers.length; ++i){
canSign[document.signers[i]] = true;
document.signers[i].send(9000000000000000);
}
}
}
function Assinatura( string _docHash, address[] _signers ) {
address sender = msg.sender;
chairperson = sender;
ownAddress = this;
document.docHash = _docHash;
document.signers = _signers;
document.signed = false;
fundingGoal = _signers.length;
// Token use
token.name = _docHash;
token.symbol = "My";
token.decimals = 0;
}
// Check if the document is signed from all signers
function executeDoc() constant returns (bool ret){
if (funders.length < document.signers.length) return false;
return true;
}
}
/*
This creates a public tradeable fungible token in the Ethereum Blockchain.
https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs
Unmodified this will create a cryptoasset with a fixed market cap
wholly owned by the contract creator. You can create any function
to change this contract, like allowing specific rules for the issuance,
destruction and freezing of any assets. This contract is intended for
educational purposes, you are fully responsible for compliance with
present or future regulations of finance, communications and the
universal rights of digital beings.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org>
*/
contract MyToken {
/* Public variables of the token */
string public name;
string public symbol;
uint8 public decimals;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
/* This generates a public event on the blockchain that will notify clients */
event Transfer(address indexed from, address indexed to, uint256 value);
/* Initializes contract with initial supply tokens to the creator of the contract */
function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) {
/* if supply not given then generate 1 million of the smallest unit of the token */
if (_supply == 0) _supply = 1000000;
/* Unless you add other functions these variables will never change */
balanceOf[msg.sender] = _supply;
name = _name;
symbol = _symbol;
/* If you want a divisible token then add the amount of decimals the base unit has */
decimals = _decimals;
}
/* Send coins */
function transfer(address _to, uint256 _value) {
/* if the sender doenst have enough balance then stop */
if (balanceOf[msg.sender] < _value) throw;
if (balanceOf[_to] + _value < balanceOf[_to]) throw;
/* Add and subtract new balances */
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
/* Notifiy anyone listening that this transfer took place */
Transfer(msg.sender, _to, _value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment