得到错误:预期资源或概念也检查过较旧的帖子,但它并没有帮助我解决我的代码问题

时间:2018-02-20 07:16:49

标签: javascript blockchain hyperledger-composer

我有两笔交易GoodsMovement和Payment,Goodsmovement将跟踪货物的交付,而付款交易将在货物交付时检查付款。

我正在编写以下代码:

    /**
 * New model file
 */

namespace org.acme.paysystem

enum PaymentStatus{
o PARTIALLY_PAID
o TOTAL_AMOUNT_PAID
o NOT_PAID
}

enum DeliveryStatus{
o DELIVERED
o IN_TRANSIT
}

asset Goods identified by billNo{
  o String billNo
  o Double billAmount
  o DateTime billDate
  o DeliveryStatus deliveryStatus
  o PaymentStatus paymentStatus default = 'NOT_PAID'
}

concept Address{
o String Country optional
o String City optional
o String Street optional
o String Zip optional
}

abstract participant user identified by email{
  o String email
  o String fname
  o String lname
  o Address address
}

participant Retailer extends user {
o String shopNo
o Double amountDue
o Double accountBalance
}

participant Distributor extends user{
o String PAN
o Double bankBalance
}

transaction Payment{
  --> Goods goods
  --> Retailer retailer
  --> Distributor distributor
  o PaymentStatus paymentStatus
}

transaction GoodsMovement {
  --> Goods goods
  o DeliveryStatus deliveryStatus

I haven't mentioned GoodsMovement transaction here since it's working as expected. 

以下是脚本文件:

/**
* @param {org.acme.paysystem.Payment} Payment
* @transaction
*/
function Payment(Payment){
        var paymentRecievedFlag = 0;
        var amountRecieved = 0;
                if(GoodsMovement == 'IN_TRANSIT')
                    {
                         console.log("Goods are IN_TRANSIT");
                    }
          else
          {
            if ((Payment.retailer.accountBalance - Payment.goods.billAmount) > 0 ){
               Payment.retailer.accountbalance -= Payment.goods.billAmount;
               Payment.distributor.bankBalance += Payment.goods.billAmount;

              Payment.paymentStatus = 'TOTAL_AMOUNT_PAID';
              //Payment.goods.paymentStatus = 'TOTAL_AMOUNT_PAID';
          }

            else{
                  Payment.retailer.amountDue = Payment.goods.billAmount - Payment.retailer.accountBalance;
                  Payment.distributor.bankBalance += Payment.retailer.accountBalance;
                  Payment.paymentStatus = PARTIALLY_PAID;
            }}


          return getParticipantRegistry('org.acme.paysystem.Distributor')
               .then(function(distributorRegistry){
                  return distributorRegistry.update(Payment.distributer);
          })
               .then(function(){
                  return getParticipantRegistry('org.acme.paysystem.Retailer');
          })
               .then(function(retailerRegistry){
                  return retailerRegistry.update(Payment.retailer);
          })
                 .then(function(){
                       return getAssetRegistry('org.acme.paysystem.Goods');
          })
                 .then(function(goodsRegistry){
                        return goodsRegistry.update(Payment.goods);
          });       
}

我已经正确检查并通过互联网搜索,但我无法弄清楚我的代码有什么问题。谢谢,如果有人可以帮我解决代码

1 个答案:

答案 0 :(得分:1)

第x行应为:

  if(Payment.goods.deliveryStatus == 'IN_TRANSIT')

第31行应该是:

 return distributorRegistry.update(Payment.distributor);

第18和25行应参考:       Payment.goods.paymentStatus =' TOTAL_AMOUNT_PAID';

不是Payment.paymentStatus

第25行需要引号:       Payment.goods.paymentStatus =' PARTIALLY_PAID';

然后使用此交易 - 它起作用了:

{
  "$class": "org.acme.paysystem.Payment",
  "goods": "resource:org.acme.paysystem.Goods#1",
  "retailer": "resource:org.acme.paysystem.Retailer#a@b.com",
  "distributor": "resource:org.acme.paysystem.Distributor#a@b.com",
  "paymentStatus": "PARTIALLY_PAID"
}