From 086bef086fe4561ce5f7ce4575bb62a00381b095 Mon Sep 17 00:00:00 2001 From: Nic Dorman Date: Wed, 13 May 2026 14:22:36 +0000 Subject: [PATCH] fix(antd-elixir): print cost-estimate fields in examples to avoid stringification crash The examples interpolated a whole UploadCostEstimate struct into a string, which raises Protocol.UndefinedError (String.Chars not implemented for the struct): ** (Protocol.UndefinedError) protocol String.Chars not implemented for Antd.UploadCostEstimate (a struct) 02_data.exs:19: (file) Print individual fields (matching what the Python/Rust/PHP examples do). For 02_data.exs the example is also reordered to estimate-then-store and gains a round-trip assertion + OK marker. Affected examples: - 02_data.exs (rewritten end-to-end, mirrors antd-py/antd-rust shape) - 04_files.exs (single-line interpolation fix) - 05_graph.exs (single-line interpolation fix) Closes #67 --- antd-elixir/examples/02_data.exs | 30 +++++++++++++++++++++--------- antd-elixir/examples/04_files.exs | 2 +- antd-elixir/examples/05_graph.exs | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/antd-elixir/examples/02_data.exs b/antd-elixir/examples/02_data.exs index e0bc467..08b3d6e 100644 --- a/antd-elixir/examples/02_data.exs +++ b/antd-elixir/examples/02_data.exs @@ -2,18 +2,30 @@ Mix.install([ {:antd, path: ".."} ]) -# Store and retrieve public immutable data +# Example 02: Store and retrieve public data, with cost estimation. +# +# Prerequisite: antd daemon running on local testnet. + client = Antd.Client.new() -# Store data -{:ok, result} = Antd.Client.data_put_public(client, "Hello, Autonomi!") -IO.puts("Stored at: #{result.address}") -IO.puts("Cost: #{result.cost} atto") +payload = "Hello, Autonomi!" + +# Estimate cost before storing +{:ok, est} = Antd.Client.data_cost(client, payload) +IO.puts( + "Estimate: #{est.file_size} bytes in #{est.chunk_count} chunks, " <> + "storage #{est.cost} atto, gas #{est.estimated_gas_cost_wei} wei, " <> + "mode #{est.payment_mode}" +) -# Retrieve data +# Store public data +{:ok, result} = Antd.Client.data_put_public(client, payload) +IO.puts("Stored at address: #{result.address}") +IO.puts("Actual cost: #{result.cost} atto tokens") + +# Retrieve it back {:ok, data} = Antd.Client.data_get_public(client, result.address) IO.puts("Retrieved: #{data}") -# Estimate cost before storing -{:ok, cost} = Antd.Client.data_cost(client, "Some data to estimate") -IO.puts("Estimated cost: #{cost} atto") +unless data == payload, do: raise "Round-trip mismatch!" +IO.puts("Public data round-trip OK!") diff --git a/antd-elixir/examples/04_files.exs b/antd-elixir/examples/04_files.exs index 48de831..43051cc 100644 --- a/antd-elixir/examples/04_files.exs +++ b/antd-elixir/examples/04_files.exs @@ -25,4 +25,4 @@ IO.puts("Directory downloaded to /tmp/mydir_copy") # Estimate file upload cost {:ok, cost} = Antd.Client.file_cost(client, "/tmp/example.txt", true, false) -IO.puts("Estimated upload cost: #{cost} atto") +IO.puts("Estimated upload cost: #{cost.cost} atto (#{cost.chunk_count} chunks)") diff --git a/antd-elixir/examples/05_graph.exs b/antd-elixir/examples/05_graph.exs index 9222dde..9fdc7f2 100644 --- a/antd-elixir/examples/05_graph.exs +++ b/antd-elixir/examples/05_graph.exs @@ -27,4 +27,4 @@ IO.puts("Exists: #{exists}") # Estimate cost {:ok, cost} = Antd.Client.graph_entry_cost(client, "public_key_hex") -IO.puts("Estimated graph entry cost: #{cost} atto") +IO.puts("Estimated graph entry cost: #{cost.cost} atto (#{cost.chunk_count} chunks)")