-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Smart contracts Escrow Deed & Vending
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.5; | ||
|
||
|
||
contract Deed{ | ||
address public add1; | ||
address payable public add2; | ||
uint public earliest; | ||
|
||
constructor(address _add1, address payable _add2, uint fromNow)payable{ | ||
add1 = _add1; | ||
add2 = _add2; //Esta es la cuenta que va a recibir | ||
earliest = block.timestamp + fromNow; | ||
} | ||
|
||
function withdraw() public{ | ||
require(msg.sender==add1,"Add1 solo puede pagar, no puede recibir :)"); | ||
require(block.timestamp>=earliest,"Demasiado pronto para el pago :)"); | ||
add2.transfer(address(this).balance); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.5; | ||
|
||
|
||
contract Escrow{ | ||
address public payer; | ||
address payable public payee; | ||
address public lawyer; | ||
uint public amount; | ||
|
||
constructor(address _payer, address payable _payee, uint _amount){ | ||
payer = _payer; | ||
payee = _payee; | ||
lawyer = msg.sender; | ||
amount = _amount; | ||
} | ||
|
||
function deposit() payable public{ | ||
require(msg.sender == payer, "LautiRad"); | ||
require(address(this).balance <= amount, "LautiRad LautiRad"); | ||
} | ||
|
||
function release() public{ | ||
require(address(this).balance == amount, "Bla bla"); | ||
require(msg.sender == lawyer, "Bla bla mas texto :D"); | ||
payee.transfer(amount); | ||
} | ||
|
||
function balanceOf() view public returns(uint) { | ||
return address(this).balance; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.7; | ||
|
||
contract VendingMachine { | ||
|
||
address public owner; | ||
mapping (address => uint) public cupcakeBalances; | ||
|
||
constructor() { | ||
|
||
owner = msg.sender; | ||
cupcakeBalances[address(this)] = 100; | ||
} | ||
|
||
function refill(uint amount) public { | ||
require(msg.sender == owner, "Solo el propietario puede recargar."); | ||
cupcakeBalances[address(this)] += amount; | ||
} | ||
|
||
function purchase(uint amount) public payable { | ||
require(msg.value >= amount * 1 ether, "Debes pagar al menos 1 ETH por cupcake, Sí esta caro el cupcake xD"); | ||
require(cupcakeBalances[address(this)] >= amount, "No hay suficientes cupcakes en stock para completar esta compra 8)"); | ||
cupcakeBalances[address(this)] -= amount; | ||
cupcakeBalances[msg.sender] += amount; | ||
} | ||
} |