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)")