Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@permaweb/aos",
"version": "2.0.3",
"version": "2.0.5",
"private": true,
"repository": "https://github.com/permaweb/aos.git",
"license": "MIT",
Expand Down
14 changes: 13 additions & 1 deletion process/ao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ local ao = {
'Timestamp', 'Nonce', 'Epoch', 'Signature', 'Forwarded-By',
'Pushed-For', 'Read-Only', 'Cron', 'Block-Height', 'Reference', 'Id',
'Reply-To'
}
},
hint = ""
}

--- Checks if a key exists in a list.
Expand Down Expand Up @@ -116,6 +117,12 @@ function ao.normalize(msg)
msg[o.name] = o.value
end
end
-- capture "Hint" on every message
if msg.Hint then
ao.hint = msg.Hint
else
ao.hint = nil
end
return msg
end

Expand Down Expand Up @@ -194,6 +201,11 @@ function ao.send(msg)
}
}

if ao.hint then
table.insert(message.Tags, { name = "From-Process", value = ao.id .. "?hint=" .. ao.hint } )
else
table.insert(message.Tags, { name = "From-Process", value = ao.id })
end
-- if custom tags in root move them to tags
for k, v in pairs(msg) do
if not _includes({"Target", "Data", "Anchor", "Tags", "From"})(k) then
Expand Down
37 changes: 34 additions & 3 deletions process/test/print.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ async function init(handle) {
Id: 'AOS',
Module: 'WOOPAWOOPA',
Tags: [
{ name: 'Name', value: 'Thomas' }
]
{ name: 'Name', value: 'Thomas' },
],
Data: ''
}, env)
return Memory
}
Expand All @@ -43,15 +44,45 @@ test('multi print feature', async () => {
Id: "1234xyxfoo",
Module: "WOOPAWOOPA",
Tags: [
{ name: 'Action', value: 'Eval' }
{ name: 'Action', value: 'Eval' },
{ name: 'Hint', value: 'https://the.ao.computer'},
],
Data: `
print("one")
print("two")
Send({Target = ao.id, Action = "Hint" })
`
}
const result = await handle(start, msg, env)
assert.equal(result.Output?.data, 'one\ntwo')
assert.ok(result.Messages[0].Tags.find(t => t.name === "From-Process").value == "AOS?hint=https://the.ao.computer")
assert.ok(true)
console.log(result.Messages[0].Tags)
})

test('multi print feature - no hint', async () => {
const handle = await AoLoader(wasm, options)
const start = await init(handle)

const msg = {
Target: 'AOS',
From: 'FOOBAR',
Owner: 'FOOBAR',
['Block-Height']: "1000",
Id: "1234xyxfoo",
Module: "WOOPAWOOPA",
Tags: [
{ name: 'Action', value: 'Eval' },
],
Data: `
print("one")
print("two")
Send({Target = ao.id, Action = "Hint" })
`
}
const result = await handle(start, msg, env)
assert.equal(result.Output?.data, 'one\ntwo')
assert.ok(result.Messages[0].Tags.find(t => t.name === "From-Process").value == "AOS")
assert.ok(true)
})

Expand Down