Skip to content

Commit

Permalink
Migrate NFTs to new format
Browse files Browse the repository at this point in the history
  • Loading branch information
macterra committed Oct 23, 2023
1 parent fe3f8f6 commit 3d25c36
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 deletions xidb.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,45 +336,59 @@ const repairAsset = (xid) => {
}

// Revise history to remove everything before unmints
const history = getHistory(xid); // history is in reverse order!
// const history = getHistory(xid); // history is in reverse order!

if (history) {
let lastUnmintIndex = -1;
// if (history) {
// let lastUnmintIndex = -1;

for (let i = 0; i < history.length; i++) {
if (history[i].type === 'unmint') {
lastUnmintIndex = i;
break;
}
}
// for (let i = 0; i < history.length; i++) {
// if (history[i].type === 'unmint') {
// lastUnmintIndex = i;
// break;
// }
// }

// if (lastUnmintIndex !== -1) {
// const jsonlPath = path.join(config.assets, xid, 'history.jsonl');
// fs.rmSync(jsonlPath);

// for (let i = lastUnmintIndex - 1; i >= 0; i--) {
// const recordString = JSON.stringify(history[i]);
// fs.appendFileSync(jsonlPath, recordString + '\n');
// }

// return {
// xid: xid,
// fixed: true,
// message: `removed unmints from history`,
// }
// }
// }

if (lastUnmintIndex !== -1) {
const jsonlPath = path.join(config.assets, xid, 'history.jsonl');
fs.rmSync(jsonlPath);
if (assetData.nft) {

for (let i = lastUnmintIndex - 1; i >= 0; i--) {
const recordString = JSON.stringify(history[i]);
fs.appendFileSync(jsonlPath, recordString + '\n');
let doSave = false;

for (const file of ['_asset.png', '_asset.jpg', '_creator.jpg', '_owner.jpg', '_collection.jpg']) {
const filePath = path.join(config.assets, xid, file);
if (fs.existsSync(filePath)) {
fs.rmSync(filePath);
console.log(`removed ${filePath}`);
doSave = true;
}
}

if (doSave) {
saveNft(xid);

return {
xid: xid,
fixed: true,
message: `removed unmints from history`,
message: `migrated NFT`,
}
}
}

// if (assetData.nft) {
// saveNft(xid);

// return {
// xid: xid,
// fixed: true,
// message: `saved NFT`,
// }
// }

const agentData = getAgent(assetData.asset.owner);

if (!agentData) {
Expand Down

0 comments on commit 3d25c36

Please sign in to comment.