Got first token modules working, and a bunch of bugfixes throughout

This commit is contained in:
Nathan Schneider
2021-12-26 23:03:57 -07:00
parent 0c59767ef7
commit 286d131839
13 changed files with 182 additions and 19 deletions

View File

@ -148,12 +148,10 @@ function change_modules:propose_change(type, mod_text)
"Consent reached:\nAdding \""
..mod_text.."\" to org "..self.org.name)
elseif type == "remove" then
modpol.msg("Removing!")
local i = 0
for k,v in pairs(self.org.modules) do
i = i + 1
if v.name == mod_text then
modpol.msg("got it!")
self.org.modules[k] = nil
end
end

View File

@ -0,0 +1,53 @@
--- create_token
-- @module create_token
-- depends on tokenomics
local create_token = {
name = "Create a token (consent)",
slug = "create_token",
desc = "With org consent, creates an org token",
hide = false;
}
--- (Required) Data for module
-- Variables that module uses during the course of a process
-- Can be blank
create_token.data = {
}
create_token.config = {
token_name = ""
}
--- (Required): initiate function
-- @param result (optional) Callback if this module is embedded in other modules
-- @function initiate
function create_token:initiate(result)
modpol.interactions.text_query(
self.initiator,
"Token name (alpha-numeric, no spaces):",
function(input)
self.config.token_name = input
self.org:call_module(
"tokenomics",
self.initiator,
{
consent = true,
token_slug = self.config.token_name
},
function(input2)
modpol.interactions.org_dashboard(
self.initiator, self.org.name)
if result then result() end
-- call this wherever process might end:
self.org:delete_process(self.id)
end
)
modpol.interactions.org_dashboard(
self.initiator, self.org.name)
end
)
end
--- (Required) Add to module table
modpol.modules.create_token = create_token

View File

@ -0,0 +1,77 @@
--- send_token
-- @module send_token
-- depends on tokenomics
local send_token = {
name = "Send tokens",
slug = "send_token",
desc = "Send tokens to another user",
hide = false;
}
--- (Required) Data for module
-- Variables that module uses during the course of a process
-- Can be blank
send_token.data = {
}
send_token.config = {
token_name = ""
}
--- (Required): initiate function
-- @param result (optional) Callback if this module is embedded in other modules
-- @function initiate
function send_token:initiate(result)
local token_list = {}
if self.org.tokens then
for k,v in pairs(self.org.tokens) do
table.insert(token_list, k)
end
end
if token_list == {} then
modpol.interactions.message(
self.initiator,
"No tokens in org")
modpol.interactions.org_dashboard(
self.initiator, self.org.name)
self.org:delete_process(self.id)
return
else
modpol.interactions.dropdown_query(
self.initiator,
"Which token do you want to send?",
token_list,
function(input_token)
modpol.interactions.dropdown_query(
self.initiator,
"Who do you want to send to?",
modpol.util.copy_table(self.org.members),
function(input_recipient)
modpol.interactions.text_query(
self.initiator,
"How much do you want to give (a number)?",
function(input_amount)
modpol.modules.tokenomics.transfer(
self.org.id,
input_token,
self.initiator,
input_recipient,
input_amount
)
modpol.interactions.org_dashboard(
self.initiator, self.org.name)
-- close process
if result then result() end
self.org:delete_process(self.id)
end
)
end
)
end
)
end
end
--- (Required) Add to module table
modpol.modules.send_token = send_token

View File

@ -1,5 +1,6 @@
--- tokenomics
-- @module tokenomics
-- Depends on consent
local tokenomics = {
name = "Tokenomics",
@ -50,10 +51,15 @@ function tokenomics:initiate(result)
"consent",
self.initiator,
{
prompt = "Create token "..self.token_slug.."?",
prompt = "Create token "..
self.config.token_slug.."?",
votes_required = #self.org.members
},
function()
modpol.interactions.message_org(
self.initiator, self.org.id,
"Consent reached: creating token "..
self.config.token_slug)
self:create_token()
end
)
@ -65,11 +71,13 @@ end
function tokenomics:create_token()
if not self.org.tokens then self.org.tokens = {} end
self.org.tokens[slug] = self.config.token_variables
self.org.tokens[self.config.token_slug] =
self.config.token_variables
self.org:record("Created token "..self.config.token_slug,
self.slug)
modpol.interactions.message_org(
self.initiator, self.org.id,
"Token "..self.config.token_slug.." created")
-- TODO need to add to persistent storage?
"Created token "..self.config.token_slug)
if self.data.result then self.data.result() end
-- call this wherever process might end:
self.org:delete_process(self.id)
@ -135,7 +143,7 @@ end
function tokenomics.transfer(org, token, sender, recipient, amount)
local sender_balance = tokenomics.balance(org, token, sender)
local recipient_balance = tokenomics.balance(org, token, recipient)
if not sender_balance or recipient balance then
if not sender_balance or recipient_balance then
return nil, "Transfer failed, user not found"
else
sender_balance = sender_balance - amount