/ test / contracts / sophia_4 / environment.aes
environment.aes
 1  
 2  // Testing primitives for accessing the block chain environment
 3  contract Interface =
 4    entrypoint contract_address : () => address
 5    entrypoint contract_creator : () => address
 6    entrypoint call_origin      : () => address
 7    entrypoint call_caller      : () => address
 8    entrypoint call_value       : () => int
 9  
10  contract Environment =
11  
12    record state = {remote : Interface}
13  
14    entrypoint init(remote) = {remote = remote}
15  
16    stateful entrypoint set_remote(remote) = put({remote = remote})
17  
18    // -- Information about the this contract ---
19  
20    // Address
21    entrypoint contract_address() : address = Contract.address
22    entrypoint nested_address(who) : address =
23      who.contract_address(gas = 10000)
24  
25    // Balance
26    entrypoint contract_balance() : int = Contract.balance
27  
28    entrypoint contract_creator() : address = Contract.creator
29    entrypoint nested_creator()   : address =
30      state.remote.contract_creator()
31  
32    // -- Information about the current call ---
33  
34    // Origin
35    entrypoint call_origin()   : address = Call.origin
36    entrypoint nested_origin() : address =
37      state.remote.call_origin()
38  
39    // Caller
40    entrypoint call_caller() : address = Call.caller
41    entrypoint nested_caller() : address =
42      state.remote.call_caller()
43  
44    // Value
45    payable entrypoint call_value() : int = Call.value
46    stateful entrypoint nested_value(value : int) : int =
47      state.remote.call_value(value = value / 2)
48  
49    // Gas price
50    entrypoint call_gas_price() : int = Call.gas_price
51  
52    // -- Information about the chain ---
53  
54    // Account balances
55    entrypoint get_balance(acct : address) : int = Chain.balance(acct)
56  
57    // Block hash
58    entrypoint block_hash(height : int) = Chain.block_hash(height)
59  
60    // Coinbase
61    entrypoint coinbase() : address = Chain.coinbase
62  
63    // Block timestamp
64    entrypoint timestamp() : int = Chain.timestamp
65  
66    // Block height
67    entrypoint block_height() : int = Chain.block_height
68  
69    // Difficulty
70    entrypoint difficulty() : int = Chain.difficulty
71  
72    // Gas limit
73    entrypoint gas_limit() : int = Chain.gas_limit
74