Contract + GPS Sub-Machine Coordination
Fuel Contract • draft
Create the main fuel contract state machine. This will track the entire delivery workflow from draft to settlement.
{
"contractId": "FC-2025-001",
"buyer": "DAG3oEy...BMUXe",
"fuelType": "Diesel",
"fuelQuantity": 5000,
"pricePerLiter": 2,
"status": "draft"
}Not created yet
Steps 5, 7, 11: Contract reads GPS state using machines.{gpsTrackerCid}.state.status
Steps 8-10: GPS submits 3 separate ProcessFiberEvent messages with eventType="log_position", staying in "tracking" state while accumulating data (dataPointCount: 1→2→3→4)
Step 12: Contract copies totalDistance (15.9 km) and gpsDataPoints (4) from GPS machine into its state
Step 13: Settlement calculates totalAmount = fuelQuantity * pricePerLiter using JSON Logic
What happens if we try to confirm delivery without enough GPS data points?
GPS status === "stopped" AND dataPointCount >= 3
"stopped" === "stopped" ✓ AND 2 >= 3 ✗
Result: GUARD FAILS ✗Result: The transition from "in_transit" to "delivered" is BLOCKED. The contract cannot proceed to delivery confirmation until GPS has logged at least 3 position updates. This ensures the delivery route is properly tracked before payment is authorized.