From 84555a873020e15fa2b96973d27d7d63e5347bf6 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Fri, 9 Sep 2022 10:39:27 -0400 Subject: [PATCH] feat: add waitForAllTransactionsToConfirm method --- src/datalayer/persistance.js | 3 +++ src/datalayer/wallet.js | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/datalayer/persistance.js b/src/datalayer/persistance.js index 4c4227d3..900149c4 100644 --- a/src/datalayer/persistance.js +++ b/src/datalayer/persistance.js @@ -8,6 +8,7 @@ import { getConfig } from '../utils/config-loader'; import { decodeHex } from '../utils/datalayer-utils'; import fullNode from './fullNode'; import { publicIpv4 } from '../utils/ip-tools'; +import { waitForAllTransactionsToConfirm } from './wallet'; // Generally I dont think this should be put here, // but because of time, will add it and thinkof a way to refactor @@ -279,6 +280,8 @@ const subscribeToStoreOnDataLayer = async (storeId) => { console.trace(storeId); const chiaConfig = fullNode.getChiaConfig(); + + await waitForAllTransactionsToConfirm(); await addMirror( storeId, `http://${await publicIpv4()}:${chiaConfig.data_layer.host_port}`, diff --git a/src/datalayer/wallet.js b/src/datalayer/wallet.js index c9920878..4bdf2c33 100644 --- a/src/datalayer/wallet.js +++ b/src/datalayer/wallet.js @@ -93,6 +93,15 @@ const getWalletBalance = async () => { } }; +const waitForAllTransactionsToConfirm = async () => { + if (await hasUnconfirmedTransactions()) { + await new Promise((resolve) => setTimeout(resolve(), 15000)); + return waitForAllTransactionsToConfirm(); + } + + return true; +}; + const hasUnconfirmedTransactions = async () => { const options = { url: `${rpcUrl}/get_transactions`, @@ -137,4 +146,5 @@ export default { walletIsAvailable, getPublicAddress, getWalletBalance, + waitForAllTransactionsToConfirm, };