对于返回多个值的查询,我需要一个示例事务包装器

时间:2019-05-15 14:56:30

标签: javascript transactions

我有一个返回多个资产的查询。

我需要一个示例事务包装器来显示结果。

我能想到的一切,首先尝试一下(做查询)。我已经用尽了我的Google Fu,这些示例似乎还不能很好地涵盖这一点。我看过driverfines和其他示例。

query getCattleForOwner {

description: "Select all cattle for farmer"

statement:

SELECT org.example.hooftotable.Cattle

WHERE (Farmer == _$owner)

}

针对资产和参与者:

abstract asset Animal identified by animalId {

 o String animalId

 --> Owner owner

 o String sex

 o String breed

 o Double acquireweight

 o DateTime dateexpiry

 o Double currweight optional

 // animal can be born or bought

 o DateTime dob

 o DateTime acquiredate optional

 // animal can be sold or killed

 o DateTime killdate optional

 o String killreason optional

 o DateTime dateshipped optional

 o DateTime datereceived optional

 // animals are usually ided by an eartag

 o String eartag

 // animals are sold by the pound

 o Double priceperpound optional

 // processor usually charge by animal/weight

 --> Transporter transporter optional

 o String typeoffeed

 o String grade optional

 --> Processor processor optional

 o Double processingfee optional

 o DateTime processingdate optional

 o Double wasteweight optional

 o Boolean processed default = false

}

asset Cattle extends Animal {

o String type default = 'Beef'

o Boolean dehorned default = false

o Boolean castrated default = false

}

abstract participant Owner identified by ownerid {

o String ownerid

o String firstname

o String lastname

o String street

o String streetaddress

o String city

o String state

o String zip

o String phone

}

participant Farmer extends Owner {

 o String type default = 'Farmer'

// animals for sale are from registered farmers

o String farmregcode

}

并且正在尝试使用此事务包装器:

async function CallgetCattleforOwner(owner) {

const cattle = [];

const cattleRegistry = await

getAssetRegistry('org.example.hooftotable.Cattle);

const results = await query('getCattleforOwner', {owner:'tx.owner'});

for (let n = 0; n < results.length; n++) {

let cattle = results[n];}

通过超级账本游乐场使用以下方式提交:

{
"$class": "org.example.hooftotable.CallgetCattleforOwner",
"owner":"resource:org.example.hooftotable.Farmer#XdyQXV3k0Z239wuv"
}

产生的错误是:

错误:ID为'$ sysregistries'的集合中ID为'Asset:org.sample.hooftotable.Cattle'的对象不存在

我想获取特定农民拥有的,尚未经过处理且未因其他原因被杀死的牛的清单。我希望将其显示在作曲家游乐场中,并最终显示在前端。

我已将交易修改为:

   async function CallgetCattleforOwner (owner){
      var x = 0;
      return getAssetRegistry('org.example.hooftotable.Cattle')
      .then(function (assetRegistry) {
        return query('getCattleForOwner',{'owner':owner})
        .then (function (results) {
          x = results.length;
          for (var n = 0; n < results.length; n++) {
            var cattle = results[n];
            var QueryCattle = getFactory().newEvent('org.example.hooftotable','QueryCattle');
            QueryCattle.cattle = cattle;
            emit(QueryCattle);
            console.log(QueryCattle);
          }
        });
               });
      console.log(x);
    }

现在它可以正确执行,但是也不产生任何事件,如何从console.log调用中看到结果?

0 个答案:

没有答案