我意识到我可以在链代码中发出事件并在节点SDK中侦听这些事件。
但是,我希望能够在创建资产时收到事件,以便我可以采取行动。这可能吗?
另一种选择可能是指定添加资产时调用的函数。
答案 0 :(得分:0)
我可以想到一个解决方法:
示例:
rule CreateAssetOnlyWithTx{
description: "Allow all learners to create and read their own submissions"
participant: "ANY"
operation: CREATE
resource: "org.example.blah.asset"
transaction: "org.example.blah.tx"
action: ALLOW
}
答案 1 :(得分:0)
如果通过事务功能添加资产,则可以在创建事件后立即发出事件。如果资产成功创建FYI,则仅发出事件。点击此处https://hyperledger.github.io/composer/business-network/publishing-events.html
//将车辆添加到资产注册表并发出事件 - 未经过测试。
return getAssetRegistry('org.acme.Vehicle')
.then(function (vehicleAssetRegistry) {
// Get the factory for creating new asset instances.
var factory = getFactory();
// Create the vehicle.
var vehicle = factory.newResource('org.acme', 'Vehicle', 'VEHICLE_1');
vehicle.colour = 'BLUE';
// Add the vehicle to the vehicle asset registry.
return vehicleAssetRegistry.add(vehicle);
})
.catch(function (error) {
// Add optional error handling here. If the transaction fails, no event is emitted please note
})
.then(function() {
var addNotification = getFactory().newEvent('org.acme.trading', 'AddNotification');
addNotification.vehicle = vehicle; // the object passed into the transaction etc etc
emit(addNotification);
})