2018-08-21 14:53:17 +02:00
|
|
|
const logger = require('winston');
|
2018-11-09 15:49:03 +01:00
|
|
|
const db = require('server/models');
|
|
|
|
const { abandonClaim } = require('server/lbrynet');
|
2018-08-21 14:53:17 +02:00
|
|
|
const deleteFile = require('../publish/deleteFile.js');
|
|
|
|
const authenticateUser = require('../publish/authentication.js');
|
|
|
|
|
|
|
|
/*
|
|
|
|
route to abandon a claim through the daemon
|
|
|
|
*/
|
|
|
|
|
|
|
|
const claimAbandon = async (req, res) => {
|
2019-05-30 20:57:47 +02:00
|
|
|
const { outpoint } = req.body;
|
|
|
|
const { user } = req;
|
2018-08-21 14:53:17 +02:00
|
|
|
try {
|
|
|
|
const [channel, claim] = await Promise.all([
|
|
|
|
authenticateUser(user.channelName, null, null, user),
|
2019-05-30 20:57:47 +02:00
|
|
|
db.Claim.findOne({ where: { outpoint } }),
|
2018-08-21 14:53:17 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
if (!claim) throw new Error('That channel does not exist');
|
2019-05-30 20:57:47 +02:00
|
|
|
if (!channel.channelName) throw new Error("You don't own this channel");
|
2018-08-21 14:53:17 +02:00
|
|
|
|
2019-05-30 20:57:47 +02:00
|
|
|
await abandonClaim({ outpoint });
|
|
|
|
const file = await db.File.findOne({ where: { outpoint } });
|
2018-08-21 14:53:17 +02:00
|
|
|
await Promise.all([
|
|
|
|
deleteFile(file.filePath),
|
2019-05-30 20:57:47 +02:00
|
|
|
db.File.destroy({ where: { outpoint } }),
|
|
|
|
db.Claim.destroy({ where: { outpoint } }),
|
2018-08-21 14:53:17 +02:00
|
|
|
]);
|
2019-05-30 20:57:47 +02:00
|
|
|
logger.debug(`Claim abandoned: ${outpoint}`);
|
2018-08-21 14:53:17 +02:00
|
|
|
res.status(200).json({
|
|
|
|
success: true,
|
2019-05-30 20:57:47 +02:00
|
|
|
message: `Claim with outpoint ${outpoint} abandonded`,
|
2018-08-21 14:53:17 +02:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
logger.error('abandon claim error:', error);
|
|
|
|
res.status(400).json({
|
|
|
|
success: false,
|
|
|
|
message: error.message,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = claimAbandon;
|