Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lidangzzz committed Jan 18, 2024
1 parent c59dcae commit 93d30d0
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 195 deletions.
17 changes: 17 additions & 0 deletions darc-protocol/contracts/protocol/Dashboard/Dashboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,24 @@ contract Dashboard is Executable {
return votingItems[idx];
}

/**
* Get the latest voting item index
*/
function getLatestVotingItemIndex() public view returns (uint256) {
return latestVotingItemIndex;
}

/**
* Get the global operation log
*/
function getGlobalOperationLog() public view returns (OperationLog memory) {
return currentMachineState.globalOperationLog;
}

/**
* Get the operation log of the address
*/
function getOperationLogByAddress(address addr) public view returns (OperationLog memory) {
return currentMachineState.operationLogMap[addr];
}
}
44 changes: 22 additions & 22 deletions darc-protocol/contracts/protocol/Plugin/Condition_OperationLog.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract Condition_OperationLog is MachineStateManager {
require(param.UINT256_2DARRAY[0].length == 1, "CE ID_701: The UINT256_2DARRAY[0] length is not 1");
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[op.operatorAddress].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[op.operatorAddress].latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime > param.UINT256_2DARRAY[0][0];
}
Expand All @@ -53,13 +53,13 @@ contract Condition_OperationLog is MachineStateManager {
require(param.UINT256_2DARRAY[0].length == 1, "CE ID_702: The UINT256_2DARRAY[0] length is not 1");
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[op.operatorAddress].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[op.operatorAddress].latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime < param.UINT256_2DARRAY[0][0];
}
else {
// in after operation plugin condition check, check the sandbox machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[op.operatorAddress].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[op.operatorAddress].latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime < param.UINT256_2DARRAY[0][0];
}
Expand All @@ -70,13 +70,13 @@ contract Condition_OperationLog is MachineStateManager {
require(param.UINT256_2DARRAY[0].length == 2, "CE ID_703: The UINT256_2DARRAY[0] length is not 2");
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[op.operatorAddress].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[op.operatorAddress].latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime >= param.UINT256_2DARRAY[0][0] && elapsedTime <= param.UINT256_2DARRAY[0][1];
}
else {
// in after operation plugin condition check, check the sandbox machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[op.operatorAddress].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[op.operatorAddress].latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime >= param.UINT256_2DARRAY[0][0] && elapsedTime <= param.UINT256_2DARRAY[0][1];
}
Expand All @@ -87,13 +87,13 @@ contract Condition_OperationLog is MachineStateManager {
require(param.UINT256_2DARRAY[0].length == 1, "CE ID_704: The UINT256_2DARRAY[0] length is not 1");
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime > param.UINT256_2DARRAY[0][0];
}
else {
// in after operation plugin condition check, check the sandbox machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime > param.UINT256_2DARRAY[0][0];
}
Expand All @@ -104,13 +104,13 @@ contract Condition_OperationLog is MachineStateManager {
require(param.UINT256_2DARRAY[0].length == 1, "CE ID_705: The UINT256_2DARRAY[0] length is not 1");
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime < param.UINT256_2DARRAY[0][0];
}
else {
// in after operation plugin condition check, check the sandbox machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime < param.UINT256_2DARRAY[0][0];
}
Expand All @@ -121,13 +121,13 @@ contract Condition_OperationLog is MachineStateManager {
require(param.UINT256_2DARRAY[0].length == 2, "CE ID_706: The UINT256_2DARRAY[0] length is not 2");
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime >= param.UINT256_2DARRAY[0][0] && elapsedTime <= param.UINT256_2DARRAY[0][1];
}
else {
// in after operation plugin condition check, check the sandbox machine state
uint256 elapsedTime = block.timestamp - sandboxMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.globalOperationLog.latestOperationTimestamp[getOpcodeID(op)];

return elapsedTime >= param.UINT256_2DARRAY[0][0] && elapsedTime <= param.UINT256_2DARRAY[0][1];
}
Expand All @@ -139,15 +139,15 @@ contract Condition_OperationLog is MachineStateManager {
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime > param.UINT256_2DARRAY[0][0]) { return true; }
}
return false;
}
else {
// in after operation plugin condition check, check the sandbox machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime > param.UINT256_2DARRAY[0][0]) { return true; }
}
return false;
Expand All @@ -160,15 +160,15 @@ contract Condition_OperationLog is MachineStateManager {
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime < param.UINT256_2DARRAY[0][0]) { return true; }
}
return false;
}
else {
// in after operation plugin condition check, check the sandbox machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime < param.UINT256_2DARRAY[0][0]) { return true; }
}
return false;
Expand All @@ -181,15 +181,15 @@ contract Condition_OperationLog is MachineStateManager {
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime >= param.UINT256_2DARRAY[0][0] && elapsedTime <= param.UINT256_2DARRAY[0][1]) { return true; }
}
return false;
}
else {
// in after operation plugin condition check, check the sandbox machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime >= param.UINT256_2DARRAY[0][0] && elapsedTime <= param.UINT256_2DARRAY[0][1]) { return true; }
}
return false;
Expand All @@ -202,15 +202,15 @@ contract Condition_OperationLog is MachineStateManager {
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime < param.UINT256_2DARRAY[0][0]) { return false; }
}
return true;
}
else {
// in after operation plugin condition check, check the sandbox machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime < param.UINT256_2DARRAY[0][0]) { return false; }
}
return true;
Expand All @@ -223,15 +223,15 @@ contract Condition_OperationLog is MachineStateManager {
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime > param.UINT256_2DARRAY[0][0]) { return false; }
}
return true;
}
else {
// in after operation plugin condition check, check the sandbox machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime > param.UINT256_2DARRAY[0][0]) { return false; }
}
return true;
Expand All @@ -244,7 +244,7 @@ contract Condition_OperationLog is MachineStateManager {
if (bIsBeforeOperation) {
// in before operation plugin condition check, just check current machine state
for (uint256 i = 0; i < param.ADDRESS_2DARRAY[0].length; i++) {
uint256 elapsedTime = block.timestamp - sandboxMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
uint256 elapsedTime = block.timestamp - currentMachineState.operationLogMap[param.ADDRESS_2DARRAY[0][i]].latestOperationTimestamp[getOpcodeID(op)];
if (elapsedTime < param.UINT256_2DARRAY[0][0] || elapsedTime > param.UINT256_2DARRAY[0][1]) { return false; }
}
return true;
Expand Down
Loading

0 comments on commit 93d30d0

Please sign in to comment.