-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* administratum: advanced master-worker relations * feat: change onwable => administratable * orders crud * master-worker crud * deals crud * change requests crud * massive market reworking * feat: migrate func added * crud for administratum * fix: cr status bug * fix: counterpartry bid matching * fix: migrate order * rating fields
- Loading branch information
1 parent
8db25ea
commit 514a72c
Showing
20 changed files
with
1,315 additions
and
620 deletions.
There are no files selected for viewing
This file contains 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,87 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
import "zeppelin-solidity/contracts/ownership/Ownable.sol"; | ||
import "./AdministratumCrud.sol"; | ||
|
||
contract Administratum is Ownable { | ||
|
||
// events | ||
event WorkerAnnounced(address indexed worker, address indexed master); | ||
event WorkerConfirmed(address indexed worker, address indexed master, address indexed confirmator); | ||
event WorkerRemoved(address indexed worker, address indexed master); | ||
event AdminAdded(address indexed admin, address indexed master); | ||
|
||
// storage | ||
|
||
mapping(address => mapping(address => bool)) masterRequest; | ||
|
||
AdministratumCrud crud; | ||
|
||
|
||
//constructor | ||
constructor(address _administratumCrud){ | ||
owner = msg.sender; | ||
crud = AdministratumCrud(_administratumCrud); | ||
} | ||
|
||
//funcs | ||
|
||
function RegisterWorker(address _master) public returns (bool) { | ||
require(crud.GetMaster(msg.sender) == msg.sender); | ||
require(!crud.isMaster(msg.sender)); | ||
require(crud.GetMaster(_master) == _master); | ||
masterRequest[_master][msg.sender] = true; | ||
emit WorkerAnnounced(msg.sender, _master); | ||
return true; | ||
} | ||
|
||
function ConfirmWorker(address _worker) public returns (bool) { | ||
require(masterRequest[msg.sender][_worker] == true || IsValid(_worker)); | ||
crud.SetMaster(_worker, msg.sender); | ||
crud.SwitchToMaster(msg.sender); | ||
delete masterRequest[msg.sender][_worker]; | ||
emit WorkerConfirmed(_worker, crud.GetMaster(_worker), msg.sender); | ||
return true; | ||
} | ||
|
||
function RemoveWorker(address _worker, address _master) public returns (bool) { | ||
require(crud.GetMaster(_worker) == _master && (msg.sender == _worker || msg.sender == _master)); | ||
crud.DeleteMaster(_worker); | ||
emit WorkerRemoved(_worker, _master); | ||
return true; | ||
} | ||
|
||
function RegisterAdmin(address _admin) public returns (bool){ | ||
require(GetMaster(msg.sender) == msg.sender); | ||
require(msg.sender != _admin); | ||
crud.SetAdmin(_admin, msg.sender); | ||
return true; | ||
} | ||
|
||
function Migrate (address _newAdministratum) public onlyOwner { | ||
crud.transferOwnership(_newAdministratum); | ||
suicide(msg.sender); | ||
} | ||
|
||
|
||
//INTERNAL | ||
// check if transaction sended by valid admin | ||
function IsValid(address _worker) internal view returns(bool){ | ||
address master = crud.GetAdminMaster(msg.sender); | ||
return master != address(0) && masterRequest[master][_worker] == true; | ||
} | ||
|
||
|
||
//GETTERS | ||
|
||
function GetMaster(address _worker) public view returns (address master) { | ||
return crud.GetMaster(_worker); | ||
} | ||
|
||
|
||
|
||
|
||
//modifiers | ||
|
||
|
||
} |
This file contains 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,60 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
import "./Administratable.sol"; | ||
|
||
contract AdministratumCrud is Administratable { | ||
|
||
// events | ||
event WorkerAnnounced(address indexed worker, address indexed master); | ||
event WorkerConfirmed(address indexed worker, address indexed master); | ||
event WorkerRemoved(address indexed worker, address indexed master); | ||
event AdminAdded(address indexed admin, address indexed master); | ||
|
||
// storage | ||
mapping(address => address) masterOf; | ||
|
||
mapping(address => bool) flagIsMaster; | ||
|
||
mapping(address => mapping(address => bool)) masterRequest; | ||
|
||
//maps admin into its master; alternative method | ||
//that's like asym cryptography, but implemented by design | ||
mapping(address => address) admins; | ||
|
||
//constructor | ||
constructor(){ | ||
owner = msg.sender; | ||
administrator = msg.sender; | ||
} | ||
|
||
function SetMaster(address _worker, address _master) public onlyOwner { | ||
masterOf[_worker] = _master; | ||
} | ||
|
||
function SetAdmin(address _admin, address _master) public onlyOwner { | ||
admins[_admin] = _master; | ||
} | ||
|
||
function DeleteMaster(address _worker) public onlyOwner { | ||
delete masterOf[_worker]; | ||
} | ||
|
||
function SwitchToMaster(address _target) public onlyOwner { | ||
flagIsMaster[_target] = true; | ||
} | ||
|
||
function GetMaster(address _worker) public view returns (address) { | ||
if (masterOf[_worker] == address(0) || flagIsMaster[_worker] == true){ | ||
return _worker; | ||
} | ||
return masterOf[_worker]; | ||
} | ||
|
||
function GetAdminMaster(address _admin) public view returns (address) { | ||
return admins[_admin]; | ||
} | ||
|
||
function isMaster(address _address) public view returns (bool) { | ||
return flagIsMaster[_address]; | ||
} | ||
} |
This file contains 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,128 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
import "./Administratable.sol"; | ||
import "zeppelin-solidity/contracts/math/SafeMath.sol"; | ||
import "./Orders.sol"; | ||
|
||
|
||
contract ChangeRequests is Administratable { | ||
using SafeMath for uint256; | ||
|
||
mapping(uint => ChangeRequest) requests; | ||
|
||
mapping(uint => uint[2]) actualRequests; | ||
|
||
uint requestsAmount; | ||
|
||
struct ChangeRequest { | ||
uint dealID; | ||
Orders.OrderType requestType; | ||
uint price; | ||
uint duration; | ||
RequestStatus status; | ||
} | ||
|
||
enum RequestStatus { | ||
REQUEST_UNKNOWN, | ||
REQUEST_CREATED, | ||
REQUEST_CANCELED, | ||
REQUEST_REJECTED, | ||
REQUEST_ACCEPTED | ||
} | ||
|
||
|
||
constructor() public { | ||
owner = msg.sender; | ||
administrator = msg.sender; | ||
} | ||
|
||
function Write( | ||
uint _dealID, | ||
Orders.OrderType _requestType, | ||
uint _price, | ||
uint _duration, | ||
RequestStatus _status) public onlyOwner returns(uint){ | ||
|
||
requestsAmount = requestsAmount.add(1); | ||
|
||
requests[requestsAmount] = ChangeRequest(_dealID, _requestType, _price, _duration, _status); | ||
|
||
return requestsAmount; | ||
} | ||
|
||
//SETTERS | ||
|
||
function SetChangeRequestDealID(uint _changeRequestID, uint _dealID) public onlyOwner { | ||
requests[_changeRequestID].dealID = _dealID; | ||
} | ||
|
||
function SetChangeRequestType(uint _changeRequestID, Orders.OrderType _type) public onlyOwner { | ||
requests[_changeRequestID].requestType = _type; | ||
} | ||
|
||
function SetChangeRequestPrice(uint _changeRequestID, uint _price) public onlyOwner { | ||
requests[_changeRequestID].price = _price; | ||
} | ||
|
||
function SetChangeRequestDuration(uint _changeRequestID, uint _duration) public onlyOwner { | ||
requests[_changeRequestID].duration = _duration; | ||
} | ||
|
||
function SetChangeRequestStatus(uint _changeRequestID, RequestStatus _status) public onlyOwner { | ||
requests[_changeRequestID].status = _status; | ||
} | ||
|
||
function SetActualChangeRequest(uint dealID, uint role, uint _changeRequestID) public onlyOwner { | ||
actualRequests[dealID][role] = _changeRequestID; | ||
} | ||
|
||
// GETTERS | ||
|
||
function GetChangeRequestDealID(uint _changeRequestID) public view returns(uint) { | ||
return requests[_changeRequestID].dealID; | ||
} | ||
|
||
function GetChangeRequestType(uint _changeRequestID) public view returns(Orders.OrderType) { | ||
return requests[_changeRequestID].requestType; | ||
} | ||
|
||
function GetChangeRequestPrice(uint _changeRequestID) public view returns(uint) { | ||
return requests[_changeRequestID].price; | ||
} | ||
|
||
function GetChangeRequestDuration(uint _changeRequestID) public view returns(uint) { | ||
return requests[_changeRequestID].duration; | ||
} | ||
|
||
function GetChangeRequestStatus(uint _changeRequestID) public view returns(RequestStatus) { | ||
return requests[_changeRequestID].status; | ||
} | ||
|
||
function GetActualChangeRequest(uint dealID, uint role)public view returns(uint) { | ||
return actualRequests[dealID][role]; | ||
|
||
} | ||
|
||
function GetChangeRequestsAmount() public view returns(uint) { | ||
return requestsAmount; | ||
} | ||
|
||
function GetChangeRequestInfo(uint changeRequestID) public view | ||
returns ( | ||
uint dealID, | ||
Orders.OrderType requestType, | ||
uint price, | ||
uint duration, | ||
RequestStatus status | ||
) { | ||
return ( | ||
requests[changeRequestID].dealID, | ||
requests[changeRequestID].requestType, | ||
requests[changeRequestID].price, | ||
requests[changeRequestID].duration, | ||
requests[changeRequestID].status | ||
); | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.