Search code examples
hyperledger-fabrichyperledgerblockchainhyperledger-composer

"Error: Could not find any functions to execute for transaction"


I'm building a network that allows "Hospitals" add themselves with their public keys and datahashes to the array in "patient" asset, but when I test it gave me

Error: Could not find any functions to execute for transaction

I am using the online composer playground, it's my first time to build a network. I think in this network, I need participant, asset and transaction, I set patient as asset with an array of hospitals, and the PatientHospital is a participant that has data hash and public key, a transaction, and a function that called by this transaction, I don't know where is wrong, but when i test, it returned me below error:

"TypeError: Cannot read property 'state' of undefined"

And

"Error: Could not find any functions to execute for transaction >org.acme.patientchain.AddHospitalToPatient#bdd6ca0b-d0d9-4003-b6c3-05b818b3fc96"

I also tried set the PatientHospital to an asset instead of participant, but still gave same error.

How do I solve this problem?

My model.cto file:

namespace org.acme.patientchain
 asset Patient identified by pubKeyPatient {
  o String pubKeyPatient
  o PatientHospital[] hospitals
}

participant PatientHospital identified by pubKeyHospital {
  o String pubKeyHospital
  o String dataHash
 // --> Hospital hospital
}

transaction AddHospitalToPatient {
  --> Patient patient
  o PatientHospital newHospital

 }

the function in My js file:

function addHospitalToPatient(AddHospitalToPatient){
 AddHospitalToPatient.patient.hospitals.push(AddHospitalToPatient.newHospital);
  return getAssetRegistry('org.acme.patientchain.Patient')
  .then(function (assetRegistry) {
    return assetRegistry.update(patient.hospitals);
  });

}

Solution

  • As per my understanding, you need to update a Patient asset with a new value of PatientHospital participant.

    logic.js changes:

    async function addHospitalToPatient(AddHospitalToPatient){
     AddHospitalToPatient.patient.hospitals.push(AddHospitalToPatient.newHospital);
      return getAssetRegistry('org.acme.patientchain.Patient')
      .then(function (assetRegistry) {
        return assetRegistry.update(AddHospitalToPatient.patient);
      });
    }