Created
February 14, 2018 14:06
-
-
Save KJlmfe/36b2e6481c06f68a923da99f1553ec41 to your computer and use it in GitHub Desktop.
LoveRose Contract
This file contains hidden or 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
pragma solidity ^ 0.4.17; | |
contract LoveRose { | |
address public ceoAddress; | |
struct Rose { | |
uint64 birthTime; | |
address buyer; | |
uint value; | |
string message; | |
string from; | |
string to; | |
} | |
Rose[] roses; | |
function LoveRose() public { | |
ceoAddress = msg.sender; | |
} | |
function getRose(uint256 _id) | |
external | |
view | |
returns ( | |
uint64 birthTime, | |
address buyer, | |
string message, | |
string from, | |
string to, | |
uint value | |
) { | |
Rose storage rose = roses[_id]; | |
birthTime = rose.birthTime; | |
buyer = rose.buyer; | |
message = rose.message; | |
to = rose.to; | |
from = rose.from; | |
value = rose.value; | |
} | |
function buyRose(string from, string to, string message) public payable returns(uint) { | |
require(msg.value >= 1000000000000000); | |
// At leaset, it should be greater than 0.001 ether | |
Rose memory _rose = Rose({ | |
birthTime: uint64(now), | |
value: msg.value, | |
buyer: msg.sender, | |
from: from, | |
to: to, | |
message: message | |
}); | |
uint256 newRoseId = roses.push(_rose) - 1; | |
return newRoseId; | |
} | |
function total() public view returns (uint) { | |
return roses.length; | |
} | |
function getBalance() public view returns (uint) { | |
return this.balance; | |
} | |
function withdrawBalance() public { | |
require(msg.sender == ceoAddress); | |
ceoAddress.transfer(this.balance); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment