```async function unlist(req, res) {
try {
const transactionsToSend = [];
for (transaction of req.body.unlist_transactions) {
transactionsToSend.push(base64Decode(transaction));
}
const appId = algosdk.decodeSignedTransaction(transactionsToSend[0]).txn.appIndex ||
algosdk.decodeSignedTransaction(transactionsToSend[1]).txn.appIndex;
const nftId = algosdk.decodeSignedTransaction(transactionsToSend[1]).txn.appForeignAssets[0];
const seller = algosdk.encodeAddress(algosdk.decodeSignedTransaction(transactionsToSend[1]).txn.from.publicKey);
const offers = await getListingOffers(appId);
const removeOfferRequests = [];
for (const offer of offers) {
removeOfferRequests.push(removeOfferFromAddress(offer.buyer, appId));
}
await Promise.all(removeOfferRequests)
.catch((e) => {
console.log(e);
return res.sendStatus(500);
});
const unlistTransactions = await algodClient.sendRawTransaction(transactionsToSend).do();
await algosdk.waitForConfirmation(algodClient, unlistTransactions.txId, 10);
await pgClient.query('DELETE FROM listings WHERE app_id = $1', [appId]);
await pgClient.query('INSERT INTO activity (nft_id, date, type, seller) VALUES ($1, $2, $3, $4)',
[
nftId,
new Date().toISOString(),
'Unlist',
seller,
]);
deleteApp(appId);
return res.sendStatus(200);
} catch (e) {
console.error(e);
return res.sendStatus(500);
}
}```async function unlist(req, res) {
try {
const transactionsToSend = [];
for (transaction of req.body.unlist_transactions) {
transactionsToSend.push(base64Decode(transaction));
}
const appId = algosdk.decodeSignedTransaction(transactionsToSend[0]).txn.appIndex ||
algosdk.decodeSignedTransaction(transactionsToSend[1]).txn.appIndex;
const nftId = algosdk.decodeSignedTransaction(transactionsToSend[1]).txn.appForeignAssets[0];
const seller = algosdk.encodeAddress(algosdk.decodeSignedTransaction(transactionsToSend[1]).txn.from.publicKey);
const offers = await getListingOffers(appId);
const removeOfferRequests = [];
for (const offer of offers) {
removeOfferRequests.push(removeOfferFromAddress(offer.buyer, appId));
}
await Promise.all(removeOfferRequests)
.catch((e) => {
console.log(e);
return res.sendStatus(500);
});
const unlistTransactions = await algodClient.sendRawTransaction(transactionsToSend).do();
await algosdk.waitForConfirmation(algodClient, unlistTransactions.txId, 10);
await pgClient.query('DELETE FROM listings WHERE app_id = $1', [appId]);
await pgClient.query('INSERT INTO activity (nft_id, date, type, seller) VALUES ($1, $2, $3, $4)',
[
nftId,
new Date().toISOString(),
'Unlist',
seller,
]);
deleteApp(appId);
return res.sendStatus(200);
} catch (e) {
console.error(e);
return res.sendStatus(500);
}
}