wallet_defined_by_keys.js
function deleteWallet(wallet, rejector_device_address, onDone){
	db.query("SELECT approval_date FROM extended_pubkeys WHERE wallet=? AND device_address=?", [wallet, rejector_device_address], function(rows){
		if (rows.length === 0) // you are not a member device
			return onDone();
		if (rows[0].approval_date) // you've already approved this wallet, you can't change your mind
			return onDone();
		db.query("SELECT device_address FROM extended_pubkeys WHERE wallet=?", [wallet], function(rows){
			var arrMemberAddresses = rows.map(function(row){ return row.device_address; });
			var arrQueries = [];
			db.addQuery(arrQueries, "DELETE FROM extended_pubkeys WHERE wallet=?", [wallet]);
			db.addQuery(arrQueries, "DELETE FROM wallet_signing_paths WHERE wallet=?", [wallet]);
			db.addQuery(arrQueries, "DELETE FROM wallets WHERE wallet=?", [wallet]);
			// delete unused indirect correspondents
			db.addQuery(
				arrQueries, 
				"DELETE FROM correspondent_devices WHERE is_indirect=1 AND device_address IN(?) AND NOT EXISTS ( \n\
					SELECT * FROM extended_pubkeys WHERE extended_pubkeys.device_address=correspondent_devices.device_address \n\
				)", 
				[arrMemberAddresses]
			);
			async.series(arrQueries, function(){
				eventBus.emit('wallet_declined', wallet, rejector_device_address);
				onDone();
			});
		});
	});
}
function deleteWallet(wallet, rejector_device_address, onDone){
	db.query("SELECT approval_date FROM extended_pubkeys WHERE wallet=? AND device_address=?", [wallet, rejector_device_address], function(rows){
		if (rows.length === 0) // you are not a member device
			return onDone();
		if (rows[0].approval_date) // you've already approved this wallet, you can't change your mind
			return onDone();
		db.query("SELECT device_address FROM extended_pubkeys WHERE wallet=?", [wallet], function(rows){
			var arrMemberAddresses = rows.map(function(row){ return row.device_address; });
			var arrQueries = [];
			db.addQuery(arrQueries, "DELETE FROM extended_pubkeys WHERE wallet=?", [wallet]);
			db.addQuery(arrQueries, "DELETE FROM wallet_signing_paths WHERE wallet=?", [wallet]);
			db.addQuery(arrQueries, "DELETE FROM wallets WHERE wallet=?", [wallet]);
			// delete unused indirect correspondents
			db.addQuery(
				arrQueries, 
				"DELETE FROM correspondent_devices WHERE is_indirect=1 AND device_address IN(?) AND NOT EXISTS ( \n\
					SELECT * FROM extended_pubkeys WHERE extended_pubkeys.device_address=correspondent_devices.device_address \n\
				)", 
				[arrMemberAddresses]
			);
			async.series(arrQueries, function(){
				eventBus.emit('wallet_declined', wallet, rejector_device_address);
				onDone();
			});
		});
	});
}
function deleteWallet ( wallet , rejector_device_address , onDone ) { db . query ( "SELECT approval_date FROM extended_pubkeys WHERE wallet=? AND device_address=?" , [ wallet , rejector_device_address ] , function ( rows ) { if ( rows . length === 0 ) // you are not a member device return onDone ( ) ; if ( rows [ 0 ] . approval_date ) // you've already approved this wallet, you can't change your mind return onDone ( ) ; db . query ( "SELECT device_address FROM extended_pubkeys WHERE wallet=?" , [ wallet ] , function ( rows ) { var arrMemberAddresses = rows . map ( function ( row ) { return row . device_address ; } ) ; var arrQueries = [ ] ; db . addQuery ( arrQueries , "DELETE FROM extended_pubkeys WHERE wallet=?" , [ wallet ] ) ; db . addQuery ( arrQueries , "DELETE FROM wallet_signing_paths WHERE wallet=?" , [ wallet ] ) ; db . addQuery ( arrQueries , "DELETE FROM wallets WHERE wallet=?" , [ wallet ] ) ; // delete unused indirect correspondents db . addQuery ( arrQueries , "DELETE FROM correspondent_devices WHERE is_indirect=1 AND device_address IN(?) AND NOT EXISTS ( \n\
					SELECT * FROM extended_pubkeys WHERE extended_pubkeys.device_address=correspondent_devices.device_address \n\
				)" , [ arrMemberAddresses ] ) ; async . series ( arrQueries , function ( ) { eventBus . emit ( 'wallet_declined' , wallet , rejector_device_address ) ; onDone ( ) ; } ) ; } ) ; } ) ; }
called from network, without user interaction One of the proposed cosigners declined wallet creation
called from network without user interaction One of the proposed cosigners declined wallet creation