application/docValidate.js
/**
 * Process the effective validation over dataset about document.
 * @param {ChaincodeClientTx} chaincodeTxValidate Transaction client to connect on ledger.
 * @param {BeanUser} validator User as validator role.
 * @param {BeanDataBlock} blockData Data block with the set of process information.
 */
Process the effective validation over dataset about document.
@param {ChaincodeClientTx} chaincodeTxValidate Transaction client to connect on ledger.
@param {BeanUser} validator User as validator role.
@param {BeanDataBlock} blockData Data block with the set of process information.
Process the effective validation over dataset about document . @param { ChaincodeClientTx } chaincodeTxValidate Transaction client to connect on ledger . @param { BeanUser } validator User as validator role . @param { BeanDataBlock } blockData Data block with the set of process information .
async function validateDocument(chaincodeTxValidate, validator, blockData){
    var blockDataValidator = await processToAddValidator(validator, blockData);
    blockDataValidator.configDateTimeLedger();
    logWrite('[validateDocument] Data to submit in transaction = ' + JSON.stringify(blockDataValidator));
    if (logActive) { fs.writeFileSync(JsonSubmitToValidate, blockDataValidator.serialize(), utf8); }
    var txResponse = await chaincodeTxValidate.processBlockchainTransaction(blockDataValidator);
    if (txResponse == null || txResponse == undefined) {
        let msgError = `The response from ledger is NULL or UNDEFINED`;
        logWrite(`[validateDocument, A] Message: ${msgError}`);
        throw msgError;
    }
    var response = ResponseModel.translateLedgerResponse(txResponse);
    logWrite(`[validateDocument] ResponseModel object =  ${response.serialize()}`);
    if (response.txStatus == ResponseModel.getTxStatusType().FAIL){
        logWrite(`[validateDocument, B] Error message = ${response.txMessage}`);
        logWrite(`[validateDocument] Error stack = ${response.txContent}`);
        throw response.txMessage;
    }
    logWrite(`[validateDocument] Transaction Message = ${response.txMessage}`);
    if (response.txStatus == ResponseModel.getTxStatusType().EMPTY) {
        logWrite(`[validateDocument, C] Message = ${response.txMessage}`);
        logWrite(`[validateDocument] Content = ${response.txContent}`);
        throw response.txMessage;
    }
    var blockDataJSon = JSON.parse(response.txContent);
    logWrite('[validateDocument] Bloco de dados = ' + JSON.stringify(blockDataJSon));
    var blockDataAfterValidated = BeanDataBlock.createBeanDataBlock(blockDataJSon);
    var status = blockDataAfterValidated.status;
    logWrite(`[validateDocument] Document status = ${status}`);
    return blockDataAfterValidated;
}
async function validateDocument ( chaincodeTxValidate , validator , blockData ) { var blockDataValidator = await processToAddValidator ( validator , blockData ) ; blockDataValidator . configDateTimeLedger ( ) ; logWrite ( '[validateDocument] Data to submit in transaction = ' + JSON . stringify ( blockDataValidator ) ) ; if ( logActive ) { fs . writeFileSync ( JsonSubmitToValidate , blockDataValidator . serialize ( ) , utf8 ) ; } var txResponse = await chaincodeTxValidate . processBlockchainTransaction ( blockDataValidator ) ; if ( txResponse == null || txResponse == undefined ) { let msgError = ` ` ; logWrite ( ` ${ msgError } ` ) ; throw msgError ; } var response = ResponseModel . translateLedgerResponse ( txResponse ) ; logWrite ( ` ${ response . serialize ( ) } ` ) ; if ( response . txStatus == ResponseModel . getTxStatusType ( ) . FAIL ) { logWrite ( ` ${ response . txMessage } ` ) ; logWrite ( ` ${ response . txContent } ` ) ; throw response . txMessage ; } logWrite ( ` ${ response . txMessage } ` ) ; if ( response . txStatus == ResponseModel . getTxStatusType ( ) . EMPTY ) { logWrite ( ` ${ response . txMessage } ` ) ; logWrite ( ` ${ response . txContent } ` ) ; throw response . txMessage ; } var blockDataJSon = JSON . parse ( response . txContent ) ; logWrite ( '[validateDocument] Bloco de dados = ' + JSON . stringify ( blockDataJSon ) ) ; var blockDataAfterValidated = BeanDataBlock . createBeanDataBlock ( blockDataJSon ) ; var status = blockDataAfterValidated . status ; logWrite ( ` ${ status } ` ) ; return blockDataAfterValidated ; }
Process the effective validation over dataset about document.
Process the effective validation over dataset about document .
// Add Validator data to block // Save in file before to submit //---------------------------------------------------------------------------------- // Process transaction into Fabric ledger // Treatment about data received as response from ledger // Validate the success of transaction // Validate the situation of transaction // Process the content of the transaction