From 4e52d54e52cc4d889871fde032537c2261d14184 Mon Sep 17 00:00:00 2001 From: MayDaReal Date: Sun, 2 Feb 2025 14:14:44 +0100 Subject: [PATCH 1/3] Improve how to manage the initial website hosting transaction on transaction chain already used to something else --- commands/deploy.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/commands/deploy.js b/commands/deploy.js index 7fb026a..719def6 100644 --- a/commands/deploy.js +++ b/commands/deploy.js @@ -149,9 +149,13 @@ const handler = async function(argv) { // Check if website is already deployed if (refIndex !== 0) { console.log(archethic.nearestEndpoints) - isWebsiteUpdate = true; const lastRefTx = await fetchLastRefTx(refAddress, archethic); - prevRefTxContent = JSON.parse(lastRefTx.data.content); + try{ + prevRefTxContent = JSON.parse(lastRefTx.data.content); + isWebsiteUpdate = true; + } catch (e){ + console.warn('No existing transaction found on refAddress for hosting the website. This will be considered as the initial hosting transaction.'); + } } // Convert directory structure into array of file content From d3ae042e591cb2ed9c1f0425d70a2a659dc1ce46 Mon Sep 17 00:00:00 2001 From: MayDaReal Date: Sun, 23 Feb 2025 18:56:49 +0100 Subject: [PATCH 2/3] Replace function fetchLastRefTx by fetchLastHostingTx to fetch the last hosting transaction on the keychain target, if any --- commands/deploy.js | 82 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 18 deletions(-) diff --git a/commands/deploy.js b/commands/deploy.js index 719def6..8e68325 100644 --- a/commands/deploy.js +++ b/commands/deploy.js @@ -149,12 +149,12 @@ const handler = async function(argv) { // Check if website is already deployed if (refIndex !== 0) { console.log(archethic.nearestEndpoints) - const lastRefTx = await fetchLastRefTx(refAddress, archethic); - try{ - prevRefTxContent = JSON.parse(lastRefTx.data.content); + const lastHostingTx = await fetchLastHostingTx(refAddress, archethic); + if (lastHostingTx) { + prevRefTxContent = JSON.parse(lastHostingTx.data.content); isWebsiteUpdate = true; - } catch (e){ - console.warn('No existing transaction found on refAddress for hosting the website. This will be considered as the initial hosting transaction.'); + } else { + console.warn('No existing hosting transaction found. This will be considered as the initial hosting transaction.'); } } @@ -317,8 +317,7 @@ async function sendTransactions(transactions, index, endpoint) { }) } - -async function fetchLastRefTx(txnAddress, archethic) { +async function fetchLastHostingTx(txnAddress, archethic) { if (typeof txnAddress !== "string" && !(txnAddress instanceof Uint8Array)) { throw "'address' must be a string or Uint8Array"; } @@ -333,23 +332,70 @@ async function fetchLastRefTx(txnAddress, archethic) { txnAddress = uint8ArrayToHex(txnAddress); } - const query =` + // Requête pour obtenir la dernière transaction + const lastTxQuery = ` query { lastTransaction( address: "${txnAddress}" - ){ - data{ + ) { + previousAddress + type + data { content } + } + }`; + + const lastTxResult = await archethic.network.rawGraphQLQuery(lastTxQuery); + + if (!lastTxResult.lastTransaction) { + return null; + } + + let txn = lastTxResult.lastTransaction; + let lastHostingTx = null; + + console.log(`Current transaction address: ${txnAddress}`); + console.log(`Previous transaction address: ${txn.previousAddress}`); + console.log(`Transaction type: ${txn.type}`); + + while (txn.previousAddress) { + txnAddress = txn.previousAddress; + + // Requête pour obtenir une transaction spécifique + const txQuery = ` + query { + transaction( + address: "${txnAddress}" + ) { + previousAddress + type + data { + content + } } - }` - - return archethic.network.rawGraphQLQuery(query) - .then(r => { - if (r.lastTransaction) { - return r.lastTransaction - } - }) + }`; + + const result = await archethic.network.rawGraphQLQuery(txQuery); + + if (!result || !result.transaction) { + console.log(`Transaction not found for address: ${txnAddress}`); + break; + } + + txn = result.transaction; + + console.log(`Current transaction address: ${txnAddress}`); + console.log(`Previous transaction address: ${txn.previousAddress}`); + console.log(`Transaction type: ${txn.type}`); + + if (txn.type === "hosting") { + lastHostingTx = txn; + break; + } + } + + return lastHostingTx; } async function logUpdateInfo(aeweb) { From 6688a2fb6ac2dc8e568e8b1ecb7c92b3576bde34 Mon Sep 17 00:00:00 2001 From: MayDaReal Date: Sun, 23 Feb 2025 19:22:28 +0100 Subject: [PATCH 3/3] Remove french comments --- commands/deploy.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/commands/deploy.js b/commands/deploy.js index 8e68325..d534a9e 100644 --- a/commands/deploy.js +++ b/commands/deploy.js @@ -332,7 +332,6 @@ async function fetchLastHostingTx(txnAddress, archethic) { txnAddress = uint8ArrayToHex(txnAddress); } - // Requête pour obtenir la dernière transaction const lastTxQuery = ` query { lastTransaction( @@ -362,7 +361,6 @@ async function fetchLastHostingTx(txnAddress, archethic) { while (txn.previousAddress) { txnAddress = txn.previousAddress; - // Requête pour obtenir une transaction spécifique const txQuery = ` query { transaction(