0

quick question regarding hyperledger fabric transactions in JS.

Say, I have an abstract asset called HotBeverage:

 abstract asset HotBeverage identified by assetId {
  o String assetId
  o Double price
}

And from that abstract class, I create two more assets:

asset HotTea extends HotBeverage {
 o String teaType
}

and

asset HotCoffee extends HotBeverage {
 o String coffeeType
}

OK, fairly straight forward so far. Now say I want to create a transaction that adds 0.50 to the price of all HotBeverages. Transactions currently cannot accept abstract assets, so it means I need to create two separate transactions :'(

transaction changeTeaPrice {
  --> HotTea Tea
  o Double newPrice
}

And

transaction changeCoffeePrice {
  --> HotCoffee coffee
  o Double newPrice
}

I really want to create just one transaction that would work on all HotBeverages instead of implementing them individually. Can this be done?

Thanks!!

mick.lynch
  • 21
  • 6
  • Alternatively, is there a way to find out the AssetType in the chaincode? For example, I create a transaction with a generic asset, then in the chaincode, I can find out if that asset is hotCoffee or hotTea? – mick.lynch Oct 02 '18 at 12:05
  • within a transaction you can use the following: `asset.getType()` `asset.getFullyQualifiedType()` – R Thatcher Oct 02 '18 at 14:10
  • Thanks @RThatcher. I found that just a couple of minutes ago!! Do you know where it is used in an example? When I try to implement it, which asset should be listed in the Transaction? – mick.lynch Oct 02 '18 at 14:21
  • I solved this issue by creating a single transaction and passing to it a string with the fully qualified reference to the asset, rather than the full asset itself. Then in the transaction code, I was able to find that asset in the assetRegistry and implement my code accordingly. – mick.lynch Oct 03 '18 at 08:27

0 Answers0