Fabric Composer test code not working

I have just replaced the sample Composer sample ("sampleAsset", "sampleTransaction", etc.) with another one I created for my better understanding. Everything works except for the transaction, which returns me an error message: "** Error: Could not find any functions to execute transaction org.acme.sample.CompraDoVinho # ** 2b2d0624-bc ..."

Find below source codes:

Blockquote

Model file:

namespace org.acme.sample

Vinho assets identified by IDvinho {

o String IDvinho
--> Participante owner
o String uva
o String nomeVinho 
o Integer preco 

      

}

Participant Participant identified by IDparticipante {

o String IDparticipante
o String tipo
o String nomeEmpresa

      

}

CompraDoVinho transaction identified by IDcompra {

o String IDcompra
--> Vinho asset
o Integer precoVenda

      

}

Logics:

function onSampleTransaction (CompraDoVinho) {

CompraDoVinho.asset.preco = CompraDoVinho.precoVenda;

return getAssetRegistry('org.acme.sample.Vinho')

    .then(function (assetRegistry) {

        return assetRegistry.update(CompraDoVinho.asset);

  });

      

}

Access rights:

rule Default {

description: "Allow all participants access to all resources"
participant: "ANY"
operation: ALL
resource: "org.acme.sample"
action: ALLOW

      

}

Blockquote

Can someone help me find where the error is in my code?

Thank you in advance

+3


source to share


3 answers


The problem is almost certainly due to the fact that you renamed the transaction. Composer has 2 mechanisms for routing transactions for JS functions:

  • (Legacy) using a naming convention onMyTransactionType

    . That is, the function is called when the instance is dispatched MyTransactionType

    .
  • (preferably) using annotations @transaction

    and @param

    . Below is an example. The annotation @transaction

    indicates that the function would like to process transactions, and the annotation is @param

    used to indicate the type of transaction to process.


    / **
     * Place an order for a vehicle
     * @param {org.acme.vehicle.lifecycle.manufacturer.PlaceOrder} placeOrder - the PlaceOrder transaction
     * @transaction
     * /
    function placeOrder (placeOrder) {
        console.log ('placeOrder');

        let factory = getFactory ();
        let NS = 'org.acme.vehicle.lifecycle.manufacturer';

        let order = factory.newResource (NS, 'Order', placeOrder.transactionId);
        order.vehicleDetails = placeOrder.vehicleDetails;
        order.orderStatus = 'PLACED';
        order.manufacturer = placeOrder.manufacturer;

        // save the order
        return getAssetRegistry (order.getFullyQualifiedType ())
            .then (function (registry) {
                return registry.add (order);
            });
    }
+2


source


Please replace the code in your file logic.js

with the following code and the error will surely go away. My problem was the same problem, I just added the required one JS doc annotations

above the function and the same problem was solved!

'use strict';
var NS = 'org.acme.sample';
/**
 * @param {org.acme.sample} CompraDoVinho 
 * @transaction
 */
function onSampleTransaction(CompraDoVinho) {

CompraDoVinho.asset.preco = CompraDoVinho.precoVenda;

return getAssetRegistry('org.acme.sample.Vinho')

    .then(function (assetRegistry) {

        return assetRegistry.update(CompraDoVinho.asset);

  });
}

      



Hope this helps you!

0


source


Quite right. Annotation is important for the function to work! @param must specify the name of the transaction class and the name of the @transaction parameter declared below, with the function to follow in the block below

@param {org.acme.mynetwork.Foo} foo - report to be processed * @transaction

0


source







All Articles