witness/witness_pow_proof.js
function validateUnit( objUnit, bRequireDefinitionOrChange, cb2 )
	{
		let bFound = false;
		_async.eachSeries
		(
			objUnit.authors,
			function( author, cb3 )
			{
				let sAddress = author.address;
				if ( -1 === arrFoundTrustMEAuthors.indexOf( sAddress ) )
				{
					//	not a witness - skip it
					return cb3();
				}

				//
				//	the latest definition chash of the witness
				//
				let definition_chash = assocDefinitionChashes[ sAddress ];
				if ( ! definition_chash )
				{
					throw Error( "definition chash not known for address " + sAddress );
				}
				if ( author.definition )
				{
					//
					//	do transaction for the first time
					//
					if ( _object_hash.getChash160( author.definition ) !== definition_chash )
					{
						return cb3( "definition doesn't hash to the expected value" );
					}

					assocDefinitions[ definition_chash ] = author.definition;
					bFound = true;
				}


				function handleAuthor()
				{
					//	FIX
					_validation.validateAuthorSignaturesWithoutReferences
					(
						author,
						objUnit,
						assocDefinitions[ definition_chash ],	//	definition JSON
						function( err )
						{
							if ( err )
							{
								return cb3( err );
							}

							//
							//	okay, definition is valid
							//
							for ( let i = 0; i < objUnit.messages.length; i++ )
							{
								let message = objUnit.messages[ i ];
								if ( 'address_definition_change' === message.app
									&& ( message.payload.address === sAddress ||
										1 === objUnit.authors.length && objUnit.authors[ 0 ].address === sAddress ) )
								{
									assocDefinitionChashes[ sAddress ] = message.payload.definition_chash;
									bFound = true;
								}
							}

							//	...
							cb3();
						}
					);
				}

				if ( assocDefinitions[ definition_chash ] )
				{
					return handleAuthor();
				}

				//
				//	only an address with money
				//	there is no transaction any more
				//
				_storage.readDefinition( _db, definition_chash,
				{
					ifFound : function( arrDefinition )
					{
						assocDefinitions[ definition_chash ] = arrDefinition;
						handleAuthor();
					},
					ifDefinitionNotFound : function( sDefinitionCHash )
					{
						throw Error( "definition " + definition_chash + " not found, address " + sAddress );
					}
				});
			},
			function( err )
			{
				if ( err )
				{
					return cb2( err );
				}

				if ( bRequireDefinitionOrChange && ! bFound )
				{
					//
					//	bRequireDefinitionOrChange always be false
					//	so, you will never arrive here so far
					//
					return cb2( "neither definition nor change" );
				}

				//	...
				cb2();
			}

		); // each authors
	}
