Skip to content

Commit

Permalink
feat: add waitForAllTransactionsToConfirm method
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Sep 9, 2022
1 parent 552fd85 commit 84555a8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}`,
Expand Down
10 changes: 10 additions & 0 deletions src/datalayer/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down Expand Up @@ -137,4 +146,5 @@ export default {
walletIsAvailable,
getPublicAddress,
getWalletBalance,
waitForAllTransactionsToConfirm,
};

0 comments on commit 84555a8

Please sign in to comment.