This repository was archived by the owner on Jan 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
adding contract for compliency with v1.1 of the spec #123
Merged
manojgop
merged 2 commits into
hyperledger-archives:master
from
iExecBlockchainComputing:contracts-proxy-model
Oct 12, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
examples/common/python/connectors/ethereum/contracts/proxy-model/WorkOrderRegistry.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* Copyright 2019 iExec Blockchain Tech | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
pragma solidity ^0.5.0; | ||
|
||
contract WorkOrderRegistry | ||
{ | ||
bytes4 constant VERSION = 0x01010000; // 1.1.0.0 | ||
|
||
enum WorkOrderStatus | ||
{ | ||
NULL, | ||
ACTIVE, | ||
COMPLETED, | ||
FAILED | ||
} | ||
|
||
struct WorkOrder | ||
{ | ||
uint256 status; | ||
uint256 timestamp; | ||
bytes32 workerID; | ||
bytes32 requesterID; | ||
string request; | ||
string response; | ||
} | ||
|
||
// workOrderID → workOrder | ||
mapping(bytes32 => WorkOrder) m_workorders; | ||
|
||
event workOrderSubmitted( | ||
bytes32 indexed workOrderId, | ||
bytes32 indexed workerId, | ||
bytes32 indexed requesterId, | ||
string workOrderRequest, | ||
uint256 errorCode, | ||
address senderAddress, | ||
bytes4 version); | ||
|
||
event workOrderCompleted( | ||
bytes32 requesterId, | ||
bytes32 workOrderId, | ||
uint256 workOrderStatus, | ||
string workOrderResponse, | ||
uint256 errorCode, | ||
bytes4 version); | ||
|
||
constructor() | ||
public | ||
{} | ||
|
||
function workOrderSubmit( | ||
bytes32 _workOrderID, | ||
bytes32 _workerID, | ||
bytes32 _requesterID, | ||
string memory _workOrderRequest) | ||
public returns ( | ||
uint256 errorCode | ||
) { | ||
WorkOrder storage wo = m_workorders[_workOrderID]; | ||
|
||
errorCode = (wo.status == uint256(WorkOrderStatus.NULL)) ? 0 : 1; | ||
|
||
if (errorCode == 0) | ||
{ | ||
wo.status = uint256(WorkOrderStatus.ACTIVE); | ||
wo.timestamp = now; | ||
wo.workerID = _workerID; | ||
wo.requesterID = _requesterID; | ||
wo.request = _workOrderRequest; | ||
} | ||
|
||
emit workOrderSubmitted( | ||
_workOrderID, | ||
_workerID, | ||
_requesterID, | ||
_workOrderRequest, | ||
errorCode, | ||
msg.sender, | ||
VERSION); | ||
|
||
return errorCode; | ||
} | ||
|
||
function workOrderComplete( | ||
bytes32 _workOrderID, | ||
string memory _workOrderResponse | ||
) public returns ( | ||
uint256 errorCode | ||
) { | ||
WorkOrder storage wo = m_workorders[_workOrderID]; | ||
|
||
errorCode = (wo.status == uint256(WorkOrderStatus.ACTIVE)) ? 0 : 1; | ||
|
||
if (errorCode == 0) | ||
{ | ||
wo.status = uint256(WorkOrderStatus.COMPLETED); | ||
wo.response = _workOrderResponse; | ||
} | ||
|
||
emit workOrderCompleted( | ||
wo.requesterID, | ||
_workOrderID, | ||
wo.status, | ||
wo.response, | ||
errorCode, | ||
VERSION); | ||
|
||
return errorCode; | ||
} | ||
|
||
function workOrderGet( | ||
bytes32 _workOrderID | ||
) public view returns ( | ||
uint256 status, | ||
bytes32 workerID, | ||
string memory request, | ||
string memory response, | ||
uint256 errorCode | ||
) { | ||
WorkOrder storage wo = m_workorders[_workOrderID]; | ||
return ( | ||
wo.status, | ||
wo.workerID, | ||
wo.request, | ||
wo.response, | ||
0); | ||
} | ||
|
||
} |
142 changes: 142 additions & 0 deletions
142
examples/common/python/connectors/ethereum/contracts/proxy-model/WorkerRegistry.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* Copyright 2019 iExec Blockchain Tech | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
pragma solidity ^0.5.0; | ||
|
||
contract WorkerRegistry | ||
{ | ||
enum WorkerStatus | ||
{ | ||
NULL, | ||
ACTIVE, | ||
OFFLINE, | ||
DECOMMISSIONED, | ||
COMPROMISED | ||
} | ||
|
||
struct Worker | ||
{ | ||
uint256 status; | ||
uint256 workerType; | ||
bytes32 organizationId; | ||
bytes32[] appTypeIds; | ||
string details; | ||
} | ||
|
||
// WorkerID → Worker | ||
mapping(bytes32 => Worker) private m_workers; | ||
|
||
// workerType → organizationId → appTypeId → WorkerID[] | ||
mapping(uint256 => mapping(bytes32 => mapping(bytes32 => bytes32[]))) m_workersDB; | ||
|
||
constructor() | ||
public | ||
{} | ||
|
||
function workerRegister( | ||
bytes32 workerID, | ||
uint256 workerType, | ||
bytes32 organizationId, | ||
bytes32[] memory appTypeIds, | ||
string memory details | ||
) public { | ||
Worker storage worker = m_workers[workerID]; | ||
|
||
require(worker.status == uint256(WorkerStatus.NULL)); | ||
worker.status = uint256(WorkerStatus.ACTIVE); | ||
worker.workerType = workerType; | ||
worker.organizationId = organizationId; | ||
worker.appTypeIds = appTypeIds; | ||
worker.details = details; | ||
|
||
require(workerType != uint256(0)); | ||
require(organizationId != bytes32(0)); | ||
m_workersDB[uint256(0)][bytes32(0) ][bytes32(0)].push(workerID); | ||
m_workersDB[workerType][bytes32(0) ][bytes32(0)].push(workerID); | ||
m_workersDB[uint256(0)][organizationId][bytes32(0)].push(workerID); | ||
m_workersDB[workerType][organizationId][bytes32(0)].push(workerID); | ||
|
||
for (uint256 p = 0; p < appTypeIds.length; ++p) | ||
{ | ||
require(appTypeIds[p] != bytes32(0)); | ||
m_workersDB[uint256(0)][bytes32(0) ][appTypeIds[p]].push(workerID); | ||
m_workersDB[workerType][bytes32(0) ][appTypeIds[p]].push(workerID); | ||
m_workersDB[uint256(0)][organizationId][appTypeIds[p]].push(workerID); | ||
m_workersDB[workerType][organizationId][appTypeIds[p]].push(workerID); | ||
} | ||
} | ||
|
||
function workerUpdate( | ||
bytes32 workerID, | ||
string memory details | ||
) public { | ||
require(m_workers[workerID].status != uint256(WorkerStatus.NULL)); | ||
m_workers[workerID].details = details; | ||
} | ||
|
||
function workerSetStatus( | ||
bytes32 workerID, | ||
uint256 status | ||
) public { | ||
require(m_workers[workerID].status != uint256(WorkerStatus.NULL)); | ||
require(status != uint256(WorkerStatus.NULL)); | ||
m_workers[workerID].status = status; | ||
} | ||
|
||
function workerLookUp( | ||
uint256 workerType, | ||
bytes32 organizationId, | ||
bytes32 appTypeId | ||
) public view returns( | ||
uint256 totalCount, | ||
uint256 lookupTag, | ||
bytes32[] memory ids | ||
) { | ||
return workerLookUpNext(workerType, organizationId, appTypeId, 0); | ||
} | ||
|
||
function workerLookUpNext( | ||
uint256 workerType, | ||
bytes32 organizationId, | ||
bytes32 appTypeId, | ||
uint256 /*lookUpTag*/ | ||
) public view returns( | ||
uint256 totalCount, | ||
uint256 newLookupTag, | ||
bytes32[] memory ids | ||
) { | ||
bytes32[] storage matchs = m_workersDB[workerType][organizationId][appTypeId]; | ||
return (matchs.length, 0, matchs); | ||
} | ||
|
||
function workerRetrieve( | ||
bytes32 workerID | ||
) public view returns ( | ||
uint256 status, | ||
uint256 workerType, | ||
bytes32 organizationId, | ||
bytes32[] memory appTypeIds, | ||
string memory details | ||
) { | ||
Worker storage worker = m_workers[workerID]; | ||
return ( | ||
worker.status, | ||
worker.workerType, | ||
worker.organizationId, | ||
worker.appTypeIds, | ||
worker.details | ||
); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From #72:
s/appTypeId/appTypeIds/
(I see no appTypeId here, only appTypeIds)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appTypeIds
are arrays ofappTypeId
to make worker searcheable by invididual appTypeId, we have to split the set of supported appTypeIds and enter as many entries in this multidimensional mapping.
workerRegister
's code should show that clearly