function validateUnit( objUnit, bRequireDefinitionOrChange, cb2 )
	{
		let bFound = false;
		_async.eachSeries
		(
			objUnit.authors,
			function( author, cb3 )
			{
				let sAddress = author.address;
				if ( -1 === arrFoundTrustMEAuthors.indexOf( sAddress ) )
				{
					//	not a witness - skip it
					return cb3();
				}

				//
				//	the latest definition chash of the witness
				//
				let definition_chash = assocDefinitionChashes[ sAddress ];
				if ( ! definition_chash )
				{
					throw Error( "definition chash not known for address " + sAddress );
				}
				if ( author.definition )
				{
					//
					//	do transaction for the first time
					//
					if ( _object_hash.getChash160( author.definition ) !== definition_chash )
					{
						return cb3( "definition doesn't hash to the expected value" );
					}

					assocDefinitions[ definition_chash ] = author.definition;
					bFound = true;
				}


				function handleAuthor()
				{
					//	FIX
					_validation.validateAuthorSignaturesWithoutReferences
					(
						author,
						objUnit,
						assocDefinitions[ definition_chash ],	//	definition JSON
						function( err )
						{
							if ( err )
							{
								return cb3( err );
							}

							//
							//	okay, definition is valid
							//
							for ( let i = 0; i < objUnit.messages.length; i++ )
							{
								let message = objUnit.messages[ i ];
								if ( 'address_definition_change' === message.app
									&& ( message.payload.address === sAddress ||
										1 === objUnit.authors.length && objUnit.authors[ 0 ].address === sAddress ) )
								{
									assocDefinitionChashes[ sAddress ] = message.payload.definition_chash;
									bFound = true;
								}
							}

							//	...
							cb3();
						}
					);
				}

				if ( assocDefinitions[ definition_chash ] )
				{
					return handleAuthor();
				}

				//
				//	only an address with money
				//	there is no transaction any more
				//
				_storage.readDefinition( _db, definition_chash,
				{
					ifFound : function( arrDefinition )
					{
						assocDefinitions[ definition_chash ] = arrDefinition;
						handleAuthor();
					},
					ifDefinitionNotFound : function( sDefinitionCHash )
					{
						throw Error( "definition " + definition_chash + " not found, address " + sAddress );
					}
				});
			},
			function( err )
			{
				if ( err )
				{
					return cb2( err );
				}

				if ( bRequireDefinitionOrChange && ! bFound )
				{
					//
					//	bRequireDefinitionOrChange always be false
					//	so, you will never arrive here so far
					//
					return cb2( "neither definition nor change" );
				}

				//	...
				cb2();
			}

		); // each authors
	}
function validateUnit ( objUnit , bRequireDefinitionOrChange , cb2 ) { let bFound = false ; _async . eachSeries ( objUnit . authors , function ( author , cb3 ) { let sAddress = author . address ; if ( - 1 === arrFoundTrustMEAuthors . indexOf ( sAddress ) ) { //	not a witness - skip it return cb3 ( ) ; } // //	the latest definition chash of the witness // let definition_chash = assocDefinitionChashes [ sAddress ] ; if ( ! definition_chash ) { throw Error ( "definition chash not known for address " + sAddress ) ; } if ( author . definition ) { // //	do transaction for the first time // if ( _object_hash . getChash160 ( author . definition ) !== definition_chash ) { return cb3 ( "definition doesn't hash to the expected value" ) ; } assocDefinitions [ definition_chash ] = author . definition ; bFound = true ; } function handleAuthor ( ) { //	FIX _validation . validateAuthorSignaturesWithoutReferences ( author , objUnit , assocDefinitions [ definition_chash ] , //	definition JSON function ( err ) { if ( err ) { return cb3 ( err ) ; } // //	okay, definition is valid // for ( let i = 0 ; i < objUnit . messages . length ; i ++ ) { let message = objUnit . messages [ i ] ; if ( 'address_definition_change' === message . app && ( message . payload . address === sAddress || 1 === objUnit . authors . length && objUnit . authors [ 0 ] . address === sAddress ) ) { assocDefinitionChashes [ sAddress ] = message . payload . definition_chash ; bFound = true ; } } //	... cb3 ( ) ; } ) ; } if ( assocDefinitions [ definition_chash ] ) { return handleAuthor ( ) ; } // //	only an address with money //	there is no transaction any more // _storage . readDefinition ( _db , definition_chash , { ifFound : function ( arrDefinition ) { assocDefinitions [ definition_chash ] = arrDefinition ; handleAuthor ( ) ; } , ifDefinitionNotFound : function ( sDefinitionCHash ) { throw Error ( "definition " + definition_chash + " not found, address " + sAddress ) ; } } ) ; } , function ( err ) { if ( err ) { return cb2 ( err ) ; } if ( bRequireDefinitionOrChange && ! bFound ) { // //	bRequireDefinitionOrChange always be false //	so, you will never arrive here so far // return cb2 ( "neither definition nor change" ) ; } //	... cb2 ( ) ; } ) ; // each authors }
checks signatures and updates definitions
checks signatures and updates definitions