Last active
January 27, 2017 22:23
-
-
Save evertonfraga/9a400c14d3ab134f34e7056b2fadadc1 to your computer and use it in GitHub Desktop.
This file contains 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.5; | |
/* | |
Cadastrando itens em um struct | |
*/ | |
contract VipClub { | |
// Estrutura de dados Member, que possui os atributos `name` e `email` | |
struct Member { | |
string name; | |
string email; | |
} | |
// Criando evento Registered com parâmetro string: _name | |
event Registered(string _name, address _addr); | |
mapping (address => Member) public members; | |
// Construtor do contrato | |
function VipClub() {} | |
function register(string _name, string _email) payable { | |
if (msg.value < 5 ether) throw; | |
// Aqui criamos um struct Member com os parâmetros passados | |
// e o gravamos no mapping (hash map) `members`. | |
members[msg.sender] = Member(_name, _email); | |
// Emitindo o evento Registered, que é basatante útil quando se tem uma | |
// aplicação de Web3 sendo utilizada | |
Registered(_name, msg.sender); | |
} | |
} | |
/* | |
Possibilidades a partir deste contrato: | |
1) Cobrar uma taxa dos participantes para se cadastrar no contrato | |
Adicionar o modifier payable no método `register()`, para habilitar o envio de ether neste método | |
+ function register(string _name, string _email) payable | |
+ Definir valor mínimo (ou exato) para registro de participante no Clube | |
2) No nosso clube hipotético, o valor de uma diária custaria 1 ether. | |
+ Adicionar `uint256 balance` ao struct Member | |
+ Adicionar método `diaria()`, que subtrairia o saldo do membro que executou tal função. | |
3) Possibilidade do usuário sair do Clube, pegando reembolso total ou proporcional a algum período determinado. | |
+ function leave() | |
> usar msg.sender.send(), com valor merecido de reembolso | |
> deletar pessoa do mapping de Member | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment