network.js
function handleOnlinePrivatePayment(ws, arrPrivateElements, bViaHub, callbacks){
	if (!ValidationUtils.isNonemptyArray(arrPrivateElements))
		return callbacks.ifError("private_payment content must be non-empty array");
	
	var unit = arrPrivateElements[0].unit;
	var message_index = arrPrivateElements[0].message_index;
	var output_index = arrPrivateElements[0].payload.denomination ? arrPrivateElements[0].output_index : -1;

	var savePrivatePayment = function(cb){
		// we may receive the same unit and message index but different output indexes if recipient and cosigner are on the same device.
		// in this case, we also receive the same (unit, message_index, output_index) twice - as cosigner and as recipient.  That's why IGNORE.
		db.query(
			"INSERT "+db.getIgnore()+" INTO unhandled_private_payments (unit, message_index, output_index, json, peer) VALUES (?,?,?,?,?)", 
			[unit, message_index, output_index, JSON.stringify(arrPrivateElements), bViaHub ? '' : ws.peer], // forget peer if received via hub
			function(){
				callbacks.ifQueued();
				if (cb)
					cb();
			}
		);
	};
	
	if (conf.bLight && arrPrivateElements.length > 1){
		savePrivatePayment(function(){
			updateLinkProofsOfPrivateChain(arrPrivateElements, unit, message_index, output_index);
			rerequestLostJointsOfPrivatePayments(); // will request the head element
		});
		return;
	}

	joint_storage.checkIfNewUnit(unit, {
		ifKnown: function(){
			//assocUnitsInWork[unit] = true;
			privatePayment.validateAndSavePrivatePaymentChain(arrPrivateElements, {
				ifOk: function(){
					//delete assocUnitsInWork[unit];
					callbacks.ifAccepted(unit);
					eventBus.emit("new_my_transactions", [unit]);
				},
				ifError: function(error){
					//delete assocUnitsInWork[unit];
					callbacks.ifValidationError(unit, error);
				},
				ifWaitingForChain: function(){
					savePrivatePayment();
				}
			});
		},
		ifNew: function(){
			savePrivatePayment();
			// if received via hub, I'm requesting from the same hub, thus telling the hub that this unit contains a private payment for me.
			// It would be better to request missing joints from somebody else
			requestNewMissingJoints(ws, [unit]);
		},
		ifKnownUnverified: savePrivatePayment,
		ifKnownBad: function(){
			callbacks.ifValidationError(unit, "known bad");
		}
	});
}
function handleOnlinePrivatePayment(ws, arrPrivateElements, bViaHub, callbacks){
	if (!ValidationUtils.isNonemptyArray(arrPrivateElements))
		return callbacks.ifError("private_payment content must be non-empty array");
	
	var unit = arrPrivateElements[0].unit;
	var message_index = arrPrivateElements[0].message_index;
	var output_index = arrPrivateElements[0].payload.denomination ? arrPrivateElements[0].output_index : -1;

	var savePrivatePayment = function(cb){
		// we may receive the same unit and message index but different output indexes if recipient and cosigner are on the same device.
		// in this case, we also receive the same (unit, message_index, output_index) twice - as cosigner and as recipient.  That's why IGNORE.
		db.query(
			"INSERT "+db.getIgnore()+" INTO unhandled_private_payments (unit, message_index, output_index, json, peer) VALUES (?,?,?,?,?)", 
			[unit, message_index, output_index, JSON.stringify(arrPrivateElements), bViaHub ? '' : ws.peer], // forget peer if received via hub
			function(){
				callbacks.ifQueued();
				if (cb)
					cb();
			}
		);
	};
	
	if (conf.bLight && arrPrivateElements.length > 1){
		savePrivatePayment(function(){
			updateLinkProofsOfPrivateChain(arrPrivateElements, unit, message_index, output_index);
			rerequestLostJointsOfPrivatePayments(); // will request the head element
		});
		return;
	}

	joint_storage.checkIfNewUnit(unit, {
		ifKnown: function(){
			//assocUnitsInWork[unit] = true;
			privatePayment.validateAndSavePrivatePaymentChain(arrPrivateElements, {
				ifOk: function(){
					//delete assocUnitsInWork[unit];
					callbacks.ifAccepted(unit);
					eventBus.emit("new_my_transactions", [unit]);
				},
				ifError: function(error){
					//delete assocUnitsInWork[unit];
					callbacks.ifValidationError(unit, error);
				},
				ifWaitingForChain: function(){
					savePrivatePayment();
				}
			});
		},
		ifNew: function(){
			savePrivatePayment();
			// if received via hub, I'm requesting from the same hub, thus telling the hub that this unit contains a private payment for me.
			// It would be better to request missing joints from somebody else
			requestNewMissingJoints(ws, [unit]);
		},
		ifKnownUnverified: savePrivatePayment,
		ifKnownBad: function(){
			callbacks.ifValidationError(unit, "known bad");
		}
	});
}
function handleOnlinePrivatePayment ( ws , arrPrivateElements , bViaHub , callbacks ) { if ( ! ValidationUtils . isNonemptyArray ( arrPrivateElements ) ) return callbacks . ifError ( "private_payment content must be non-empty array" ) ; var unit = arrPrivateElements [ 0 ] . unit ; var message_index = arrPrivateElements [ 0 ] . message_index ; var output_index = arrPrivateElements [ 0 ] . payload . denomination ? arrPrivateElements [ 0 ] . output_index : - 1 ; var savePrivatePayment = function ( cb ) { // we may receive the same unit and message index but different output indexes if recipient and cosigner are on the same device. // in this case, we also receive the same (unit, message_index, output_index) twice - as cosigner and as recipient.  That's why IGNORE. db . query ( "INSERT " + db . getIgnore ( ) + " INTO unhandled_private_payments (unit, message_index, output_index, json, peer) VALUES (?,?,?,?,?)" , [ unit , message_index , output_index , JSON . stringify ( arrPrivateElements ) , bViaHub ? '' : ws . peer ] , // forget peer if received via hub function ( ) { callbacks . ifQueued ( ) ; if ( cb ) cb ( ) ; } ) ; } ; if ( conf . bLight && arrPrivateElements . length > 1 ) { savePrivatePayment ( function ( ) { updateLinkProofsOfPrivateChain ( arrPrivateElements , unit , message_index , output_index ) ; rerequestLostJointsOfPrivatePayments ( ) ; // will request the head element } ) ; return ; } joint_storage . checkIfNewUnit ( unit , { ifKnown : function ( ) { //assocUnitsInWork[unit] = true; privatePayment . validateAndSavePrivatePaymentChain ( arrPrivateElements , { ifOk : function ( ) { //delete assocUnitsInWork[unit]; callbacks . ifAccepted ( unit ) ; eventBus . emit ( "new_my_transactions" , [ unit ] ) ; } , ifError : function ( error ) { //delete assocUnitsInWork[unit]; callbacks . ifValidationError ( unit , error ) ; } , ifWaitingForChain : function ( ) { savePrivatePayment ( ) ; } } ) ; } , ifNew : function ( ) { savePrivatePayment ( ) ; // if received via hub, I'm requesting from the same hub, thus telling the hub that this unit contains a private payment for me. // It would be better to request missing joints from somebody else requestNewMissingJoints ( ws , [ unit ] ) ; } , ifKnownUnverified : savePrivatePayment , ifKnownBad : function ( ) { callbacks . ifValidationError ( unit , "known bad" ) ; } } ) ; }
handles one private payload and its chain
handles one private payload and its chain