-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPatron.sol
70 lines (53 loc) · 2.17 KB
/
Patron.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
//for compability reasons, we work only with these versions
pragma solidity >=0.7.0 < 0.9.0;
import "./DArt.sol";
import "./DCoin.sol";
contract Patron {
event Donation(address sender, address indexed receiver, bytes32 artwork);
event UnlockedFunds(address indexed receiver, bytes32 artwork);
mapping (bytes32 => uint) public patronCredit;
mapping (bytes32 => uint) public funds;
address public minter;
//address public constant verificatioSmartcontract;
DCoin public dcoinSmartcontract;
//address public dcoinSmartcontract;
DArt public mainSmartcontract;
constructor(){
minter = msg.sender;
}
function setContrats(address main, address dcoin) external {
assert(msg.sender == minter);
mainSmartcontract = DArt(main);
dcoinSmartcontract = DCoin(dcoin);
}
function crowfunding(bytes32 artwork, uint amount) external {
address museum = mainSmartcontract.getProperty(artwork);
require(museum != address(0x0), "Artwork does not exist");
dcoinSmartcontract.lock(amount, msg.sender);
funds[artwork] += amount;
patronCredit[hashAddressAndAddress(msg.sender, museum)] += amount;
emit Donation(msg.sender, museum, artwork);
}
function hashAddressAndAddress(address first, address second) public pure returns(bytes32) {
return keccak256(abi.encodePacked(first, second));
}
function viewFunds(bytes32 artwork) external view returns(uint){
return funds[artwork];
}
function viewPatronCredit(address patron, address museum) external view returns(uint){
return patronCredit[keccak256(abi.encodePacked(patron,museum))];
}
function moveFunds(address _to, bytes32 artwork) external {
assert(msg.sender == address(mainSmartcontract));
uint fund = funds[artwork];
if (fund != 0) {
dcoinSmartcontract.magicMint(_to, fund);
funds[artwork] = 0;
emit UnlockedFunds(_to, artwork);
}
}
function terminate() public {
require(msg.sender == minter, "You cannot terminate the contract!");
selfdestruct(payable(minter));
}
}