async function onSavedUnit(objJoint) {
	let objUnit = objJoint.unit;
	if (!objUnit.messages) // final-bad
		return;
	let objBaseMessage = objUnit.messages.find(message => message.app === 'payment' && !message.payload.asset);
	if (!objBaseMessage.payload.outputs.find(output => output.address === conf.aa_address && output.amount >= constants.MIN_BYTES_BOUNCE_FEE))
		return;
	let objDataMessage = objUnit.messages.find(message => message.app === 'data');
	let data = objDataMessage ? objDataMessage.payload : null;
	let address = objUnit.authors[0].address;
	if (address === conf.aa_address /*|| address === operator.getAddress()*/) // sent by AA or operator
		return;
	// deposits
	if (!data || ValidationUtils.isValidAddress(data.to)) {
		if (data && data.to)
			address = data.to;
		sendBalancesUpdate(address, 'pending_deposit');
	}
	// withdrawals
	else if (data && data.withdraw && (data.amount > 0 || data.amount === 'all') && utils.isValidAsset(data.asset)) {
		let withdrawn_symbol = await getSymbolByAsset(data.asset);
		getBalances(address, ({ balances_by_symbol, balances_by_asset }) => {
			let amount = (data.amount === 'all') ? balances_by_asset[data.asset] : data.amount;
			balances_by_symbol[withdrawn_symbol] -= amount;
			balances_by_asset[data.asset] -= amount;
			if (balances_by_symbol[withdrawn_symbol] < 0) // it'll fail
				return console.error("received a withdrawal from " + address + " that will fail");
			assocPendingWithdrawals[objUnit.unit] = { address, asset: data.asset, symbol: withdrawn_symbol, amount: data.amount };
			eventBus.emit('balances_update', { address, balances_by_symbol, balances_by_asset, event: 'pending_withdrawal' });
		});
	}
	// cancels
	else if (data && data.cancel && data.order) {
		signing.validateSignedMessage(data.order, err => {
			if (err)
				return console.log("bad cancel: " + err);
			if (order.signed_message.address !== address)
				return console.log("cancelling of another's order");
			let hash = orders.getOrderHash(order);
			eventBus.emit('cancel_order', { orderHash: hash, userAddress: address });
		});
	}
	// revokes
	else if (data && data.revoke && ValidationUtils.isValidAddress(data.address))
		eventBus.emit('revoke', { signerAddress: data.address, userAddress: address });
	// trade submitted by another matcher
	else if (data && data.order1 && data.order2 && address !== operator.getAddress() && !orders.getOrderError(data.order1.signed_message) && !orders.getOrderError(data.order2.signed_message)) {
		
	}
}
// look for trigger units sent to the AA
look for trigger units sent to the AA
look for trigger units sent to the AA
async function onSavedUnit(objJoint) {
	let objUnit = objJoint.unit;
	if (!objUnit.messages) 
		return;
	let objBaseMessage = objUnit.messages.find(message => message.app === 'payment' && !message.payload.asset);
	if (!objBaseMessage.payload.outputs.find(output => output.address === conf.aa_address && output.amount >= constants.MIN_BYTES_BOUNCE_FEE))
		return;
	let objDataMessage = objUnit.messages.find(message => message.app === 'data');
	let data = objDataMessage ? objDataMessage.payload : null;
	let address = objUnit.authors[0].address;
	if (address === conf.aa_address ) 
		return;
	if (!data || ValidationUtils.isValidAddress(data.to)) {
		if (data && data.to)
			address = data.to;
		sendBalancesUpdate(address, 'pending_deposit');
	}
	else if (data && data.withdraw && (data.amount > 0 || data.amount === 'all') && utils.isValidAsset(data.asset)) {
		let withdrawn_symbol = await getSymbolByAsset(data.asset);
		getBalances(address, ({ balances_by_symbol, balances_by_asset }) => {
			let amount = (data.amount === 'all') ? balances_by_asset[data.asset] : data.amount;
			balances_by_symbol[withdrawn_symbol] -= amount;
			balances_by_asset[data.asset] -= amount;
			if (balances_by_symbol[withdrawn_symbol] < 0) 
				return console.error("received a withdrawal from " + address + " that will fail");
			assocPendingWithdrawals[objUnit.unit] = { address, asset: data.asset, symbol: withdrawn_symbol, amount: data.amount };
			eventBus.emit('balances_update', { address, balances_by_symbol, balances_by_asset, event: 'pending_withdrawal' });
		});
	}
	else if (data && data.cancel && data.order) {
		signing.validateSignedMessage(data.order, err => {
			if (err)
				return console.log("bad cancel: " + err);
			if (order.signed_message.address !== address)
				return console.log("cancelling of another's order");
			let hash = orders.getOrderHash(order);
			eventBus.emit('cancel_order', { orderHash: hash, userAddress: address });
		});
	}
	else if (data && data.revoke && ValidationUtils.isValidAddress(data.address))
		eventBus.emit('revoke', { signerAddress: data.address, userAddress: address });
	else if (data && data.order1 && data.order2 && address !== operator.getAddress() && !orders.getOrderError(data.order1.signed_message) && !orders.getOrderError(data.order2.signed_message)) {
	}
}
async function onSavedUnit ( objJoint ) { let objUnit = objJoint . unit ; if ( ! objUnit . messages ) return ; let objBaseMessage = objUnit . messages . find ( message => message . app === 'payment' && ! message . payload . asset ) ; if ( ! objBaseMessage . payload . outputs . find ( output => output . address === conf . aa_address && output . amount >= constants . MIN_BYTES_BOUNCE_FEE ) ) return ; let objDataMessage = objUnit . messages . find ( message => message . app === 'data' ) ; let data = objDataMessage ? objDataMessage . payload : null ; let address = objUnit . authors [ 0 ] . address ; if ( address === conf . aa_address ) return ; if ( ! data || ValidationUtils . isValidAddress ( data . to ) ) { if ( data && data . to ) address = data . to ; sendBalancesUpdate ( address , 'pending_deposit' ) ; } else if ( data && data . withdraw && ( data . amount > 0 || data . amount === 'all' ) && utils . isValidAsset ( data . asset ) ) { let withdrawn_symbol = await getSymbolByAsset ( data . asset ) ; getBalances ( address , ( { balances_by_symbol , balances_by_asset } ) => { let amount = ( data . amount === 'all' ) ? balances_by_asset [ data . asset ] : data . amount ; balances_by_symbol [ withdrawn_symbol ] -= amount ; balances_by_asset [ data . asset ] -= amount ; if ( balances_by_symbol [ withdrawn_symbol ] < 0 ) return console . error ( "received a withdrawal from " + address + " that will fail" ) ; assocPendingWithdrawals [ objUnit . unit ] = { address , asset : data . asset , symbol : withdrawn_symbol , amount : data . amount } ; eventBus . emit ( 'balances_update' , { address , balances_by_symbol , balances_by_asset , event : 'pending_withdrawal' } ) ; } ) ; } else if ( data && data . cancel && data . order ) { signing . validateSignedMessage ( data . order , err => { if ( err ) return console . log ( "bad cancel: " + err ) ; if ( order . signed_message . address !== address ) return console . log ( "cancelling of another's order" ) ; let hash = orders . getOrderHash ( order ) ; eventBus . emit ( 'cancel_order' , { orderHash : hash , userAddress : address } ) ; } ) ; } else if ( data && data . revoke && ValidationUtils . isValidAddress ( data . address ) ) eventBus . emit ( 'revoke' , { signerAddress : data . address , userAddress : address } ) ; else if ( data && data . order1 && data . order2 && address !== operator . getAddress ( ) && ! orders . getOrderError ( data . order1 . signed_message ) && ! orders . getOrderError ( data . order2 . signed_message ) ) { } }
look for trigger units sent to the AA
look for trigger units sent to the AA
// final-bad /*|| address === operator.getAddress()*/ // sent by AA or operator // deposits // withdrawals // it'll fail // cancels // revokes // trade submitted by another matcher