Base functions of the KV
- kv:get()
- kv:set()
- kv:del()
- Batch
- kv:batchInit()
- b:set(), b:execute()
- kv:batchInit()
- Normalized keys
- Lists
- sorted
- Encoded values
- encoding binary data for value
- encoding json for value
- Make sure you have APM
load-blueprint apm - Use APM to install
APM.install("@permaweb/kv-base")
- Require
KV = require("@permaweb/kv-base") - Instantiate
local status, result = pcall(KV.new, plugins) local store = result - Set
local nameKey = "FancyName" store:set(nameKey, "BobbaBouey") - Get
local response = store:get(nameKey)
KV = require("@permaweb/kv-base")
plugin = require("someKvPlugin")
local status, result = pcall(KV.new, { plugin })
sudo apt install luarocks
luarocks install busted --local
export PATH=$PATH:$HOME/.luarocks/bin
cd kv/base; busted
cd kv/base; ./build.sh
cd kv/batchplugin; ./build.sh
Plugins should have a register function
function plugin.register(kv)
kv:registerPlugin("aPluginFunction", function()
return plugin.createBatch(kv)
end)
-- more
end
Instantiate myKV and use myKV:aPluginFunction()
- Run build script in selected subfolder
./build/sh - Publish
main.luafromdist/
The Asset Manager Lua package (@permaweb/asset-manager) provides a utility for managing digital assets, including adding, removing, and updating asset quantities. It uses the bint library for handling large integer arithmetic and includes utilities for validating asset data and maintaining asset balances.
- Asset Management:
- Add or remove assets.
- Maintain and update asset quantities with timestamps.
Create a new instance of the AssetManager:
local AssetManager = require('@permaweb/asset-manager')
local manager = AssetManager.new()Returns a JSON-encoded string of the current list of assets.
local assets = manager:get()
print(assets) -- Outputs JSON stringUpdates an asset's balance. This function handles both Add and Remove operations.
- Arguments:
Type(string): The type of update ("Add"or"Remove").AssetId(string): The ID of the asset to update.Timestamp(number): The timestamp of the update.
manager:update({
Type = 'Add',
AssetId = 'valid-asset-id-12345678901234567890123456789012345678901',
Timestamp = os.time()
})Registers a handler to process Add-Upload events, automatically updating the asset manager.
Handlers.add('Add-Upload', 'Add-Upload', function(msg)
manager:update({
Type = 'Add',
AssetId = msg.AssetId,
Timestamp = msg.Timestamp
})
end)local manager = AssetManager.new()
-- Add an asset
manager:update({
Type = 'Add',
AssetId = 'valid-asset-id-12345678901234567890123456789012345678901',
Timestamp = os.time()
})
-- Get the current list of assets
print(manager:get())