Skip to content

Commit

Permalink
✨ Add IS_CHAIN_UPGRADING block
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Jul 20, 2022
1 parent 41d5498 commit 7744263
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ config.APP_SERVER = 'likecoin-api-pulic';
config.CMC_PRO_API_KEY = '';
config.CMC_API_CACHE_S = 300;

config.IS_CHAIN_UPGRADING = false;

module.exports = config;
31 changes: 21 additions & 10 deletions src/routes/iscn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { checkFileValid, convertMulterFiles } from '../../util/api/arweave';
import { estimateARPrices, convertARPricesToLIKE, uploadFilesToArweave } from '../../util/arweave';
import { getIPFSHash, uploadFilesToIPFS } from '../../util/ipfs';

const { ARWEAVE_LIKE_TARGET_ADDRESS } = require('../../../config/config');
const { ARWEAVE_LIKE_TARGET_ADDRESS, IS_CHAIN_UPGRADING } = require('../../../config/config');

const maxSize = 100 * 1024 * 1024; // 100 MB

Expand Down Expand Up @@ -107,15 +107,6 @@ async function handleRegisterISCN(req, res, next) {
address,
accountNumber,
} = res.locals.signingInfo;
const createIscnSigningFunction = ({ sequence }) => signingClient.createISCNRecord(
address,
ISCNPayload, {
accountNumber,
sequence,
chainId: COSMOS_CHAIN_ID,
broadcast: false,
},
);

if (req.query.estimate) {
const uploadPrice = req.uploadPrice || 0;
Expand All @@ -131,6 +122,21 @@ async function handleRegisterISCN(req, res, next) {
return;
}

if (IS_CHAIN_UPGRADING) {
res.status(400).send('CHAIN_UPGRADING');
return;
}

const createIscnSigningFunction = ({ sequence }) => signingClient.createISCNRecord(
address,
ISCNPayload, {
accountNumber,
sequence,
chainId: COSMOS_CHAIN_ID,
broadcast: false,
},
);

const [iscnFee, iscnRes] = await Promise.all([
signingClient.estimateISCNTxFee(address, ISCNPayload),
sendTransactionWithSequence(address, createIscnSigningFunction),
Expand Down Expand Up @@ -282,6 +288,11 @@ router.post('/upload',
next();
return;
}
if (IS_CHAIN_UPGRADING) {
res.status(400).send('CHAIN_UPGRADING');
return;
}

const amount = new BigNumber(LIKE).shiftedBy(9).toFixed();
const signingClient = await getISCNSigningClient();
if (!res.locals.signingInfo) {
Expand Down

0 comments on commit 7744263

Please sign in to comment.