-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEscrow.sol
66 lines (46 loc) · 1.91 KB
/
Escrow.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
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract Escrow{
mapping(address => uint) public DepositMap;
mapping(address => uint) WithdrawedMap;
address owner;
address payable public payee;
uint public depamount;
uint public existingamount;
uint public newAmt;
uint public amtwithdraw;
uint public newbalance;
function SetPayee(address payable _payee) public {
payee = _payee;
}
modifier IsOwner() {
require(owner == msg.sender, "Not Owner!");
_;
}
modifier IsPayee() {
require(payee == address(payee), "Please enter a valid address");
_;
}
constructor(){
owner = msg.sender;
}
function deposit() payable public IsOwner{
depamount = msg.value; //get the amount to be deposited
existingamount = DepositMap[owner]; //just extending the existing mapped deposited amount to a variable
newAmt = existingamount + depamount; //add existing and to be deposited amount
DepositMap[owner] = newAmt;
// updateDep();
}
function withdraw(uint _amt) payable public IsPayee{
amtwithdraw = _amt * 1000000000000000000; // ether to wei conversion
existingamount = DepositMap[owner]; // fetch the existing balance
require(amtwithdraw <= existingamount,"Lack of funds!"); //check if owner has enough to pay for requested withdrawal
newbalance = existingamount - amtwithdraw; //subtract existing from amount to be withdrawn
DepositMap[owner] = newbalance; //update the new balance for owner
payee.transfer(amtwithdraw); //send the amount
}
function fetchBalance(address _adr) public view returns(uint){
return DepositMap[_adr];
}
}
//not the best code but pretty good for a Day2 Solidity Guy