3

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

Find below the source codes:

Blockquote

Model file:

namespace org.acme.sample

asset Vinho identified by IDvinho {

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

}

participant Participante identified by IDparticipante {

o String IDparticipante
o String tipo
o String nomeEmpresa

}

transaction CompraDoVinho identified by IDcompra {

o String IDcompra
--> Vinho asset
o Integer precoVenda

}

Logic:

function onSampleTransaction(CompraDoVinho) {

CompraDoVinho.asset.preco = CompraDoVinho.precoVenda;

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

    .then(function (assetRegistry) {

        return assetRegistry.update(CompraDoVinho.asset);

  });

}

Permissions:

rule Default {

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

}

Blockquote

Could anybody help me finding where is the bug in my code?

Thanks in advance

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
MCreimer
  • 31
  • 1
  • 3

3 Answers3

2

The issue is almost certainly because you've renamed the transaction. Composer has 2 mechanisms to route transactions to JS functions:

  1. (Legacy) using an onMyTransactionType naming convention. I.e. the function will be called when an instance of MyTransactionType is submitted.
  2. (Preferred) using the @transaction and @param annotations. See below for an example. The @transaction annotation indicates that the function would like to process transactions and the @param annotation is used to specify the type of the 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);
            });
    }
Dan Selman
  • 2,287
  • 2
  • 9
  • 18
  • Interesting. I was not aware of such convention rule. I´ve just replaced "CompraDoVinho" for "onSampleTransaction", but it´s still not working. Any other thought? Thanks by now. – MCreimer Apr 27 '17 at 21:02
  • 1
    I think it should be onCompraDoVinho, however much better to go with the annotation approach – david_k Apr 28 '17 at 17:18
  • I had the same problem. I made a new transaction called "Sell" and I didn't change the `@param` from *trade* to *sell*. `@param {org.acme.mynetwork.Sell}` Having the `@param` in what appears to be comments is very misleading. – Flea Sep 29 '17 at 20:35
  • @Dan What is getFactory() method? – rajadilipkolli Jan 30 '18 at 12:35
  • getFactory is used to create instances of assets, participants, transactions, events etc. – Dan Selman Feb 04 '18 at 18:49
  • Hi i am just trying to create demo but i am getting below error :- Error: Could not find any functions to execute for transaction org.acme.mynetwork.Trade#4dbcc76f-332b-4a68-8606-8d9a510e1284 But i am following the official tutorial – sharma_kunal Apr 12 '18 at 14:33
1

Absolutely. The annotation is essential for the function to work! @param must state the class name of the transaction and the param name @transaction declared underneath, with function to follow in block below

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

0

Please Replace the code in your logic.js file with following code and the error will surely be gone. Mine was the same problem, I just added the required JS doc annotations above the function and the same issue was resolved!

'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!

PrashantNagawade
  • 426
  • 1
  • 6
  • 24