-
Notifications
You must be signed in to change notification settings - Fork 1
/
herencia.sol
126 lines (95 loc) · 2.86 KB
/
herencia.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// SPDX-License-Identifier: MIT
pragma solidity ^0.8;
contract Ownable {
address public owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner {
require(msg.sender==owner,"Solo puede llamarla el beneficiario");
_;
}
}
contract Pausable is Ownable {
bool public paused;
modifier WhenPaused {
require(paused,"Solo cuando esta pausado");
_;
}
modifier WhenNotPaused {
require(!paused,"Solo cuando esta activo");
_;
}
constructor() {
paused=false;
}
function Pause() onlyOwner public {
require(!paused,"Ya esta pausado");
paused= true;
}
function Unpause() onlyOwner public {
require(paused,"Ya esta activo");
paused= false;
}
}
contract AuthList is Ownable {
mapping(address=>bool) private Authorized;
modifier onlyAuthorized {
require(isAuthorized(msg.sender),"No esta en la lista de autorizados");
_;
}
function Grant(address _newAddress) public {
require(isAuthorized(_newAddress),"Autorizacion ya entregada");
Authorized[_newAddress] = true;
}
function Revoke(address _newAddress) public {
require(!isAuthorized(_newAddress),"Autorizacion ya revocada");
Authorized[_newAddress] = false;
}
function isAuthorized(address _addr) public view returns(bool) {
return Authorized[_addr];
}
}
contract DemoAddress {
uint public saldo;
address public beneficiario;
mapping(address=>uint) public aportes;
uint public meta;
bool public aportesAbiertos;
bool public devolucionHabilitada;
modifier onlyBeneficiario {
require(msg.sender==beneficiario,"Solo puede llamarla el beneficiario");
_;
}
modifier onlyColectaAbierta {
require(aportesAbiertos,"La colecta esta cerrada");
_;
}
constructor(uint _meta) {
beneficiario = msg.sender;
aportesAbiertos = true;
meta = _meta;
devolucionHabilitada = false;
}
function depositar() public payable onlyColectaAbierta {
saldo = saldo + msg.value;
aportes[msg.sender]= aportes[msg.sender] + msg.value;
}
function retirarAporte() public {
require(devolucionHabilitada,"Las devoluciones no estan habilitadas");
require(aportes[msg.sender]>0,"No tiene saldo por retirar");
payable(msg.sender).transfer(aportes[msg.sender]);
saldo = saldo - aportes[msg.sender];
aportes[msg.sender]=0;
}
function cerrarAportes() public onlyBeneficiario onlyColectaAbierta {
aportesAbiertos = false;
if(saldo >= meta) {
payable(beneficiario).transfer(saldo);
saldo = 0;
selfdestruct(payable(msg.sender));
} else{
devolucionHabilitada = true;
}
}
}