diff --git a/contract/src/main.lua b/contract/src/main.lua index ee410e0b..932bc0ce 100644 --- a/contract/src/main.lua +++ b/contract/src/main.lua @@ -526,4 +526,17 @@ Handlers.add('addGateway', utils.hasMatchingTag("Action", 'AddGateway'), functio end end) +Handlers.add('addRecord', utils.hasMatchingTag("Action", 'AddRecord'), function(msg) + if(msg.From ~= Owner) then + ao.send({ Target = msg.From, Data = "Unauthorized" }) + return + end + local status, result = pcall(arns.addRecord, msg.Tags.Name, json.decode(msg.Data)) + if status then + ao.send({ Target = msg.From, Data = json.encode(result) }) + else + ao.send({ Target = msg.From, Data = json.encode(result) }) + end +end) + return process diff --git a/migration/migrate-gateways.ts b/migration/migrate-gateways.ts index 83e3b170..0c833919 100644 --- a/migration/migrate-gateways.ts +++ b/migration/migrate-gateways.ts @@ -25,7 +25,6 @@ const main = async () => { }); const currentBlock = await arweave.blocks.getCurrent(); const millisecondsPerBlock = 1000 * 2 * 60; // two minutes - for (const [address, gateway] of Object.entries(gateways)) { const { message, result } = await connect(jwk) const startTimestamp = await arweave.blocks.getByHeight(gateway.start).then(block => block.timestamp) @@ -42,19 +41,18 @@ const main = async () => { observerAddress: gateway.observerWallet, operatorStake: gateway.operatorStake, settings: gateway.settings, - // TODO: fetch the block height of the gateway block height startTimestamp: startTimestamp, status: gateway.status, stats: { - ...gateway.stats, - // give them the max amount of passed - "passedConsecutiveEpochs": gateway.stats.passedEpochCount, + passedEpochCount: 0, + submittedObservationEpochCount: 0, + prescribedEpochCount: 0, + failedConsecutiveEpochs: 0, + passedConsecutiveEpochs: 0, }, - // TODO: fetch the block height of the gateway block height endTimestamp: endTimestamp, delegates: gateway.delegates, vaults: gateway.vaults, - }), signer: createDataItemSigner(jwk), }); diff --git a/migration/migrate-records.ts b/migration/migrate-records.ts new file mode 100644 index 00000000..866fe00d --- /dev/null +++ b/migration/migrate-records.ts @@ -0,0 +1,72 @@ +import { + createDataItemSigner, + connect, +} from "@permaweb/aoconnect"; +import { ArIO } from "@ar.io/sdk"; +import Arweave from 'arweave' + +import fs from 'fs' +import path from 'path' + +const processId = 'GaQrvEMKBpkjofgnBi_B3IgIDmY_XYelVLB6GcRGrHc' +const dirname = new URL(import.meta.url).pathname +const jwk = JSON.parse(fs.readFileSync(path.join(dirname, '../wallet.json')).toString()) +// const scheduler = '_GQ33BkPtZrqxA84vM8Zk-N2aO0toNNu_C-l-rawrBA' // tom's scheduler +const main = async () => { + // fetch gateways from contract + const devnetContract = ArIO.init({ + contractTxId: '_NctcA2sRy1-J4OmIQZbYFPM17piNcbdBPH2ncX2RL8' + }) + const records = await devnetContract.getArNSRecords(); + const arweave = Arweave.init({ + host: 'arweave.net', + port: 443, + protocol: 'https', + }); + // const uniqueSetOfContractTxIds = new Set(Object.values(records).map(record => record.contractTxId)) + // const mapOfContractTxIdToAntTxId: Record = {} + // spawn ANT using ANT module (or inject source code) for each contract + // for (const contractTxId of uniqueSetOfContractTxIds) { + // const processId = await spawn({ + // // The Arweave TXID of the ao Module + // module: '', // TODO: replace with the actual module tx id + // scheduler: scheduler, + // tags: [ + // { name: "Memory-Limit", value: "500-mb" }, + // { name: "Compute-Limit", value: "9000000000000" }, + // { name: "ContractTxId", value: contractTxId} + // ], + // // A signer function containing your wallet + // signer: createDataItemSigner(jwk), + // }); + // mapOfContractTxIdToAntTxId[contractTxId] = processId + // } + const currentBlock = await arweave.blocks.getCurrent(); + for (const [name, record] of Object.entries(records)) { + const { message, result } = await connect(jwk) + const messageTxId = await message({ + process: processId, + tags: [ + { name: 'ProcessId', value: processId}, + { name: 'Action', value: 'AddRecord' }, + { name: 'Name', value: name}, + ], + data: JSON.stringify({ + type: 'lease', + endTimestamp: currentBlock.timestamp * (1000 * 60 * 60 * 24 * 365 * 2), // 2 years + contractTxId: record.contractTxId, + undernameLimit: record.undernames, + purchasePrice: record.purchasePrice, + }), + signer: createDataItemSigner(jwk), + }); + console.log('Sent data to process', messageTxId) + const res = await result({ + message: messageTxId, + process: processId + }) + console.log('Result:', res) + } +} + +main()