Raj Saraf
Raj Saraf

Reputation: 59

How does Hyperledger composer enforce validity of transaction inputs?

In my application, my transaction is modeled as follows:

transaction Invoice {
    o String invoiceNumber
    o DateTime invoiceDt
    o Double amount
    o Integer creditPeriod
    o String poNumber

  --> Buyer buyer
  --> Seller seller 
}

I want to make sure that buyer and seller are present in Buyer/Seller registry

When I test in Composer, even when buyer in transaction is not present in the buyer registry, transaction is still committed.

Any help is highly appreciated.

Thanks & regards...

Upvotes: 1

Views: 129

Answers (1)

Paul O'Mahony
Paul O'Mahony

Reputation: 6740

So the check to see if you actually have a Buyer and/or Seller is up to you to check in your transaction logic explicitly - we don't enforce it per se. Ideally, you would do the check for both being set, before you submit() the transaction?

But the answer in the TP function, would be to throw an error in your chain - then the transaction would not be committed !

eg.

 // and catch any exceptions that are triggered
      .catch(function (error) {
          throw error;
});

Upvotes: 1

Related Questions