如何在 Hyperledger Fabric 中更新资产之前检查条件

山塔努

我正在尝试在更新资产之前使用 if 条件检查条件。但我不能这样做。我需要检查房产是否存在,以及用户的账户余额是否超过房产的市场价格。

我已尝试使用我所知道的所有类型的选项。但我是新手,因此无法解决问题。如果我只尝试检查该属性是否存在,则它可以正常工作。但是当我尝试检查平衡条件时,它会出现问题。

模型.cto

/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* This namespace helps in idetifying the entities for the network. */
namespace org.example.property

/* Asset Property identified by a striing PID
This is used to maintain the properties which are registered in the system.
*/

asset Property identified by PID {
o String PID
o String owner
o Integer mktprice
o String RegistrationDate
o String PropertyType
o String Location
o String Status default = "Registered"
o Boolean Public
o Boolean Private
o Boolean IntentOfSale

}

/* Asset PropertyListing identified by a striing PLID
This is used to maintain the properties which are listed for sale in the system.
*/
asset PropertyListing identified by PLID {

o String PLID
o String owner
o Integer mktprice
o String RegistrationDate
o String PropertyType
o String Location
o String Status default = "Intent Of Sale"
}

/* Participant Buyer identified by a striing Bname
This is used to maintain the buyers who are part of the system.
*/ 
participant Buyer identified by Bname {
o String Bname
o String Bemail
o Integer IdentityNo //Passport, SSN, Aadhar etc.
o String Bnkname
o String Bnkaddress
o Integer AccNo
o String IFSC
o Integer Balance
}

/* Participant Seller identified by a striing Sname
This is used to maintain the sellers who are part of the system.
*/ 
participant Seller identified by Sname {
o String Sname
o String Semail
o Integer IdentityNo
o String Bnkname
o String Bnkaddress
o Integer AccNo
o String IFSC
o Integer Balance
o String SaleDeedDocs
}

/* Participant Registrar identified by a striing Rname
This is used to maintain the registrar who are part of the system.
*/ 
participant Registrar identified by Rname {
o String Rname 
o String Remail
}

/* Transaction Created
This is used to add new properties in the system.
*/ 
transaction Created {
o String PID
--> Property cproperty
}

transaction Registered {
o String PID
--> PropertyListing rpropertylisting
--> Buyer rbuyer
}

transaction IntentForSale { 
--> Property iproperty
--> PropertyListing ipropertylisting
--> Seller iseller  
}

脚本.js

/**
* Transaction Created to add the new property in the system
* @param {org.example.property.Registered} tx3
* @transaction
*/

async function Registered(tx3) {
   const propertynamespace = 'org.example.property';
   const factory = getFactory();
   var updateOwner;
   var buyerBalance = tx3.rbuyer.Balance;
   var marketPrice = tx3.rpropertylisting.mktprice;

  return getAssetRegistry(propertynamespace + '.Property')
      .then(function(assetRegistry){
       return assetRegistry.exists(tx3.PID);

     })
     return getParticipantRegistry(propertynamespace + '.Buyer')
        .then(function (participantRegistry) {
         // Get the specific driver from the driver participant registry.
        return participantRegistry.get(tx3.rbuyer.Bname);
     })

      .then(function(exists){


       if(exists && buyerBalance > marketPrice){

          return getAssetRegistry(propertynamespace + '.Property')                       
                    .then(function(assetRegistry2){                               
                    return assetRegistry2.get(tx3.PID);
          })
          .then(function(updateProperty){
                        updateOwner = updateProperty 
                        updateOwner.owner = tx3.rbuyer.Bname;
                        updateOwner.Status = "Registered";


                        return getAssetRegistry(propertynamespace + '.Property')


                })
                .then(function(assetRegistry3){
                        return assetRegistry3.update(updateOwner);
                })
       }

     else{
    console.log('Property doesnot exists')
  }

  })
}

它应该更新财产的所有者和状态。

山塔努

看起来问题出在exists函数上。由于传递了错误的参数。

脚本.js

