-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef13887
commit 2b00ac3
Showing
2 changed files
with
102 additions
and
0 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,50 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
library LibProperty { | ||
struct Property { | ||
string name; | ||
uint256 propertyType; // 0 = Residential, 1 = Commercial | ||
uint256 workerPoolBalance; // Funds allocated to workers | ||
address owner; | ||
} | ||
|
||
struct PropertyStorage { | ||
mapping(uint256 => Property) properties; | ||
uint256 propertyCounter; | ||
} | ||
|
||
bytes32 constant STORAGE_POSITION = keccak256("gizaprotocol.property.storage"); | ||
|
||
function propertyStorage() internal pure returns (PropertyStorage storage ps) { | ||
bytes32 position = STORAGE_POSITION; | ||
assembly { | ||
ps.slot := position | ||
} | ||
} | ||
} | ||
|
||
contract PropertyFacet { | ||
event PropertyAdded(uint256 indexed propertyId, string name, uint256 propertyType, address owner); | ||
|
||
function addProperty( | ||
string memory _name, | ||
uint256 _propertyType, | ||
address _owner | ||
) external { | ||
LibProperty.PropertyStorage storage ps = LibProperty.propertyStorage(); | ||
ps.properties[ps.propertyCounter] = LibProperty.Property({ | ||
name: _name, | ||
propertyType: _propertyType, | ||
workerPoolBalance: 0, | ||
owner: _owner | ||
}); | ||
emit PropertyAdded(ps.propertyCounter, _name, _propertyType, _owner); | ||
ps.propertyCounter++; | ||
} | ||
|
||
function getProperty(uint256 propertyId) external view returns (LibProperty.Property memory) { | ||
LibProperty.PropertyStorage storage ps = LibProperty.propertyStorage(); | ||
return ps.properties[propertyId]; | ||
} | ||
} |
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,52 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
library LibWorker { | ||
struct Worker { | ||
address wallet; | ||
uint256 contributionShare; // Share of the total contribution | ||
bool isRegistered; | ||
} | ||
|
||
struct WorkerStorage { | ||
mapping(address => Worker) workers; | ||
address[] workerAddresses; | ||
} | ||
|
||
bytes32 constant STORAGE_POSITION = keccak256("gizaprotocol.worker.storage"); | ||
|
||
function workerStorage() internal pure returns (WorkerStorage storage ws) { | ||
bytes32 position = STORAGE_POSITION; | ||
assembly { | ||
ws.slot := position | ||
} | ||
} | ||
} | ||
|
||
contract WorkerFacet { | ||
event WorkerRegistered(address indexed worker, uint256 contributionShare); | ||
|
||
function registerWorker(address _worker, uint256 _contributionShare) external { | ||
LibWorker.WorkerStorage storage ws = LibWorker.workerStorage(); | ||
require(!ws.workers[_worker].isRegistered, "Worker already registered"); | ||
|
||
ws.workers[_worker] = LibWorker.Worker({ | ||
wallet: _worker, | ||
contributionShare: _contributionShare, | ||
isRegistered: true | ||
}); | ||
ws.workerAddresses.push(_worker); | ||
|
||
emit WorkerRegistered(_worker, _contributionShare); | ||
} | ||
|
||
function getWorker(address _worker) external view returns (LibWorker.Worker memory) { | ||
LibWorker.WorkerStorage storage ws = LibWorker.workerStorage(); | ||
return ws.workers[_worker]; | ||
} | ||
|
||
function getAllWorkers() external view returns (address[] memory) { | ||
LibWorker.WorkerStorage storage ws = LibWorker.workerStorage(); | ||
return ws.workerAddresses; | ||
} | ||
} |