StarOS: contract and relay

See the overview.

From a robot

contract.call(id, function, args=None, gas=0, value=0) records a call. The robot's owner calls and pays. At most 3 a turn. A dict of args is keyword arguments, a list is positional; at most 2 KiB of JSON. gas is the step limit (0 means 100 000). value is drops sent along. The result is a contract_call or contract_failed event on the robot.

relay

relay.set(id, open) (5 a turn) and relay.get(id). This belongs to an older grid: relay and breaker devices can no longer be placed, so the module has nothing to switch.

Inside a contract

A contract is a Starlark source with its own account. It is public and never changes. It has json, math, log(message) and:

module members
wallet balance(), pay(to, amount), and the attributes caller, owner, value
state get(key, default), set, delete, keys(); 8 KiB
market best_bid, best_ask, last, buy(item, quantity, price=None, warehouse=None) returns the order id; no selling
storage contents(id), free(id) for the deployer's warehouses
ledger supply(), treasury(), contract_balance(id)
turn number, day, day_turns, hour(), is_day()
contract call(id, function, args=None, value=0) returns ok, result, error
turret fire turrets that allow it

The meter and relay modules of a contract refer to the retired grid devices.

A contract with EVERY = <turns> and def tick(): runs on that schedule, and its deployer pays the gas. Deploying costs 10 MT; gas is 200 drops per 1 000 steps. A failed call is rolled back completely, and the gas is still charged. See the cookbook for a buying contract.