async function Registered(tx3) {

  //Getting the namespace and factory 
  const factory = getFactory();
  const propertynamespace = 'org.example.property';

 //Checking if property exists
 return getAssetRegistry(propertynamespace + '.Property')
      .then(function(assetRegistry){
       return assetRegistry.exists(tx3.PID);
 })

  .then(function(exists){
  //Creating the condition if property exists
  if(exists && tx3.rbuyer.Balance > tx3.rpropertylisting.mktprice){

      //updating property
     const property = factory.newResource(propertynamespace, 'Property', tx3.PID);
     property.owner = tx3.rbuyer.Bname;
     property.mktprice = tx3.rpropertylisting.mktprice;
     property.RegistrationDate = tx3.rpropertylisting.RegistrationDate;
     property.PropertyType = tx3.rpropertylisting.PropertyType;
     property.Location = tx3.rpropertylisting.Location;
     property.Status = "Registered";
     //Setting the flags
     property.Public = true;
     property.Private = false;
     property.IntentOfSale = false;

     //Getting asset registry
     return getAssetRegistry(propertynamespace + '.Property')
     //Saving property
    .then(function(assetRegistry3){
        return assetRegistry3.update(property);
    })
     }
   //Creating condition if property dosent exist  
  else{
    console.log('Property does not exist');
  }
 })
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我如何在Hyperledger Fabric中获得唯一的ID

来自分类Dev

如何在 Hyperledger Fabric 中创建新块

来自分类Dev

Hyperledger Fabric 中的 GOPATH

来自分类Dev

Hyperledger Fabric 1.4:我们如何定义资产?

来自分类Dev

如何对Hyperledger Fabric进行审核?

来自分类Dev

Hyperledger Fabric 中的事务回滚是如何工作的?

来自分类Dev

如何在Hyperledger Fabric测试网络中配置第三方CA?

来自分类Dev

Hyperledger Fabric 如何在非权限网络和权限网络中设置Auditor

来自分类Dev

如何使用grafana监视Hyperledger Fabric网络?

来自分类Dev

Hyperledger Fabric安全性如何?

来自分类Dev

如何使用 Hyperledger Fabric 部署链代码?

来自分类Dev

Hyperledger Fabric 更新分类帐失败

来自分类Dev

是否在HyperLedger Fabric中挖掘块?

来自分类Dev

查看Hyperledger Fabric中的区块链块

来自分类Dev

在Hyperledger Fabric中评估生产网络

来自分类Dev

Hyperledger Fabric网络中的Chaincode问题

来自分类Dev

在 Hyperledger Fabric 中创建通道失败

来自分类Dev

Hyperledger Fabric 中的对等通道创建失败

来自分类Dev

从 Hyperledger Fabric 交易中检索结果

来自分类Dev

Hyperledger Fabric 中的多主机连接

来自分类Dev

在 Hyperledger Fabric 中,什么是组织和对等?

来自分类Dev

对等节点在 Hyperledger Fabric 中崩溃后如何检索旧数据?

来自分类Dev

在Hyperledger Fabric中更新证书后会发生什么?

来自分类Dev

如何在 hyperledger composer 中管理我的资产?

来自分类Dev

Hyperledger fabric Crypto materials

来自分类Dev

Hyperledger Fabric的ChannelCreationPolicy

来自分类Dev

Hyperledger Fabric 通道

来自分类Dev

如何使用Hyperledger Fabric Network SDK查询Chaincode Metada

来自分类Dev

Hyperledger Fabric EVM如何从公钥生成地址?

Related 相关文章

  1. 1

    我如何在Hyperledger Fabric中获得唯一的ID

  2. 2

    如何在 Hyperledger Fabric 中创建新块

  3. 3

    Hyperledger Fabric 中的 GOPATH

  4. 4

    Hyperledger Fabric 1.4:我们如何定义资产?

  5. 5

    如何对Hyperledger Fabric进行审核?

  6. 6

    Hyperledger Fabric 中的事务回滚是如何工作的?

  7. 7

    如何在Hyperledger Fabric测试网络中配置第三方CA?

  8. 8

    Hyperledger Fabric 如何在非权限网络和权限网络中设置Auditor

  9. 9

    如何使用grafana监视Hyperledger Fabric网络?

  10. 10

    Hyperledger Fabric安全性如何?

  11. 11

    如何使用 Hyperledger Fabric 部署链代码?

  12. 12

    Hyperledger Fabric 更新分类帐失败

  13. 13

    是否在HyperLedger Fabric中挖掘块?

  14. 14

    查看Hyperledger Fabric中的区块链块

  15. 15

    在Hyperledger Fabric中评估生产网络

  16. 16

    Hyperledger Fabric网络中的Chaincode问题

  17. 17

    在 Hyperledger Fabric 中创建通道失败

  18. 18

    Hyperledger Fabric 中的对等通道创建失败

  19. 19

    从 Hyperledger Fabric 交易中检索结果

  20. 20

    Hyperledger Fabric 中的多主机连接

  21. 21

    在 Hyperledger Fabric 中,什么是组织和对等?

  22. 22

    对等节点在 Hyperledger Fabric 中崩溃后如何检索旧数据?

  23. 23

    在Hyperledger Fabric中更新证书后会发生什么?

  24. 24

    如何在 hyperledger composer 中管理我的资产?

  25. 25

    Hyperledger fabric Crypto materials

  26. 26

    Hyperledger Fabric的ChannelCreationPolicy

  27. 27

    Hyperledger Fabric 通道

  28. 28

    如何使用Hyperledger Fabric Network SDK查询Chaincode Metada

  29. 29

    Hyperledger Fabric EVM如何从公钥生成地址?

热门标签

归档