diff --git a/.luacheckrc b/.luacheckrc index 2f0cde9..f48231c 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -16,7 +16,6 @@ globals = { "Description", "Keywords", "Denomination", - "SourceCodeTxId", "Initialized" } max_line_length = 185 diff --git a/CHANGELOG.md b/CHANGELOG.md index d9ae8cc..4b5373b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Refactored handlers to use a util that codifies responses on calls. - Added documentation with luadoc types for improved linting. - Records are now returned as an alphabetically sorted array of [{name, transactionId, ttlSeconds}] with the '@' record being the first. +- Removed `Evolve` handler and SourceCodeTxId from state and state responses. ### Fixed diff --git a/README.md b/README.md index eb5a209..ccc45ac 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,6 @@ Retrieves the entire state of the ANT, which includes: - Denomination - TotalSupply - Initialized -- Source-Code-TX-ID | Tag Name | Type | Pattern | Required | Description | | -------- | ------ | ------- | -------- | --------------------------------- | diff --git a/src/common/main.lua b/src/common/main.lua index 07ccae4..6f20751 100644 --- a/src/common/main.lua +++ b/src/common/main.lua @@ -6,7 +6,6 @@ function ant.init() local json = require(".common.json") local utils = require(".common.utils") local notices = require(".common.notices") - local camel = utils.camelCase local createActionHandler = utils.createActionHandler -- spec modules @@ -49,9 +48,6 @@ function ant.init() ---@alias Initialized boolean ---@description Whether the ANT has been initialized with the Initialized = Initialized or false - ---@alias SourceCodeTxId string - ---@description The Arweave ID of the lua source the ANT currently uses. INSERT placeholder used by build script to inject the appropriate ID - SourceCodeTxId = SourceCodeTxId or "__INSERT_SOURCE_CODE_ID__" ---@alias AntRegistryId string ---@description The Arweave ID of the ANT Registry contract that this ANT is registered with AntRegistryId = AntRegistryId or ao.env.Process.Tags["ANT-Registry-Id"] or nil @@ -141,7 +137,6 @@ function ant.init() Denomination = tostring(Denomination), Owner = Owner, Handlers = utils.getHandlerNames(Handlers), - ["Source-Code-TX-ID"] = SourceCodeTxId, } ao.send({ Target = msg.From, @@ -274,41 +269,6 @@ function ant.init() ["Process-Id"] = antProcessIdToReassign, }) end) - - Handlers.prepend( - camel(ActionMap.Evolve), - Handlers.utils.continue(utils.hasMatchingTag("Action", "Eval")), - function(msg) - local srcCodeTxId = msg.Tags["Source-Code-TX-ID"] - if not srcCodeTxId then - return - end - - if Owner ~= msg.From then - ao.send({ - Target = msg.From, - Action = "Invalid-Evolve-Notice", - Error = "Evolve-Error", - ["Message-Id"] = msg.Id, - Data = "Only the Owner [" .. Owner or "no owner set" .. "] can call Evolve", - }) - return - end - - local srcCodeTxIdStatus = pcall(utils.validateArweaveId, srcCodeTxId) - if not srcCodeTxIdStatus then - ao.send({ - Target = msg.From, - Action = "Invalid-Evolve-Notice", - Error = "Evolve-Error", - ["Message-Id"] = msg.Id, - Data = "Source-Code-TX-ID is required", - }) - return - end - SourceCodeTxId = srcCodeTxId - end - ) end return ant diff --git a/src/common/notices.lua b/src/common/notices.lua index 189a39d..0c6d809 100644 --- a/src/common/notices.lua +++ b/src/common/notices.lua @@ -70,7 +70,6 @@ function notices.notifyState(msg, target) Denomination = Denomination, TotalSupply = TotalSupply, Initialized = Initialized, - ["Source-Code-TX-ID"] = SourceCodeTxId, } ao.send(notices.addForwardedTags(msg, { diff --git a/src/common/types.lua b/src/common/types.lua index 7dd6845..2f18997 100644 --- a/src/common/types.lua +++ b/src/common/types.lua @@ -44,6 +44,5 @@ --- Denomination: integer, --- TotalSupply: integer, --- Initialized: boolean, ---- ["Source-Code-TX-ID"|SourceCodeTxId]: string, --- Records: table, ---} diff --git a/src/common/utils.lua b/src/common/utils.lua index 7bc1211..7974c80 100644 --- a/src/common/utils.lua +++ b/src/common/utils.lua @@ -148,7 +148,6 @@ function utils.getState() Denomination = Denomination, TotalSupply = TotalSupply, Initialized = Initialized, - ["Source-Code-TX-ID"] = SourceCodeTxId, } end @@ -157,6 +156,7 @@ end --- @return string[] function utils.getHandlerNames(handlers) local names = {} + for _, handler in ipairs(handlers.list) do table.insert(names, handler.name) end diff --git a/test/evolve.test.mjs b/test/evolve.test.mjs index e97d558..e270180 100644 --- a/test/evolve.test.mjs +++ b/test/evolve.test.mjs @@ -23,12 +23,8 @@ describe('aos Evolve', async () => { } it('should evolve the ant and retain eval ability', async () => { - const srcCodeTxIdStub = 'new-source-code-tx-id-'.padEnd(43, '-1'); const evolveResult = await handle({ - Tags: [ - { name: 'Action', value: 'Eval' }, - { name: 'Source-Code-TX-ID', value: srcCodeTxIdStub }, - ], + Tags: [{ name: 'Action', value: 'Eval' }], Data: BUNDLED_AOS_ANT_LUA, }); @@ -40,7 +36,6 @@ describe('aos Evolve', async () => { ); const state = JSON.parse(result.Messages[0].Data); assert(state); - assert(state['Source-Code-TX-ID'] === srcCodeTxIdStub); const evalResult = await handle( { @@ -49,9 +44,8 @@ describe('aos Evolve', async () => { }, evolveResult.Memory, ); - assert(evalResult.Output.data.output); - assert(evalResult.Output.data.output.includes('evolve')); + assert(evalResult.Output.data.output.includes('info')); }); it('should not evolve the ant', async () => { @@ -60,7 +54,7 @@ describe('aos Evolve', async () => { { name: 'Action', value: 'Eval' }, // omit src code id ], - Data: BUNDLED_AOS_ANT_LUA, + Data: "Foo = 'bar'", }); const result = await handle( @@ -72,17 +66,27 @@ describe('aos Evolve', async () => { const state = JSON.parse(result.Messages[0].Data); assert(state); - assert(state['Source-Code-TX-ID'] === '__INSERT_SOURCE_CODE_ID__'); + + const fooRes = await handle( + { + Tags: [ + { + name: 'Action', + value: 'Eval', + }, + ], + Data: 'print(Foo)', + }, + result.Memory, + ); + + assert(!fooRes.Output.output?.includes('bar')); }); it('should not evolve the ant with correct tags called by a non owner', async () => { - const srcCodeTxIdStub = ''.padEnd(43, '123-test'); const evolveResult = await handle({ - Tags: [ - { name: 'Action', value: 'Eval' }, - { name: 'Source-Code-TX-ID', value: srcCodeTxIdStub }, - ], - Data: BUNDLED_AOS_ANT_LUA, + Tags: [{ name: 'Action', value: 'Eval' }], + Data: "Foo = 'bar'", Owner: 'im-not-the-owner-'.padEnd(43, 'a'), }); @@ -95,6 +99,20 @@ describe('aos Evolve', async () => { const state = JSON.parse(result.Messages[0].Data); assert(state); - assert(state['Source-Code-TX-ID'] === '__INSERT_SOURCE_CODE_ID__'); + + const fooRes = await handle( + { + Tags: [ + { + name: 'Action', + value: 'Eval', + }, + ], + Data: 'print(Foo)', + }, + result.Memory, + ); + + assert(!fooRes.Output?.output?.includes('bar')); }); }); diff --git a/test/info.test.mjs b/test/info.test.mjs index d41cc8c..42b9eb7 100644 --- a/test/info.test.mjs +++ b/test/info.test.mjs @@ -37,9 +37,8 @@ describe('aos Info', async () => { assert(processInfo.Owner); assert(processInfo.Handlers); assert.deepStrictEqual(processInfo.Handlers, [ - 'evolve', '_eval', - '_default', + '_default', 'transfer', 'balance', 'balances', diff --git a/tools/publish-aos.mjs b/tools/publish-aos.mjs index d025f4b..a10796c 100644 --- a/tools/publish-aos.mjs +++ b/tools/publish-aos.mjs @@ -8,8 +8,6 @@ import version from '../version.mjs'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); -const srcCodeTxIdPlaceholder = '__INSERT_SOURCE_CODE_ID__'; - const bundledLua = fs.readFileSync( path.join(__dirname, '../dist/aos-bundled.lua'), 'utf-8', @@ -17,12 +15,15 @@ const bundledLua = fs.readFileSync( const dryRun = process.argv.includes('--dry-run') || process.env.DRY_RUN === 'true'; + const walletPath = process.argv.includes('--wallet-file') ? process.argv[process.argv.indexOf('--wallet-file') + 1] : process.env.WALLET_PATH || path.join(__dirname, 'key.json'); + const jwk = process.env.WALLET ? JSON.parse(process.env.WALLET) : JSON.parse(fs.readFileSync(walletPath, 'utf-8')); + const signer = new ArweaveSigner(jwk); const turbo = TurboFactory.authenticated({ signer }); const publishingTags = Object.entries({ @@ -36,38 +37,18 @@ const publishingTags = Object.entries({ .filter(([_, value]) => value !== undefined) .map(([name, value]) => ({ name, value })); -/** - * NOTE: with the current use of SOURCE-CODE-TX-ID, we have to publish the generate the source code twice - * to get the tx id into the bundled file. In the future, we should move to using incremental - * bundle versions to avoid this issue. - */ -const data1 = createData(bundledLua, signer, { +const data = createData(bundledLua, signer, { tags: publishingTags, }); -await data1.sign(signer); - -console.log('Generated source code data item with id: ' + data1.id); -// replace placeholder with actual tx id -const bundledLuaWithTxId = bundledLua.replace(srcCodeTxIdPlaceholder, data1.id); - -const data2 = createData(bundledLuaWithTxId, signer, { - tags: [...publishingTags, { name: 'Original-Tx-Id', value: data1.id }], -}); -await data2.sign(signer); +await data.sign(signer); -console.log('Generated bundled data item with id: ' + data2.id); +console.log('Generated source code data item with id: ' + data.id); if (!dryRun) { console.log('Publishing ANT Source code to Arweave...'); - await Promise.all([ - turbo.uploadSignedDataItem({ - dataItemSizeFactory: () => data1.getRaw().byteLength, - dataItemStreamFactory: () => data1.getRaw(), - }), - turbo.uploadSignedDataItem({ - dataItemSizeFactory: () => data2.getRaw().byteLength, - dataItemStreamFactory: () => data2.getRaw(), - }), - ]); + await turbo.uploadSignedDataItem({ + dataItemSizeFactory: () => data.getRaw().byteLength, + dataItemStreamFactory: () => data.getRaw(), + }); } -console.log('Tagged source code tx id: ' + data1.id); +console.log('Tagged source code tx id: ' + data.id);