Created
November 25, 2021 14:41
-
-
Save wesfloyd/8d2233e0ed329f84834025c40bf39ad2 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
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
//SPDX-License-Identifier: Unlicense | |
pragma solidity ^0.8.0; | |
contract ComputeLease { | |
uint16 durationMins; | |
uint256 containerID; | |
address driverAddress; | |
address minerAddress; | |
address minerPoolAddress; | |
string containerURL; | |
constructor(string memory _containerURL, address _driver, address _miner, | |
uint16 _duration, address _minerPool) { | |
containerURL = _containerURL; | |
minerAddress = _miner; | |
durationMins = _duration; | |
driverAddress = _driver; | |
minerPoolAddress = _minerPool; | |
} | |
event LeaseInitiated(address indexed lease); | |
// Miner confirms lease acceptance and begins hosting | |
function initiateLease() payable public{ | |
require (msg.sender == minerAddress, "Sender address not equal to minerAddress"); | |
// Pay the first fraction of payment | |
(bool sent, bytes memory data) = minerAddress.call{value: msg.value}(""); | |
require(sent, "Failed to initiateLease at send Ether to miner:"); | |
emit LeaseInitiated(address(address(this))); | |
} | |
// Todo how to limit checkpoints from Miner to once every X minutes? | |
function checkpoint() public { | |
require (msg.sender == driverAddress, "Checkpoint caller address not equal to driver address"); | |
} | |
receive() external payable {} | |
fallback() external payable {} | |
} | |
contract MinerPool { | |
struct Miner { | |
address minerAddress; | |
int8 minerReputation; | |
} | |
Miner[] minerStack; | |
address[] activeLeases; | |
event LeaseCreated(address indexed newLease, string message); | |
event MinerRegistered(); | |
event MinerReputationReported(); | |
function registerNewMiner() public{ | |
// todo register message.sender | |
minerStack.push(Miner(msg.sender, 0)); | |
} | |
// Driver creates and assigns a lease to a miner | |
function createLease(string memory _packageURL, address _miner, uint16 _duration) payable public { | |
address newLease = address(new ComputeLease(_packageURL, msg.sender, _miner, _duration, address(this))); | |
activeLeases.push(newLease); | |
//(bool sent, bytes memory data) = newLease.call{value: msg.value}(""); | |
(bool sent, bytes memory data) = newLease.call{value: msg.value}(""); | |
require(sent, "Failed to send Ether. CallData:"); | |
emit LeaseCreated(address(newLease), "New lease created"); | |
} | |
// ComputeLease reports change in miner reputation | |
function reportMinerReputation() public{ | |
// The ComputeLease contract should report reputation positive if | |
// compute lease is fully paid and driver has positive outcome | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment