diff --git a/scripts/network.js b/scripts/network.js index 6514db4b..15cf7d54 100644 --- a/scripts/network.js +++ b/scripts/network.js @@ -89,42 +89,28 @@ export class ExplorerNetwork extends Network { * @returns {Promise} the block fetched from explorer */ async getBlock(blockHeight, skipCoinstake = false) { - try { - const block = await this.safeFetchFromExplorer( - `/api/v2/block/${blockHeight}` + const block = await this.safeFetchFromExplorer( + `/api/v2/block/${blockHeight}` + ); + const newTxs = []; + // This is bad. We're making so many requests + // This is a quick fix to try to be compliant with the blockbook + // API, and not the PIVX extension. + // In the Blockbook API /block doesn't have any chain specific information + // Like hex, shield info or what not. + // We could change /getshieldblocks to /getshieldtxs? + // In addition, always skip the coinbase transaction and in case the coinstake one + // TODO: once v6.0 and shield stake is activated we might need to change this optimization + for (const tx of block.txs.slice(skipCoinstake ? 2 : 1)) { + const r = await fetch( + `${this.strUrl}/api/v2/tx-specific/${tx.txid}` ); - const newTxs = []; - // This is bad. We're making so many requests - // This is a quick fix to try to be compliant with the blockbook - // API, and not the PIVX extension. - // In the Blockbook API /block doesn't have any chain specific information - // Like hex, shield info or what not. - // We could change /getshieldblocks to /getshieldtxs? - // In addition, always skip the coinbase transaction and in case the coinstake one - // TODO: once v6.0 and shield stake is activated we might need to change this optimization - for (const tx of block.txs.slice(skipCoinstake ? 2 : 1)) { - const r = await fetch( - `${this.strUrl}/api/v2/tx-specific/${tx.txid}` - ); - if (!r.ok) throw new Error('failed'); - const newTx = await r.json(); - newTxs.push(newTx); - } - block.txs = newTxs; - return block; - } catch (e) { - // Don't display block not found errors to user - // This is a bug with blockbook, where it sends a bad - // request error or newly minted blocks - if ( - e.message.match(/block not found/i) || - e.message.match(/safe fetch/) || - e.message.match(/bad request/i) - ) { - return; - } - throw e; + if (!r.ok) throw new Error('failed'); + const newTx = await r.json(); + newTxs.push(newTx); } + block.txs = newTxs; + return block; } async getBlockCount() { diff --git a/scripts/wallet.js b/scripts/wallet.js index 85719640..9e66228d 100644 --- a/scripts/wallet.js +++ b/scripts/wallet.js @@ -827,7 +827,6 @@ export class Wallet { ) { try { block = await cNet.getBlock(blockHeight); - if (!block) return; if (block.txs) { if ( this.hasShield() && @@ -1230,7 +1229,7 @@ export class Wallet { } const txs = await db.getTxs(); for (const tx of txs) { - this.addTransaction(tx, true); + await this.addTransaction(tx, true); } } }