function Exchange(exchange){
// We do the actual exchange here:
// We first need to get both actual nodes:
var nodeIdFrom=exchange.nodeIdFrom;
var quantity =exchange.quantity;
var price = exchange.price;
var nodeIdTo =exchange.nodeIdTo;
return getParticipantRegistry('org.acme.mynetwork.Node')
.then(function(ParticipantRegistry){
ParticipantRegistry.get(nodeIdFrom)
.then(function(Participant){
Participant.Need=Participant.Need+quantity;
Participant.Balance_account=Participant.Balance_account+quantity*price;
return ParticipantRegistry.update(Participant);
});
});我正在尝试执行一个定义为:
transaction Exchange{
o String nodeIdFrom
o String nodeIdTo
o Double quantity
o Double Price
}来执行事务(我们把钱放到另一个地方)。其中只有节点的ids作为参数。
但是现在这个函数不起作用,你可以在操场上执行它,但是我的节点没有被修改。是否可以在不将节点指定为节点的情况下应用事务(节点是参与者)。
发布于 2017-09-19 00:10:58
它应该是有效的-这里有一个例子(使用一个虚构的样本'Trader‘Network,和你一样,我在交易模型定义中将'qty’定义为'Double‘),通过一个特定的标识符(你正在做一些类似的事情--参与者ID)来更新一个资产,然后--使用下面的Promises链来更新资产的数量。建议在调试时也使用console.log()作为输出。
So -给定事务模型:
transaction TraderById {
o String tradeId
o String tradingSymbol
o Double qty
}和一个资产,建模为:
asset Commodity identified by tradingSymbol {
o String tradingSymbol
o String description
o String mainExchange
o Double quantity
--> Trader owner
}您可以按如下方式更新资产数量(‘数量’):
/**
*
* @param {org.acme.trading.TraderById} tradeById - the trade to be processed
* @transaction
*/
function TradeById(tradeById){
var commodityRegistry;
return getAssetRegistry('org.acme.trading.Commodity')
.then(function(registry){
commodityRegistry=registry;
return commodityRegistry.get(tradeById.tradingSymbol);
})
.then(function(result){
result.quantity-=tradeById.qty;
return commodityRegistry.update(result);
});
}https://stackoverflow.com/questions/46262472
复制相似问题