Skip to content

Commit

Permalink
shakedex: query finalize tx when cancelling listing (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
chikeichan authored Apr 19, 2021
1 parent 004c2d7 commit 2c2eac2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
20 changes: 14 additions & 6 deletions app/background/shakedex/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {app} from "electron";
import bdb from "bdb";
import {
auctionSchema,
finalizeLockScheme,
fulfillmentSchema,
getFinalizeFromTransferTx,
nameLockSchema,
Expand Down Expand Up @@ -189,10 +188,20 @@ export async function transferCancel(nameLock, password) {
const existing = await get(
`${listingPrefix()}/${nameLock.name}/${nameLock.transferTxHash}`,
);
const {finalizeLock} = existing;
const {
tx: finalizeTx,
coin: finalizeCoin,
} = await getFinalizeFromTransferTx(
nameLock.transferTxHash,
nameLock.name,
nodeService,
);

const cancelNameLock = await transferNameLockCancel(context, {
...finalizeLock,
publicKey: Buffer.from(finalizeLock.publicKey, 'hex'),
...nameLock,
finalizeTxHash: finalizeTx.hash,
finalizeOutputIdx: finalizeCoin.index,
publicKey: Buffer.from(nameLock.publicKey, 'hex'),
privateKey: Buffer.from(decrypt(nameLock.encryptedPrivateKey, password), 'hex'),
});
const {privateKey, ...cancelLockJSON} = cancelNameLock.toJSON(context);
Expand Down Expand Up @@ -242,11 +251,10 @@ export async function finalizeCancel(nameLock, password) {

export async function restoreOneListing(listing) {
const {valid: auctionValid} = jsonSchemaValidate(listing.auction, auctionSchema);
const {valid: finalizeValid} = jsonSchemaValidate(listing.finalizeLock, finalizeLockScheme);
const {valid: nameLockValid} = jsonSchemaValidate(listing.nameLock || {}, nameLockSchema);
const {valid: paramsValid} = jsonSchemaValidate(listing.params, paramSchema);

if (!auctionValid || !finalizeValid || !nameLockValid || !paramsValid) {
if (!auctionValid || !nameLockValid || !paramsValid) {
throw new Error('Invalid backup file schema');
}
const {nameLock} = listing;
Expand Down
3 changes: 2 additions & 1 deletion app/ducks/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,9 @@ export const launchExchangeAuction = (nameLock, overrideParams) => async (dispat

try {
const passphrase = await new Promise((resolve, reject) => dispatch(getPassphrase(resolve, reject)));
await shakedex.launchAuction(nameLock, passphrase, overrideParams);
await shakedex.launchAuction(nameLock, passphrase, overrideParams, true);
} catch (e) {
console.log(e);
dispatch({
type: LAUNCH_EXCHANGE_AUCTION_ERR,
});
Expand Down
4 changes: 3 additions & 1 deletion app/utils/shakedex.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,10 @@ export async function getFinalizeFromTransferTx(transferTxHash, name, nodeClient
finalizeOutputIdx = 0;

for (let i = 0; i < finalizeTx.outputs.length; i++) {
if (finalizeTx.outputs[i].covenant.action === 'FINALIZE') {
const covenant = finalizeTx.outputs[i].covenant;
if (covenant.action === 'FINALIZE' && covenant.items[0] === nameHash) {
finalizeOutputIdx = i;
continue;
}
}

Expand Down

0 comments on commit 2c2eac2

Please sign in to comment.