-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: market crud #1565
Merged
Merged
feat: market crud #1565
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
42912bc
administratum: advanced master-worker relations
quasisamurai 8efee2d
tests updated
quasisamurai be1654f
linted
quasisamurai da992f4
remove limit for da contract bytecode length
quasisamurai 1587b79
some refactoring
quasisamurai 3c85c40
feat: migrate func added
quasisamurai a1771a0
some style mistakes fixed
quasisamurai 5e730d6
crud for administratum
quasisamurai cd5b559
and update its migrations
quasisamurai d459acc
and update its tests
quasisamurai e407070
clean
quasisamurai 991089d
fix: cr status bug
quasisamurai fb870b5
fix: counterpartry bid matching
quasisamurai b51d751
fix: migrations order
quasisamurai 0fe57a3
feat: change onwable => administratable
quasisamurai dc07e53
rating fields commited
quasisamurai 4dd15b5
fix tuple err while generating abi
quasisamurai 806b999
optimization enabled back
quasisamurai 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
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); | ||
quasisamurai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is this? |
||
|
||
|
||
} |
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"; | ||
|
||
quasisamurai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
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.
Administratable
orOwnable