sophia/test/contracts/environment.aes
2019-06-27 14:19:39 +02:00

70 lines
1.8 KiB
Plaintext

// Testing primitives for accessing the block chain environment
contract Interface =
function contract_address : () => address
function call_origin : () => address
function call_caller : () => address
function call_value : () => int
contract Environment =
record state = {remote : Interface}
function init(remote) = {remote = remote}
stateful function set_remote(remote) = put({remote = remote})
// -- Information about the this contract ---
// Address
function contract_address() : address = Contract.address
function nested_address(who) : address =
who.contract_address(gas = 1000)
// Balance
function contract_balance() : int = Contract.balance
// -- Information about the current call ---
// Origin
function call_origin() : address = Call.origin
function nested_origin() : address =
state.remote.call_origin()
// Caller
function call_caller() : address = Call.caller
function nested_caller() : address =
state.remote.call_caller()
// Value
function call_value() : int = Call.value
stateful function nested_value(value : int) : int =
state.remote.call_value(value = value / 2)
// Gas price
function call_gas_price() : int = Call.gas_price
// -- Information about the chain ---
// Account balances
function get_balance(acct : address) : int = Chain.balance(acct)
// Block hash
function block_hash(height : int) : option(hash) = Chain.block_hash(height)
// Coinbase
function coinbase() : address = Chain.coinbase
// Block timestamp
function timestamp() : int = Chain.timestamp
// Block height
function block_height() : int = Chain.block_height
// Difficulty
function difficulty() : int = Chain.difficulty
// Gas limit
function gas_limit() : int = Chain.gas_limit