Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions antd-lua/antd-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
42 changes: 24 additions & 18 deletions antd-lua/examples/02-data.lua
Original file line number Diff line number Diff line change
@@ -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!")
2 changes: 1 addition & 1 deletion antd-lua/examples/04-files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion antd-lua/examples/05-graph.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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))