/** * Copyright 2017–2019, LaborX PTY * Licensed under the AGPL Version 3 license. */ pragma solidity ^0.4.25; import "../common/initializable/InitializableStorageAdapter.sol"; contract WorkflowCore is InitializableStorageAdapter { uint constant internal OK = 1; uint constant internal UPFRONT_PERCENT_PRECISION = 10000; uint constant internal TASK_PENALTY_PERCENT_PRECISION = 10000; /// @dev Indices for task details return values uint constant internal TASK_DETAILS_BUDGET_IDX = 0; uint constant internal TASK_DETAILS_PAID_AMOUNT_IDX = 1; uint constant internal TASK_DETAILS_UPFRONT_AMOUNT_IDX = 2; uint constant internal TASK_DETAILS_WITHDRAW_FEE_AMOUNT = 3; uint constant internal TASK_DETAILS_LENGTH = 4; enum TaskState { NOT_STARTED, STARTED, PAUSED, COMPLETION_REQUESTED, COMPLETION_DECLINED, ///deprecated REWORK_REQUESTED, ///deprecated COMPLETED } /// @dev hash(contractId, contract host address) => boolean StorageInterface.Bytes32BoolMapping internal contractRegistrationsStorage; /// @dev hash(contractId, contract host address) => set of task ids StorageInterface.UIntSetMapping internal taskIdsStorage; /// @dev hash(contractId, contract host address) => total upfront value of all uncompleted tasks in a contract StorageInterface.Bytes32UIntMapping internal tasksUnspentUpfrontStorage; /** TASK */ /// @dev hash(contractId, contract host address, taskId) => TaskState StorageInterface.Bytes32UInt8Mapping internal taskStateStorage; /// @dev hash(contractId, contract host address, taskId) => timestamp StorageInterface.Bytes32UIntMapping internal taskStartedAtStorage; /// @dev hash(contractId, contract host address, taskId) => timestamp StorageInterface.Bytes32UIntMapping internal taskPausedAtStorage; /// @dev hash(contractId, contract host address, taskId) => block when task completion was requested StorageInterface.Bytes32UIntMapping internal taskCompletedAtBlockStorage; /// @dev hash(contractId, contract host address, taskId) => duration StorageInterface.Bytes32UIntMapping internal taskPausedForStorage; /// @dev hash(contractId, contract host address, taskId) => timestamp StorageInterface.Bytes32UIntMapping internal taskFinishedStorage; /// @dev hash(contractId, contract host address, taskId) => upfront payment StorageInterface.Bytes32UIntMapping internal taskUpfrontValueStorage; /// @dev hash(contractId, contract host address, taskId) => budget to pay (left amount after upfront payment) StorageInterface.Bytes32UIntMapping internal taskBudgetLeftValueStorage; /// @dev hash(contractId, contract host address, taskId) => paid budget (amount that has already been paid) StorageInterface.Bytes32UIntMapping internal taskBudgetPaidValueStorage; /// @dev hash(contractId, contract host address, taskId) => timestamp StorageInterface.Bytes32UIntMapping internal taskDeadlineStorage; /** TASK PENALTY */ /// @dev hash(contractId, contract host address, taskId) => set of penalty ids StorageInterface.UIntSetMapping internal penaltyIdsStorage; /// @dev hash(hash(contractId, contract host address, taskId), penaltyId) => PenaltyApplicationType StorageInterface.Bytes32UInt8Mapping internal taskPenaltyApplicationTypeStorage; /// @dev hash(hash(contractId, contract host address, taskId), penaltyId) => amount to penalize StorageInterface.Bytes32UIntMapping internal taskPenaltyValueStorage; /// @dev hash(hash(contractId, contract host address, taskId), penaltyId) => number of blocks after task finishing until penalty is activated StorageInterface.Bytes32UIntMapping internal taskPenaltyPaymentWindowValueStorage; function _initCore() internal { contractRegistrationsStorage.init("contractRegistrations"); taskIdsStorage.init("taskIds"); tasksUnspentUpfrontStorage.init("tasksUnspentUpfront"); taskStateStorage.init("taskState"); taskStartedAtStorage.init("taskStartedAt"); taskPausedAtStorage.init("taskPausedAt"); taskCompletedAtBlockStorage.init("taskCompletedAtBlock"); taskPausedForStorage.init("taskPausedFor"); taskFinishedStorage.init("taskFinished"); taskUpfrontValueStorage.init("taskUpfrontValue"); taskBudgetLeftValueStorage.init("taskBudgetLeftValue"); taskBudgetPaidValueStorage.init("taskBudgetPaidValue"); taskDeadlineStorage.init("taskDeadline"); penaltyIdsStorage.init("penaltyIds"); taskPenaltyApplicationTypeStorage.init("taskPenaltyApplicationType"); taskPenaltyValueStorage.init("taskPenaltyValue"); taskPenaltyPaymentWindowValueStorage.init("taskPenaltyPaymentWindowValue"); } }