Merge pull request #1012 from lbryio/fix-abandon

fix: abandoning claims
This commit is contained in:
jessopb 2019-05-31 15:23:10 -04:00 committed by GitHub
commit 75818e47fe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 33 deletions

View file

@ -1,6 +1,6 @@
import Request from '../utils/request';
export function getLongClaimId (host, name, modifier) {
export function getLongClaimId(host, name, modifier) {
let body = {};
// create request params
if (modifier) {
@ -13,40 +13,40 @@ export function getLongClaimId (host, name, modifier) {
}
body['claimName'] = name;
const params = {
method : 'POST',
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body : JSON.stringify(body),
body: JSON.stringify(body),
};
// create url
const url = `${host}/api/claim/long-id`;
// return the request promise
return Request(url, params);
};
}
export function getShortId (host, name, claimId) {
export function getShortId(host, name, claimId) {
const url = `${host}/api/claim/short-id/${claimId}/${name}`;
return Request(url);
};
}
export function getClaimData (host, name, claimId) {
export function getClaimData(host, name, claimId) {
const url = `${host}/api/claim/data/${name}/${claimId}`;
return Request(url);
};
}
export function checkClaimAvailability (claim) {
export function checkClaimAvailability(claim) {
const url = `/api/claim/availability/${claim}`;
return Request(url);
}
export function getClaimViews (claimId) {
export function getClaimViews(claimId) {
const url = `/api/claim/views/${claimId}`;
return Request(url);
}
export function doAbandonClaim (claimId) {
export function doAbandonClaim(outpoint) {
const params = {
method : 'POST',
body : JSON.stringify({claimId}),
method: 'POST',
body: JSON.stringify({ outpoint }),
headers: new Headers({
'Content-Type': 'application/json',
}),

View file

@ -5,17 +5,19 @@ import { updatePublishStatus, clearFile } from '../actions/publish';
import { removeAsset } from '../actions/show';
import { doAbandonClaim } from '../api/assetApi';
function * abandonClaim (action) {
function* abandonClaim(action) {
const { claimData, history } = action.data;
const { claimId } = claimData;
const { outpoint } = claimData;
const confirm = window.confirm('Are you sure you want to abandon this claim? This action cannot be undone.');
const confirm = window.confirm(
'Are you sure you want to abandon this claim? This action cannot be undone.'
);
if (!confirm) return;
yield put(updatePublishStatus(publishStates.ABANDONING, 'Your claim is being abandoned...'));
try {
yield call(doAbandonClaim, claimId);
yield call(doAbandonClaim, outpoint);
} catch (error) {
return console.log('abandon error:', error.message);
}
@ -25,6 +27,6 @@ function * abandonClaim (action) {
return history.push('/');
}
export function * watchAbandonClaim () {
export function* watchAbandonClaim() {
yield takeLatest(actions.ABANDON_CLAIM, abandonClaim);
};
}

View file

@ -9,28 +9,28 @@ const authenticateUser = require('../publish/authentication.js');
*/
const claimAbandon = async (req, res) => {
const {claimId} = req.body;
const {user} = req;
const { outpoint } = req.body;
const { user } = req;
try {
const [channel, claim] = await Promise.all([
authenticateUser(user.channelName, null, null, user),
db.Claim.findOne({where: {claimId}}),
db.Claim.findOne({ where: { outpoint } }),
]);
if (!claim) throw new Error('That channel does not exist');
if (!channel.channelName) throw new Error('You don\'t own this channel');
if (!channel.channelName) throw new Error("You don't own this channel");
await abandonClaim({claimId});
const file = await db.File.findOne({where: {claimId}});
await abandonClaim({ outpoint });
const file = await db.File.findOne({ where: { outpoint } });
await Promise.all([
deleteFile(file.filePath),
db.File.destroy({where: {claimId}}),
db.Claim.destroy({where: {claimId}}),
db.File.destroy({ where: { outpoint } }),
db.Claim.destroy({ where: { outpoint } }),
]);
logger.debug(`Claim abandoned: ${claimId}`);
logger.debug(`Claim abandoned: ${outpoint}`);
res.status(200).json({
success: true,
message: `Claim with id ${claimId} abandonded`,
message: `Claim with outpoint ${outpoint} abandonded`,
});
} catch (error) {
logger.error('abandon claim error:', error);

View file

@ -73,13 +73,14 @@ module.exports = {
});
});
},
async abandonClaim({ claimId }) {
logger.debug(`lbryApi >> Abandon claim "${claimId}"`);
async abandonClaim({ outpoint }) {
logger.debug(`lbryApi >> Abandon claim "${outpoint}"`);
const gaStartTime = Date.now();
const [txid, nout] = outpoint.split(':');
try {
const abandon = await axios.post(lbrynetUri, {
method: 'claim_abandon',
params: { claim_id: claimId },
method: 'stream_abandon',
params: { txid: txid, nout: Number(nout) },
});
sendGATimingEvent('lbrynet', 'abandonClaim', 'ABANDON_CLAIM', gaStartTime, Date.now());
return abandon.data;