# Local fixture: no signer, provider, wallet or settlement endpoint. # Keep Raxol's local data inside this disposable project. Set inside the VM, never # exported by the launcher, so no version manager shim sees a redirected XDG. project = Path.dirname(__ENV__.file) System.put_env(%{ "XDG_DATA_HOME" => Path.join(project, ".data"), "XDG_CONFIG_HOME" => Path.join(project, ".config") }) Logger.configure(level: :warning) Application.put_env(:raxol, :startup_mode, :minimal) # No source watcher: it needs inotify-tools in a container and nothing here reloads. Application.put_env(:raxol, :code_reloader, false) {:ok, _} = Application.ensure_all_started(:raxol) defmodule ContributorDemo do use Raxol.Agent alias Raxol.Payments.{Ledger, SpendingPolicy} def init(_), do: %{receipt: nil, decision: nil} def update({:pay_contributor, amount}, state) do policy = %SpendingPolicy{per_request_max: Decimal.new(30), currency: "USDC"} case Ledger.check_request(Decimal.new(amount), policy) do :ok -> # Stand-in for the settlement boundary, with no chain transaction. receipt = %{mode: "mock settlement", amount: amount, currency: "USDC"} {%{state | decision: :allowed, receipt: receipt}, []} {:over_limit, reason} -> {%{state | decision: {:refused, reason}, receipt: nil}, []} end end end unless Process.whereis(Raxol.Headless), do: Raxol.Headless.start_link() {:ok, id} = Raxol.Headless.start(ContributorDemo, subscriptions: false) :ok = Raxol.Headless.send_message(id, {:pay_contributor, 35}) {:ok, %{decision: {:refused, :per_request}, receipt: nil}} = Raxol.Headless.get_model(id) IO.puts("35 USDC: refused by Raxol; no fixture receipt") :ok = Raxol.Headless.send_message(id, {:pay_contributor, 25}) {:ok, %{decision: :allowed, receipt: %{amount: 25, currency: "USDC"} = receipt}} = Raxol.Headless.get_model(id) IO.puts("25 USDC: allowed by Raxol; " <> Jason.encode!(receipt))