From 2451245855e168d28bcac92c04b7189b337deccc Mon Sep 17 00:00:00 2001 From: Nic Dorman Date: Wed, 13 May 2026 14:48:25 +0000 Subject: [PATCH] fix(antd-lua): add missing discover module to rockspec; fix example cost-table concatenation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The rockspec listed only 5 of the 6 .lua modules — antd.discover was missing — so after luarocks make, require("antd") failed: module antd.discover not found: no file .../antd/discover.lua Add the missing entry. Also fix three examples that tried to concatenate a Lua table (the cost estimate) directly to a string — same shape as #66 (PHP) and #67 (Elixir). 02-data.lua is reworked to match the Python/PHP/Elixir shape (estimate- then-store, round-trip assertion, OK marker); 04-files.lua and 05-graph.lua get single-line fixes. Closes #68 --- antd-lua/antd-scm-1.rockspec | 1 + antd-lua/examples/02-data.lua | 42 +++++++++++++++++++--------------- antd-lua/examples/04-files.lua | 2 +- antd-lua/examples/05-graph.lua | 2 +- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/antd-lua/antd-scm-1.rockspec b/antd-lua/antd-scm-1.rockspec index a80ca95..3ab72c5 100644 --- a/antd-lua/antd-scm-1.rockspec +++ b/antd-lua/antd-scm-1.rockspec @@ -27,5 +27,6 @@ build = { ["antd.models"] = "src/antd/models.lua", ["antd.errors"] = "src/antd/errors.lua", ["antd.base64"] = "src/antd/base64.lua", + ["antd.discover"] = "src/antd/discover.lua", }, } diff --git a/antd-lua/examples/02-data.lua b/antd-lua/examples/02-data.lua index d97fd66..9e5212e 100644 --- a/antd-lua/examples/02-data.lua +++ b/antd-lua/examples/02-data.lua @@ -1,34 +1,40 @@ ---- Example: Store and retrieve public data. +--- Example 02: Store and retrieve public data, with cost estimation. +-- +-- Prerequisite: antd daemon running on local testnet. local antd = require("antd") local client = antd.new_client() --- Store public data -local data = "Hello, Autonomi!" -local result, err = client:data_put_public(data) -if err then - print("Put error: " .. err.message) +local payload = "Hello, Autonomi!" + +-- Estimate cost before storing +local est, err1 = client:data_cost(payload) +if err1 then + print("Cost error: " .. err1.message) os.exit(1) end +print(string.format( + "Estimate: %d bytes in %d chunks, storage %s atto, gas %s wei, mode %s", + est.file_size, est.chunk_count, est.cost, est.estimated_gas_cost_wei, est.payment_mode +)) -print("Stored at: " .. result.address) -print("Cost: " .. result.cost .. " atto") - --- Retrieve it back -local retrieved, err2 = client:data_get_public(result.address) +-- Store public data +local result, err2 = client:data_put_public(payload) if err2 then - print("Get error: " .. err2.message) + print("Put error: " .. err2.message) os.exit(1) end +print("Stored at address: " .. result.address) +print("Actual cost: " .. result.cost .. " atto tokens") -print("Retrieved: " .. retrieved) - --- Estimate cost before storing -local cost, err3 = client:data_cost("Some data to estimate") +-- Retrieve it back +local retrieved, err3 = client:data_get_public(result.address) if err3 then - print("Cost error: " .. err3.message) + print("Get error: " .. err3.message) os.exit(1) end +print("Retrieved: " .. retrieved) -print("Estimated cost: " .. cost .. " atto") +assert(retrieved == payload, "Round-trip mismatch!") +print("Public data round-trip OK!") diff --git a/antd-lua/examples/04-files.lua b/antd-lua/examples/04-files.lua index 7e7e01f..8f3908d 100644 --- a/antd-lua/examples/04-files.lua +++ b/antd-lua/examples/04-files.lua @@ -40,4 +40,4 @@ if err5 then os.exit(1) end -print("Estimated upload cost: " .. cost .. " atto") +print(string.format("Estimated upload cost: %s atto (%d chunks)", cost.cost, cost.chunk_count)) diff --git a/antd-lua/examples/05-graph.lua b/antd-lua/examples/05-graph.lua index 8f1dbd5..210e371 100644 --- a/antd-lua/examples/05-graph.lua +++ b/antd-lua/examples/05-graph.lua @@ -47,4 +47,4 @@ if err4 then os.exit(1) end -print("Estimated cost: " .. cost .. " atto") +print(string.format("Estimated cost: %s atto (%d chunks)", cost.cost, cost.chunk_count))