Why does transaction give this error

2019-07-27 12:12发布

问题:

My model.cto file -

namespace org.acme.mynetwork

participant Client identified by ClientId {
  o String ClientId  
  o String ClientName
  o String[] Policies
  o String[] RFQAraay
}

participant Insurer identified by InsurerId {
  o String InsurerId  
  o String InsurerName
  o String[] RFQArray
  o String[] Quotes
  o String[] Policies
}

asset RFQ identified by RFQId {
  o String RFQId
  o String ClientId
  o String InsurerName
  o String TypeOfInsurance
  o String RiskAmunt
  o String Status
  o String currentOwner
  o String[] Quotes
  o String[] SelectedInsurer
  o String LeadInsurer
  o String[] FinalInsurer
}

participant Broker identified by BrokerId {
  o String BrokerId
  o String BrokerName
  o String[] Clients
}

asset Quote identified by QuoteId {
  o String QuoteId
  o String InsurerName
  o String InsurerId
  o String Premium
  o String Capacity
  o String RFQId
}

transaction GenerateRFQ {
  o String RFQId
  o String ClientId
  o String InsurerName
  o String TypeOfInsurance
  o String RiskAmount
  o String[] InsurerAddresses 
}

My Script.js file

/**
* Insurance script file
* @param {org.acme.mynetwork.GenerateRFQ} generate - the trade to be  processed
* @transaction
*/
function generateRFQ(generate){
  var RFQId = generate.RFQId ;
  var today = new Date();
  var y = today.getFullYear();
  var m = today.getMonth();
  var d = today.getDate();
  return getAssetRegistry('org.acme.mynetwork.RFQ').then(function(assetRegistry){
    var RFQregistry = assetRegistry;
    RFQregistry.RFQId = generate.RFQId; 
    RFQregistry.ClientId = generate.ClientId 
    RFQregistry.InsuredName = generate.InsurerName;
    RFQregistry.TypeOfInsurance = generate.TypeOfInsurance;
    RFQregistry.RiskAmount = generate.RiskAmount; 
    RFQregistry.Status = "RFQ fired on "+ d + m + y;
    RFQregistry. Insurer = generate.InsurerAddresses;
  return assetRegistry.update(RFQregistry);
  })
}

I'm using online playground. Submitting this transaction gives me an error:

Could not find any functions to execute for transaction org.acme.mynetwork.GenerateRFQ#ae28a855-ba3c-48fe-9404-291ad95b24c7

I've tried changing its name but still no good. However SampleTransaction business logic is working fine.

回答1:

your problem is that you have not modeled a transaction (in your .cto file) called GenerateRFQ as in: org.acme.mynetwork.GenerateRFQ in your decorator.

So add the following (below) to your model file - then do a composer network update to update your business network (and chaincode) to recognise the newly modeled transaction (that you call in your script).

transaction GenerateRFQ {
 ...add your model elements or relationships here
}

There is one issue I noticed in your script (which needs to be under the /lib subdirectory of your network project). You assign a new Date() - this is non-deterministic code, so each peer that would execute this will execute the 'date' function and get a different timestamp.

Also - other things that you may wish to consider - (based on the model you posted here):

Clients should be a relationship to Broker - see a sample network here -> https://github.com/hyperledger/composer-sample-networks/blob/master/packages/trade-network/models/trading.cto for an example of relationships. There may be in fact more relationships to consider in your model (eg one to many etc). Lastly your transaction should ideally have a relationship back to the participants and assets that are being 'referenced' in your code (eg. Client, Insurer etc). Again, look at the model file link I sent you to get an idea - also look at the other samples here -> https://github.com/hyperledger/composer-sample-networks/tree/master/packages for pointers and review the model language guide here -> https://hyperledger.github.io/composer/unstable/reference/cto_language.html