/ test / contracts / 05_greeter.aes
05_greeter.aes
 1  /* https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/05_greeter.sol
 2  
 3     /*
 4  	The following is an extremely basic example of a solidity contract.
 5  	It takes a string upon creation and then repeats it when greet() is called.
 6     */
 7  
 8    contract Greeter         // The contract definition. A constructor of the same name will be automatically called on contract creation.
 9    {
10      address creator;     // At first, an empty "address"-type variable of the name "creator". Will be set in the constructor.
11      string greeting;     // At first, an empty "string"-type variable of the name "greeting". Will be set in constructor and can be changed.
12  
13      function Greeter(string _greeting) public   // The constructor. It accepts a string input and saves it to the contract's "greeting" variable.
14      {
15          creator = msg.sender
16          greeting = _greeting
17      }
18  
19      function greet() constant returns (string)
20      {
21          return greeting
22      }
23  
24      function getBlockNumber() constant returns (uint) // this doesn't have anything to do with the act of greeting
25      {													// just demonstrating return of some global variable
26          return block.number
27      }
28  
29      function setGreeting(string _newgreeting)
30      {
31          greeting = _newgreeting
32      }
33  
34       /**********
35       Standard kill() function to recover funds
36       **********/
37  
38      function kill()
39      {
40          if (msg.sender == creator)  // only allow this action if the account sending the signal is the creator
41              suicide(creator);       // kills this contract and sends remaining funds back to creator
42      }
43  
44    }
45  
46  */
47  
48  contract Greeter =
49  
50  
51       /* The creator of the contract will automatically
52         be set in creator() by the transaction creating the contract. */
53      entrypoint blockheight : () => uint
54      record transaction = { tx : string }
55      record state = { greeting: string }
56      record retval = { state: state,
57                      transactions: list(transaction)}
58  
59      let state = { greeting = "Hello" }
60  
61      let setGreeting =
62          (greeting: string) =>
63              state{ greeting = greeting }
64  
65  
66  
67      /* this doesn't have anything to do with the act of greeting
68         just demonstrating return of some global variable */
69      entrypoint getBlockNumber() = blockheight()
70  
71      /* There is no suicide entrypointallity in Sophia */
72      entrypoint kill() =
73        if ((caller() == creator()) /* only allow this action if the account sending the signal is the creator */
74            && (balance() > 0)) /* only creata a transaction if there is something to send */
75            state{ transactions = [spend_tx(creator(), balance())] }
76        else state
77