light.js
function createLinkProof(later_unit, earlier_unit, arrChain, cb){
	storage.readJoint(db, later_unit, {
		ifNotFound: function(){
			cb("later unit not found");
		},
		ifFound: function(objLaterJoint){
			var later_mci = objLaterJoint.unit.main_chain_index;
			arrChain.push(objLaterJoint);
			storage.readUnitProps(db, objLaterJoint.unit.last_ball_unit, function(objLaterLastBallUnitProps){
				var later_lb_mci = objLaterLastBallUnitProps.main_chain_index;
				storage.readJoint(db, earlier_unit, {
					ifNotFound: function(){
						cb("earlier unit not found");
					},
					ifFound: function(objEarlierJoint){
						var earlier_mci = objEarlierJoint.unit.main_chain_index;
						var earlier_unit = objEarlierJoint.unit.unit;
						if (later_mci < earlier_mci && later_mci !== null && earlier_mci !== null)
							return cb("not included");
						if (later_lb_mci >= earlier_mci && earlier_mci !== null){ // was spent when confirmed
							// includes the ball of earlier unit
							proofChain.buildProofChain(later_lb_mci + 1, earlier_mci, earlier_unit, arrChain, function(){
								cb();
							});
						}
						else{ // the output was unconfirmed when spent
							graph.determineIfIncluded(db, earlier_unit, [later_unit], function(bIncluded){
								if (!bIncluded)
									return cb("not included");
								buildPath(objLaterJoint, objEarlierJoint, arrChain, function(){
									cb();
								});
							});
						}
					}
				});
			});
		}
	});
}
function createLinkProof(later_unit, earlier_unit, arrChain, cb){
	storage.readJoint(db, later_unit, {
		ifNotFound: function(){
			cb("later unit not found");
		},
		ifFound: function(objLaterJoint){
			var later_mci = objLaterJoint.unit.main_chain_index;
			arrChain.push(objLaterJoint);
			storage.readUnitProps(db, objLaterJoint.unit.last_ball_unit, function(objLaterLastBallUnitProps){
				var later_lb_mci = objLaterLastBallUnitProps.main_chain_index;
				storage.readJoint(db, earlier_unit, {
					ifNotFound: function(){
						cb("earlier unit not found");
					},
					ifFound: function(objEarlierJoint){
						var earlier_mci = objEarlierJoint.unit.main_chain_index;
						var earlier_unit = objEarlierJoint.unit.unit;
						if (later_mci < earlier_mci && later_mci !== null && earlier_mci !== null)
							return cb("not included");
						if (later_lb_mci >= earlier_mci && earlier_mci !== null){ // was spent when confirmed
							// includes the ball of earlier unit
							proofChain.buildProofChain(later_lb_mci + 1, earlier_mci, earlier_unit, arrChain, function(){
								cb();
							});
						}
						else{ // the output was unconfirmed when spent
							graph.determineIfIncluded(db, earlier_unit, [later_unit], function(bIncluded){
								if (!bIncluded)
									return cb("not included");
								buildPath(objLaterJoint, objEarlierJoint, arrChain, function(){
									cb();
								});
							});
						}
					}
				});
			});
		}
	});
}
function createLinkProof ( later_unit , earlier_unit , arrChain , cb ) { storage . readJoint ( db , later_unit , { ifNotFound : function ( ) { cb ( "later unit not found" ) ; } , ifFound : function ( objLaterJoint ) { var later_mci = objLaterJoint . unit . main_chain_index ; arrChain . push ( objLaterJoint ) ; storage . readUnitProps ( db , objLaterJoint . unit . last_ball_unit , function ( objLaterLastBallUnitProps ) { var later_lb_mci = objLaterLastBallUnitProps . main_chain_index ; storage . readJoint ( db , earlier_unit , { ifNotFound : function ( ) { cb ( "earlier unit not found" ) ; } , ifFound : function ( objEarlierJoint ) { var earlier_mci = objEarlierJoint . unit . main_chain_index ; var earlier_unit = objEarlierJoint . unit . unit ; if ( later_mci < earlier_mci && later_mci !== null && earlier_mci !== null ) return cb ( "not included" ) ; if ( later_lb_mci >= earlier_mci && earlier_mci !== null ) { // was spent when confirmed // includes the ball of earlier unit proofChain . buildProofChain ( later_lb_mci + 1 , earlier_mci , earlier_unit , arrChain , function ( ) { cb ( ) ; } ) ; } else { // the output was unconfirmed when spent graph . determineIfIncluded ( db , earlier_unit , [ later_unit ] , function ( bIncluded ) { if ( ! bIncluded ) return cb ( "not included" ) ; buildPath ( objLaterJoint , objEarlierJoint , arrChain , function ( ) { cb ( ) ; } ) ; } ) ; } } } ) ; } ) ; } } ) ; }
adds later unit earlier unit is not included in the chain
adds later unit earlier unit is not included in the chain