0

my issue is that I am defining transaction in model file and then using it in js script but it throws an error " Error: Could not find any functions to execute for transaction." when i try to execute.It occurs during testing of the code

my mode file /** * New model file */

/**
 * New model file
 */

namespace org.acme.bank

participant accountholder identified by bankid
{
  o String bankid
  o String firstname
  o String lastname
  o String address
}

asset acount identified by accno
{
  o String accno
  o String balance 
  -->accountholder customer1
}

transaction amountTransfer 
{
  o String tid
  o String amount
  -->acount owner1
  -->acount owner2

}

my script.js

   /**
* Track the trade of a commodity from one trader to another
* @param {org.acme.bank.amountTransfer} Transfer - to trade
* @transactiton
 */
function Transfer(Transfer)
{
  var amount1=Transfer.owner1.balance
  var amount2=Transfer.owner2.balance
if(Transfer.amount>amount1)
{
  return 0;
}else
{
  owner1.balance-=Transfer.amount
   owner2.balance+=Transfer.amount

  return getAssetRegistry('org.acme.bank.acount')
    .then(function (assetRegistry) {
        return assetRegistry.update(Transfer.owner1);
    }).then(function () {
        return getAssetRegistry('org.acme.bank.acount');
    }).then(function (assetRegistry) {
        return assetRegistry.update(Transfer.owner2);
    });
}  
  }

thank you in advance

1 Answers1

0

I found a tiny typo @transactiton in my script.js and I changer it then the error no longer occurs.

I think the code below works as you expected.

  /**
* Track the trade of a commodity from one trader to another
* @param {org.acme.bank.amountTransfer} Transfer - to trade
* @transaction
 */

function Transfer(Transfer)
{
  var amount1=Transfer.owner1.balance
  var amount2=Transfer.owner2.balance
if(Transfer.amount>amount1)
{
  return 0;
}else
{
  var owner1 =  Transfer.owner1
  var owner2 =  Transfer.owner2
  owner1.balance-=Transfer.amount
  owner2.balance+=Transfer.amount

  return getAssetRegistry('org.acme.bank.acount')
    .then(function (assetRegistry) {
        return assetRegistry.update(owner1);
    }).then(function () {
        return getAssetRegistry('org.acme.bank.acount');
    }).then(function (assetRegistry) {
        return assetRegistry.update(owner2);
    });
}  
  }

Now balance and amount field's type in your model are changed to Integer.

S.Skmt
  • 187
  • 1
  • 11