Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. /*
  2. The following is an extremely basic example of a solidity contract.
  3. It takes a string upon creation and then repeats it when greet() is called.
  4. */
  5.  
  6. contract Greeter // The contract definition. A constructor of the same name will be automatically called on contract creation.
  7. {
  8. address creator; // At first, an empty "address"-type variable of the name "creator". Will be set in the constructor.
  9. string greeting; // At first, an empty "string"-type variable of the name "greeting". Will be set in constructor and can be changed.
  10. bytes32 hashMessage;
  11.  
  12. event offChainStuff (bytes32 hash, string greeting);
  13. event onChainStuff (bytes32 hashMessage);
  14.  
  15. function Greeter(string _greeting) public // The constructor. It accepts a string input and saves it to the contract's "greeting" variable.
  16. {
  17. creator = msg.sender;
  18. greeting = _greeting;
  19. }
  20.  
  21. function mortal() {
  22. creator = msg.sender;
  23. }
  24.  
  25. function getCreator() constant public returns (address) {
  26. return creator;
  27. }
  28.  
  29. // Hey, go provide me the value of the message from the db with this contract's greeting hash.
  30. function fireOnChainEvent() public {
  31. onChainStuff(hashMessage);
  32. }
  33.  
  34. // get the value back from the DB, and returns it to the user.
  35. function greet(string message) constant public returns (string)
  36. {
  37. // run intergrity check here.
  38. if(keccak256(message) == hashMessage) {
  39. return message;
  40. } else {
  41. return "ALERT! DATA HAS BEEN CORRUPTED";
  42. }
  43.  
  44. }
  45.  
  46.  
  47. function getBlockNumber() constant public returns (uint) // this doesn't have anything to do with the act of greeting
  48. { // just demonstrating return of some global variable
  49. return block.number;
  50. }
  51.  
  52. function setGreeting(string _newgreeting) public
  53. {
  54. greeting = _newgreeting;
  55. }
  56.  
  57. function startOffChain(string _newgreeting) public {
  58. hashMessage = keccak256(_newgreeting);
  59. offChainStuff(hashMessage, _newgreeting);
  60. }
  61.  
  62. /**********
  63. Standard kill() function to recover funds
  64. **********/
  65.  
  66. function kill() public
  67. {
  68. if (msg.sender == creator) // only allow this action if the account sending the signal is the creator
  69. suicide(creator); // kills this contract and sends remaining funds back to creator
  70. }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement