Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hollow #109

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<link rel="stylesheet" href="/css/mithril/leaderboard.css" />
<link rel="stylesheet" href="/css/mithril/global-leaderboard.css" />
<link rel="stylesheet" href="/css/mithril/character-pick-gui.css" />
<link rel="stylesheet" href="/css/mithril/market-page.css" />
<title>Cyberpunk Beavers</title>
</head>
<!-- Google tag (gtag.js) -->
Expand All @@ -33,6 +34,10 @@
padding: 0px;
overflow: hidden;
height: 100%;

@media (max-width: 600px) {
overflow: auto;
}
}

#mithril-gui {
Expand Down Expand Up @@ -61,10 +66,9 @@
</style>

<body>
<div id="game"></div>
<div id="app"></div>
<div id="mithril-gui" class="mithril-gui-hide"></div>
<script type="module" src="/src/game/config/warp-ao.js"></script>
<script type="module" src="/src/main.js"></script>
<script type="module" src="/src/routes.js"></script>
<audio id="button-click-sound" src="/assets/audio/click.mp3"></audio>
</body>
</html>
70 changes: 70 additions & 0 deletions lua/hollow/hollow-db.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
local sqlite3 = require("lsqlite3")

function ExecuteStatement(stmt, name)
local step_result, step_err = stmt:step()
if step_result ~= sqlite3.DONE then
stmt:finalize()
error(name .. " error executing statement: " .. (step_err or "Unknown error") .. " step_result: " .. step_result)
end
end

function InsertOrder(wallet_address, timestamp, item_type, item_qty, payment)
local stmt = db:prepare([[
insert into orders(wallet_address, timestamp, item_type, item_qty, payment)
values (?, ?, ?, ?, ?);
]])
if not stmt then
error("Preparing insert order failure: " .. db:errcode() .. " " .. db:errmsg())
end
local stmtBind = stmt:bind_values(wallet_address, timestamp, item_type, item_qty, payment)
if not stmtBind then
error("Binding insert order failure: " .. db:errcode() .. " " .. db:errmsg())
end

ExecuteStatement(stmt, "Inserting order")
end

function ReadOrders(limit, offset, wallet_address)
local readOrdersResult = {}

local sql = [[
SELECT *
FROM orders
]]

local valuesToBind = {}

if wallet_address then
sql = sql .. ' WHERE wallet_address = ?'
table.insert(valuesToBind, wallet_address)
end

sql = sql .. ' ORDER BY timestamp DESC LIMIT ? OFFSET ?;'
table.insert(valuesToBind, limit)
table.insert(valuesToBind, offset)
local stmt, err_parse = db:prepare(sql)
if not stmt then
error("Error parsing SQL statement: " .. (err_parse or "Unknown error"))
end

local ok, err_bind = pcall(function ()
stmt:bind_values(table.unpack(valuesToBind))
end)
if not ok then
stmt:finalize()
error("Error binding values: " .. (err_bind or "Unknown error"))
end

local exec_ok, err_exec = pcall(function ()
for row in stmt:nrows("") do
table.insert(readOrdersResult, row)
end
end)
if not exec_ok then
stmt:finalize()
error("Error executing query: " .. (err_exec or "Unknown error"))
end

stmt:finalize()
return readOrdersResult
end
40 changes: 40 additions & 0 deletions lua/hollow/hollow-utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
local bint = require('.bint')(256)

function CheckValidAddress(address)
if not address or type(address) ~= 'string' then
return false
end

return string.match(address, '^[%w%-_]+$') ~= nil and (#address == 43 or #address == 42)
end

function CheckValidAmount(data)
return bint(data) > bint(0)
end

function Add(a,b)
return tostring(bint(a) + bint(b))
end

function Multiply(a,b)
return tostring(bint(a) * bint(b))
end

function Subtract(a,b)
return tostring(bint(a) - bint(b))
end

function HandleError(args) -- Target, TransferToken, Quantity
-- If there is a valid quantity then return the funds
if args.TransferToken and args.Quantity and CheckValidAmount(args.Quantity) then
ao.send({
Target = args.TransferToken,
Action = 'Transfer',
Tags = {
Recipient = args.Target,
Quantity = tostring(args.Quantity)
}
})
end
ao.send({ Target = args.Target, Action = args.Action, Tags = { Status = 'Error', Message = args.Message } })
end
Loading