-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlowerSacrifice.sol
51 lines (41 loc) · 1.19 KB
/
FlowerSacrifice.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
pragma solidity ^0.5.1;
import "./IERC20.sol";
import "./ISacrifice.sol";
contract FlowerSacrifice is ISacrifice {
uint private _price;
address private _erc20Address;
string private _name;
string private _flower;
address public _owner;
constructor(address _ad, uint _p) public {
_erc20Address = _ad;
_price = _p;
_owner = msg.sender;
}
function updatePrice(address _ad, uint _p) public {
require(_ad != address(0));
require(_owner == msg.sender);
_erc20Address = _ad;
_price = _p;
}
function updateFlower(string memory _nm, string memory _f) public {
require(_owner == msg.sender);
require(bytes(_f).length<1000 && bytes(_f).length>0);
_flower = _f;
_name = _nm;
}
function getSacrifice() external view returns (string memory, string memory){
return (_name, _flower);
}
function getPrice() external view returns (address, uint) {
return (_erc20Address, _price);
}
function buySacrifice() external returns (string memory) {
require(IERC20(_erc20Address).transferFrom(msg.sender, address(this), _price));
return _flower;
}
function withdrawTokens(uint num) public {
require(_owner == msg.sender);
require(IERC20(_erc20Address).transfer(msg.sender, num));
}
}