From 93efb975c9523055d0f7f75c30d467b8dd8c5ec3 Mon Sep 17 00:00:00 2001 From: Thorsten Zoerner Date: Fri, 19 Jan 2024 02:45:57 +0100 Subject: [PATCH] Feat: Re-implemented auto seal. Auto Seal is an optional parameter to the addSettlement method of balancing. The epoch n-value will be automatically sealed. Useful for meter readings - might be used with other balancing points in the future, but not implemented so far. --- framework/services/balancing.service.js | 24 ++++++++++++++--------- framework/services/loadprofile.service.js | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/framework/services/balancing.service.js b/framework/services/balancing.service.js index 9b31de7..fcf28a8 100644 --- a/framework/services/balancing.service.js +++ b/framework/services/balancing.service.js @@ -230,6 +230,12 @@ module.exports = { } else { await ctx.call("balance_settlements_active_model.insert",{entity:statement}); } + if(typeof ctx.params.autoseal !== 'undefined') { + ctx.call("balancing.seal",{ + assetId:ctx.params.meterId, + epoch:ctx.params.epoch - (1*ctx.params.autoseal) + }); + } } catch(e) { // in case of an exception the settlement needs to be handled manually. // Handle manual settlement in case of an exception @@ -334,7 +340,7 @@ module.exports = { }, }); console.log("Query",{ - "$or": [ { "from": ctx.params.assertId }, { "to": ctx.params.assetId}], + "$or": [ { "from": ctx.params.assetId }, { "to": ctx.params.assetId}], epoch: ctx.params.epoch * 1 }); balance.upstream = await ctx.call("balancing.getUpstream", {assetId: ctx.params.assetId}); @@ -387,7 +393,7 @@ module.exports = { } let intermediateBalance = await ctx.call("balancing.unsealedBalance",ctx.params); - if(intermediateBalance.clearing.energy !== 0) { + if((intermediateBalance.energy !== 0)&&(intermediateBalance.clearing.energy !== 0)){ let statement = { from: intermediateBalance.clearing.from, to:intermediateBalance.clearing.to, @@ -395,19 +401,19 @@ module.exports = { energy: intermediateBalance.clearing.energy, label: ".end" } - await ctx.call("balance_settlements_late_model.insert",{entity:statement}); + await ctx.call("balance_settlements_active_model.insert",{entity:statement}); intermediateBalance = await ctx.call("balancing.unsealedBalance",ctx.params); } - if(intermediateBalance.clearing.energy == 0) { + if((intermediateBalance.energy == 0)||(intermediateBalance.clearing.energy == 0)) { let seal_content = { assetId: ctx.params.assetId, epoch: ctx.params.epoch * 1, - in: intermediateBalance.in, - out: intermediateBalance.out, - energy: intermediateBalance.energy, - upstream: intermediateBalance.upstream + upstream: intermediateBalance.upstream, + balance: intermediateBalance.in, + energy: intermediateBalance.upstreamenergy } - const res = jwt.sign(seal_content, process.env.JWT_SECRET); + const signOptions = JSON.parse(process.env.JWT_OPTIONS); + const res = jwt.sign(seal_content, process.env.JWT_PRIVATEKEY,signOptions); seal_content.seal = res; await ctx.call("balances_sealed_model.insert",{entity:seal_content}); return seal_content; diff --git a/framework/services/loadprofile.service.js b/framework/services/loadprofile.service.js index 1dca051..dc31424 100644 --- a/framework/services/loadprofile.service.js +++ b/framework/services/loadprofile.service.js @@ -85,6 +85,7 @@ module.exports = { await ctx.call("loadprofile_model.insert",{entity:existing}); } // Forward to balancing (asynchronously) + ctx.params.autoseal = 1; // Auto seal for meter readings the previous epoch ctx.call("balancing.addSettlement",ctx.params); return; }