Viewable transaction log

This commit is contained in:
raymoo 2016-02-26 19:45:32 -08:00
parent 7713075aef
commit 81da10ae6c
2 changed files with 41 additions and 1 deletions

26
atm.lua
View File

@ -5,10 +5,11 @@ local exchange = ...
local atm_form = "global_exchange:atm_form"
local main_menu =[[
size[6,1]
size[6,2]
button[0,0;2,1;new_account;New Account]
button[2,0;2,1;info;Account Info]
button[4,0;2,1;wire;Wire Monies]
button[1,1;4,1;transaction_log;Transaction Log]
]]
@ -122,6 +123,25 @@ local function send_fs(p_name, receiver, amt_str)
end
local function log_fs(p_name)
local res = { "size[8,8]label[0,0;Transaction Log]button[0,7;2,1;logout;Log Out]",
"tablecolumns[text;text]",
"table[0,1;8,6;log_table;Time,Message",
}
local log = exchange:player_log(p_name)
for i, entry in ipairs(log) do
table.insert(res, ",")
table.insert(res, tostring(entry.Time))
table.insert(res, ",")
table.insert(res, entry.Message)
end
table.insert(res, "]")
return table.concat(res)
end
local trans_ids = {}
@ -160,6 +180,10 @@ local function handle_fields(player, formname, fields)
send_fs(p_name, fields.recipient, fields.amount))
end
if fields["transaction_log"] then
minetest.show_formspec(p_name, atm_form, log_fs(p_name))
end
return true
end

View File

@ -1134,6 +1134,22 @@ function ex_methods.market_summary(self)
end
-- Returns a list of log entries, sorted by time.
function ex_methods.player_log(self, p_name)
local stmt = self.stmts.transaction_log_stmt
stmt:bind_names({ p_name = p_name })
local res = {}
for row in stmt:nrows() do
table.insert(res, row)
end
stmt:reset()
return res
end
function exports.test()
local ex = exports.open_exchange("test.db")