通过Hyperledger Composer中的事务进行资产创建 [英] Asset Creation through Transaction in Hyperledger Composer

查看:75
本文介绍了通过Hyperledger Composer中的事务进行资产创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建任何资产参与者时,需要在某些字段上检查某些条件 Like(IF..THEN..ELSE).

While creating any asset or participant need to check some condition Like (IF..THEN..ELSE) on some field.

是否可以通过交易创建资产参与者?

Is it Possible to create Asset or Participant through transaction?

推荐答案

是的.

我在网络中做过同样的事情,通过交易创建资产并应用您需要的任何规则.

I did the same thing in my network, creating assets with a transaction and applying whatever rules you need.

事务是从lib中的logic.js文件运行的.

transactions are run from your logic.js file in lib.

假设您在org.myAssets命名空间中拥有资产myAsset

assume you have an asset myAsset in org.myAssets namespace

asset myAsset identified by assetId
{
  o String assetId
  o String someData
  //other fields as required
}

您现在想要一笔可以创建资产的交易

you now want a transaction which will create an asset

您的CTO交易如下:

namespace org.transactions
import org.myAssets.*

transaction MyAssetCreate
{
  o myAsset anAsset
}

由于您尚无资产,因此您无法在此处引用该资产.

you can't have a reference to the asset here since you won't have an asset yet.

在您的lib/logic.js中,您有类似的东西:

in your lib/logic.js you have something like:

/**
 * creates an asset
 * @param {org.transactions.MyAssetCreate} myAssetCreate 
 * @transaction
 */
async function MyAssetCreate(myAssetCreate) {
    return getAssetRegistry('org.myAssets.myAsset')
    .then(function(result) {
        var factory = getFactory();
        var newAsset = factory.newResource(
        'org.myAssets', 
        'myAsset', 
        myAssetCreate.anAsset.assetId); 
        newAsset.someData = myAssetCreate.anAsset.someData
        //continue with property assignments and any logic you have
        //when you are done and everything looks good you can continue
        return result.add(newAsset);
     });

现在您可以调用MyAssetCreate,您将在正确的注册表中获取资产. 当然,如果这样做,则需要确保您不允许通过标准资产终结点创建资产.

now you can invoke MyAssetCreate and you will get your asset in the right registry. Of course, if you do this then you need to make sure you don't allow assets to be created via the standard asset endpoint.

我本人计划根本不公开任何资产端点,仅允许通过交易进行更改.

I myself plan to not expose any asset endpoints at all and only allow changes via transactions.

检查代码是否有错别字等,我从运行中的网络中删除了该代码,替换了我的类型名称,以便可能我输错了一些内容.

Check the code for typos etc, I took this from my running network, replacing my type names so it's possible I mistyped something.

这篇关于通过Hyperledger Composer中的事务进行资产创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