Created
November 8, 2022 03:38
-
-
Save luchenqun/7cf8a1d9c60a3ac13f77863bdf05a7c1 to your computer and use it in GitHub Desktop.
ProjectManager
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
contract ProjectManager { | |
// 算力资源 | |
struct ComputeRes { | |
int256 id; | |
int256 tid; // 领取的任务id | |
address owner; | |
int256 status; | |
int256 ctype; // 算力类型:处理视频,处理音频,图像识别..... | |
int256[] pows; | |
} | |
// 任务 | |
struct Task { | |
int256 id; | |
int256 cid; // 被哪个算力领取了 | |
string name; | |
string desc; | |
string resPath; // 资源路径 | |
string params; // 参数 | |
int256 status; // 状态 | |
int256 ctype; // 需要的算力类型 | |
// address nft; ? | |
int256[] powRequires; // 比如索引0代表cpu个数, 1代表内存多少G,不同算力类型每个索引对应资源不同 | |
} | |
// 项目 | |
struct Project { | |
int256 id; | |
address owner; | |
string name; | |
string desc; | |
int256 ptype; | |
Task[] tasks; | |
} | |
// 角色 | |
struct Role { | |
address user; | |
bool verify; // 是否审核过了 | |
int256 permission; // 权限,支持一个人有多种权限。比如user既是项目发布也是算力发布方 | |
} | |
mapping(address => Role) roles; // 三种角色:管理员,项目发布方,算力发布方。 | |
mapping(int256 => Project) public projects; | |
mapping(int256 => ComputeRes) public computeReses; | |
// 任何人:注册角色 | |
function registerRole() { | |
// roles[msg.sender] = role 地址对应的其他信息放在中心化服务器 | |
} | |
// 管理员:审核角色 | |
function verifyRole(address user) { | |
// 检查 msg.sender == admin | |
} | |
// 项目方:创建项目 | |
function createProject(Project project) { | |
int256 id; | |
if (roles[msg.sender].permission == 1) { | |
project.owner = msg.sender; | |
projects[id] = project; | |
} | |
} | |
// 项目方:在项目里面添加任务 | |
function addTask(int256 projectId, Task task) { | |
if (msg.sender == projects[projectId].owner) { | |
projects[projectId].tasks.push(task); | |
} | |
} | |
// 算立方:发布算力资源 | |
function publicComputeRes(ComputeRes computeRes) { | |
int256 id; | |
if (roles[msg.sender].permission == 2) { | |
computeRes.owner = msg.sender; | |
ComputeReses[id] = computeRes; | |
} | |
} | |
// 算立方:使用算力资源computeResId领取任务taskId | |
function startTask(int256 computeResId, uint256 taskId) { | |
ComputeRes computeRes = computeReses[computeResId]; | |
Task task = computeReses[taskId]; | |
if (msg.sender == computeRes[computeResId].user) { | |
// 检查 computeRes.status 是否是正常的 | |
// 检查 computeTes.ctype == task.ctype | |
// 检查 compute.pows >= task.powRequires,数组逐个值比较 | |
// 检查 task.status 是否是没被锁定 | |
// 检查... | |
} | |
} | |
// 算立方:上报任务状态(已完成,未完成放弃) | |
function reportTask( | |
int256 computeResId, | |
uint256 taskId, | |
uint256 status | |
) {} | |
// 项目方:检查任务是否完成 | |
function checkTask(int256 computeResId, uint256 taskId) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment