async function updateTradeStatuses() {
	if (conf.bLight && !network.isStarted()) // we need the network to read the balances in AA and send balance updates
		return eventBus.once('network_started', updateTradeStatuses);
	let mongodb = await mongo.getMongo();
	let trades = await mongodb.collection('trades').find({ status: 'SUCCESS' }).toArray();
	console.error(trades.length + " uncommitted trades");
	if (trades.length === 0)
		return;
	let arrUnits = trades.map(trade => trade.txHash);
	let rows = await db.query("SELECT mci, trigger_address, aa_address, trigger_unit, bounced, response_unit, response, creation_date FROM aa_responses WHERE trigger_unit IN(" + arrUnits.map(db.escape).join(', ') + ") ORDER BY " + (conf.storage === 'sqlite' ? 'rowid' : 'mci'));
	console.error(rows.length + " unhandled AA responses");
	rows.forEach(row => {
		objectHash.cleanNulls(row);
		row.response = JSON.parse(row.response);
		let objAAResponse = row;
		onAAResponse(objAAResponse);
	});
}
// some events might be missed if the daemon crashes
some events might be missed if the daemon crashes
some events might be missed if the daemon crashes
async function updateTradeStatuses() {
	if (conf.bLight && !network.isStarted()) 
		return eventBus.once('network_started', updateTradeStatuses);
	let mongodb = await mongo.getMongo();
	let trades = await mongodb.collection('trades').find({ status: 'SUCCESS' }).toArray();
	console.error(trades.length + " uncommitted trades");
	if (trades.length === 0)
		return;
	let arrUnits = trades.map(trade => trade.txHash);
	let rows = await db.query("SELECT mci, trigger_address, aa_address, trigger_unit, bounced, response_unit, response, creation_date FROM aa_responses WHERE trigger_unit IN(" + arrUnits.map(db.escape).join(', ') + ") ORDER BY " + (conf.storage === 'sqlite' ? 'rowid' : 'mci'));
	console.error(rows.length + " unhandled AA responses");
	rows.forEach(row => {
		objectHash.cleanNulls(row);
		row.response = JSON.parse(row.response);
		let objAAResponse = row;
		onAAResponse(objAAResponse);
	});
}
async function updateTradeStatuses ( ) { if ( conf . bLight && ! network . isStarted ( ) ) return eventBus . once ( 'network_started' , updateTradeStatuses ) ; let mongodb = await mongo . getMongo ( ) ; let trades = await mongodb . collection ( 'trades' ) . find ( { status : 'SUCCESS' } ) . toArray ( ) ; console . error ( trades . length + " uncommitted trades" ) ; if ( trades . length === 0 ) return ; let arrUnits = trades . map ( trade => trade . txHash ) ; let rows = await db . query ( "SELECT mci, trigger_address, aa_address, trigger_unit, bounced, response_unit, response, creation_date FROM aa_responses WHERE trigger_unit IN(" + arrUnits . map ( db . escape ) . join ( ', ' ) + ") ORDER BY " + ( conf . storage === 'sqlite' ? 'rowid' : 'mci' ) ) ; console . error ( rows . length + " unhandled AA responses" ) ; rows . forEach ( row => { objectHash . cleanNulls ( row ) ; row . response = JSON . parse ( row . response ) ; let objAAResponse = row ; onAAResponse ( objAAResponse ) ; } ) ; }
some events might be missed if the daemon crashes
some events might be missed if the daemon crashes
// we need the network to read the balances in AA and send balance updates