Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- The following is an extremely basic example of a solidity contract.
- It takes a string upon creation and then repeats it when greet() is called.
- */
- contract Greeter // The contract definition. A constructor of the same name will be automatically called on contract creation.
- {
- address creator; // At first, an empty "address"-type variable of the name "creator". Will be set in the constructor.
- string greeting; // At first, an empty "string"-type variable of the name "greeting". Will be set in constructor and can be changed.
- bytes32 hashMessage;
- event offChainStuff (bytes32 hash, string greeting);
- event onChainStuff (bytes32 hashMessage);
- function Greeter(string _greeting) public // The constructor. It accepts a string input and saves it to the contract's "greeting" variable.
- {
- creator = msg.sender;
- greeting = _greeting;
- }
- function mortal() {
- creator = msg.sender;
- }
- function getCreator() constant public returns (address) {
- return creator;
- }
- // Hey, go provide me the value of the message from the db with this contract's greeting hash.
- function fireOnChainEvent() public {
- onChainStuff(hashMessage);
- }
- // get the value back from the DB, and returns it to the user.
- function greet(string message) constant public returns (string)
- {
- // run intergrity check here.
- if(keccak256(message) == hashMessage) {
- return message;
- } else {
- return "ALERT! DATA HAS BEEN CORRUPTED";
- }
- }
- function getBlockNumber() constant public returns (uint) // this doesn't have anything to do with the act of greeting
- { // just demonstrating return of some global variable
- return block.number;
- }
- function setGreeting(string _newgreeting) public
- {
- greeting = _newgreeting;
- }
- function startOffChain(string _newgreeting) public {
- hashMessage = keccak256(_newgreeting);
- offChainStuff(hashMessage, _newgreeting);
- }
- /**********
- Standard kill() function to recover funds
- **********/
- function kill() public
- {
- if (msg.sender == creator) // only allow this action if the account sending the signal is the creator
- suicide(creator); // kills this contract and sends remaining funds back to creator
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement