JavaScript文件新版本的hypeledger作曲家(最新)

时间:2018-03-29 17:10:17

标签: javascript hyperledger hyperledger-composer

Hyperledger Composer,请帮我将旧版本的JavaScript事务处理器(文件.js)转换为新版本(最新)。我想更新我的代码以使用新语法。

这是我的代码(旧版本)

function sampleTransaction(tx) {

    // Update the asset with the new value.
    tx.asset.value = tx.newValueSample;
    tx.test.value = tx.newalueTest;;

    return getParticipantRegistry('org.acme.sample.SampleParticipant')
          .then(function (assetParticipant) {

          })
          .then(function () {
              return getAssetRegistry('org.acme.sample.TestAsset');
          })
          .then(function (testRegistry) {
              // Update the asset in the asset registry.
              return testRegistry.update(tx.test);
          })
          .then(function () {
              return getAssetRegistry('org.acme.sample.SampleAsset');
          })
          .then(function (assetRegistry) {
              // Update the asset in the asset registry.
              return assetRegistry.update(tx.asset);
          });
}

下面是新版本中的示例代码。

async function tradeCommodity(trade) {
    trade.commodity.owner = trade.newOwner;
    let assetRegistry = await getAssetRegistry('org.acme.mynetwork.Commodity');
    await assetRegistry.update(trade.commodity);
}

1 个答案:

答案 0 :(得分:0)

async function sampleTransaction(tx) {

   // Update the asset with the new value.
   tx.asset.value = tx.newValueSample;
   tx.test.value = tx.newalueTest;

   let assetParticipant = await getParticipantRegistry('org.acme.sample.SampleParticipant');
   // assetParticipant isn't used but I left it in anyway

   let testRegistry = await getAssetRegistry('org.acme.sample.TestAsset'); 
   await testRegistry.update(tx.test);
   let assetRegistry = await getAssetRegistry('org.acme.sample.SampleAsset');
   await assetRegistry.update(tx.asset);
}