-
Notifications
You must be signed in to change notification settings - Fork 128
Description
I am attempting to refactor the perishable-goods template to use a stateful architecture as requested in issue #126. The goal being, to initialize the contract state with sentinel values and incrementally track sensor readings.
I checked the local environment and verified I am running @accordproject/ergo-compiler@0.22.2.
Problem:
Since the compiler is v0.22.2, I attempted to use the Modern Imports (org.accordproject.runtime, etc.) to match the standard libraries. However, the build fails immediately with a network/dependency error:
Error: Unable to download external model dependency '[https://models.accordproject.org/cicero/contract.cto](https://models.accordproject.org/cicero/contract.cto)'
It appears the CI/Test environment cannot resolve these external URLs.
I already attempted to resolve this using 2 methods:
-
Revert to Local Imports: I tried reverting to the legacy local imports (import org.accordproject.cicero.runtime.*). This bypasses the download error but causes IllegalModelException: Namespace is not defined because the 0.22.2 compiler expects the modern namespaces.
-
State Initialization: I have successfully written the init clause and logic using sentinel values (to avoid null safety issues), but I cannot compile it due to the model loading blocker above.
Please let me know if the logic is correct or not, the temperature & humidity has the -999 workaround because the compiler was not accepting comparisons such as min(null, 5.0)
/* logic.ergo */
namespace org.accordproject.perishablegoods
// Modern namespaces (Required for Ergo 0.22.2)
import org.accordproject.runtime.*
import org.accordproject.obligation.*
import org.accordproject.time.*
import org.accordproject.money.*
contract PerishableGoods over PerishableGoodsContract state PerishableGoodsState {
// Init Clause to set Sentinel Values (Avoiding null issues)
clause init(request : Request) : Response {
set state PerishableGoodsState{
stateId: "org.accordproject.perishablegoods.PerishableGoodsState",
status: CREATED,
minTemperatureRecorded: 999.0,
maxTemperatureRecorded: -999.0,
minHumidityRecorded: 999.0,
maxHumidityRecorded: -999.0
};
return Response{}
}
clause ingestReading(request : SensorReading) : SensorReadingResult {
// Standard state updates
if (request.centigrade < state.minTemperatureRecorded)
then set state.minTemperatureRecorded = request.centigrade
else set state.minTemperatureRecorded = state.minTemperatureRecorded;
// ... (rest of logic for Max Temp, Humidity, etc)
return SensorReadingResult{}
}
}
Is there a recommended way to reference the standard org.accordproject.* models locally in this repo without triggering the external download? The current setup seems to trap me between "Unreachable External Models" (Modern) and "Undefined Namespaces" (Legacy).