Skip to content

Commit

Permalink
Merge pull request #1126 from Chia-Network/fix/transfer-staging-lockout
Browse files Browse the repository at this point in the history
fix: bug in which active transfers prevent transfer related actions
  • Loading branch information
TheLastCicada authored Jul 17, 2024
2 parents 2f99321 + 02024f2 commit 8b8da07
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
11 changes: 5 additions & 6 deletions src/controllers/offer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import { Meta, Staging } from '../models';

import {
assertHomeOrgExists,
assertNoPendingCommits,
assertWalletIsSynced,
assertIfReadOnlyMode,
assertStagingTableNotEmpty,
assertStagingTableIsEmpty,
assertNoActiveOfferFile,
assertActiveOfferFile,
assertNoPendingCommitsExcludingTransfers,
assertNoPendingCommits,
} from '../utils/data-assertions';

import { deserializeMaker, deserializeTaker } from '../utils/datalayer-utils';
Expand All @@ -26,7 +27,7 @@ export const generateOfferFile = async (req, res) => {
await assertStagingTableNotEmpty();
await assertHomeOrgExists();
await assertWalletIsSynced();
await assertNoPendingCommits();
await assertNoPendingCommitsExcludingTransfers();

const offerFile = await Staging.generateOfferFile();
res.json(offerFile);
Expand All @@ -46,7 +47,7 @@ export const cancelActiveOffer = async (req, res) => {
await assertStagingTableNotEmpty();
await assertHomeOrgExists();
await assertWalletIsSynced();
await assertNoPendingCommits();
await assertNoPendingCommitsExcludingTransfers();

const activeOffer = await Meta.findOne({
where: { metaKey: 'activeOfferTradeId' },
Expand Down Expand Up @@ -121,7 +122,7 @@ export const commitImportedOfferFile = async (req, res) => {
await assertStagingTableIsEmpty();
await assertHomeOrgExists();
await assertWalletIsSynced();
await assertNoPendingCommits();
await assertNoPendingCommitsExcludingTransfers();

const offerFile = await Meta.findOne({
where: { metaKey: 'activeOffer' },
Expand Down Expand Up @@ -193,8 +194,6 @@ export const getCurrentOfferInfo = async (req, res) => {
const makerChanges = deserializeMaker(offerFile.offer.maker);
const takerChanges = deserializeTaker(offerFile.offer.taker);

console.log(makerChanges);

let maker = makerChanges.filter((record) => record.table === 'project');

makerChanges.forEach((record) => {
Expand Down
6 changes: 2 additions & 4 deletions src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,17 +611,15 @@ const getSubscriptions = async () => {
const makeOffer = async (offer) => {
const url = `${CONFIG.DATALAYER_URL}/make_offer`;
const { cert, key, timeout } = getBaseOptions();
offer.fee = CONFIG.DEFAULT_FEE;

try {
const response = await superagent
.post(url)
.key(key)
.cert(cert)
.timeout(timeout)
.send({
...offer,
fee: _.get(CONFIG, 'DEFAULT_FEE', 300000000),
});
.send(offer);

const data = response.body;

Expand Down
13 changes: 13 additions & 0 deletions src/utils/data-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ export const assertNoPendingCommits = async () => {
}
};

export const assertNoPendingCommitsExcludingTransfers = async () => {
const pendingCommits = await Staging.findAll({
where: { commited: true, failedCommit: false, isTransfer: false },
raw: true,
});

if (pendingCommits.length > 0) {
throw new Error(
'You currently have changes pending on the blockchain. Please wait for them to propagate before making more changes',
);
}
};

export const assertWalletIsSynced = async () => {
if (!USE_SIMULATOR) {
if (!(await datalayer.walletIsSynced())) {
Expand Down

0 comments on commit 8b8da07

Please sign in to comment.