Skip to content

Commit

Permalink
Support send to worker and post addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
kikakkz committed Mar 29, 2023
1 parent ff37d50 commit cd1bba1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
24 changes: 11 additions & 13 deletions contracts/v0.1/OwnerActor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ pragma solidity ^0.8.17;
import "./controller/Controllable.sol";
import "./miner/Miner.sol";
import "./beneficiary/Beneficiary.sol";

// import "https://github.com/Zondax/filecoin-solidity/blob/v4.0.2/contracts/v0.8/PowerAPI.sol";
// import "https://github.com/Zondax/filecoin-solidity/blob/v4.0.2/contracts/v0.8/types/PowerTypes.sol";
import "./send/Send.sol";

// TODO: we cannot detect method 0 within runtime contract
// so we have to let a genesis account to record the deposit
Expand Down Expand Up @@ -82,15 +80,15 @@ contract OwnerActor is Controllable {
Miner.accounting(_miner, amount);
}

function setWorker(address newWorkerActorId) public onlyController {
function setWorker(uint64 newWorkerActorId) public onlyController {
require(_miner.exist, "Owner: there is no miner custodied");
require(newWorkerActorId != address(0), "Owner: invalid actor id");
require(newWorkerActorId > 0, "Owner: invalid actor id");
Miner.setWorker(_miner, newWorkerActorId);
}

function setPoStControl(address newControlActorId) public onlyController {
function setPoStControl(uint64 newControlActorId) public onlyController {
require(_miner.exist, "Owner: there is no miner custodied");
require(newControlActorId != address(0), "Owner: invalid actor id");
require(newControlActorId > 0, "Owner: invalid actor id");
Miner.setPoStControl(_miner, newControlActorId);
}

Expand All @@ -105,18 +103,18 @@ contract OwnerActor is Controllable {

function sendToWorker(uint256 amount) public onlyController {
require(_miner.exist, "Owner: there is no miner custodied");
address payable worker = payable(Miner._worker(_miner));
require(worker != address(0), "Owner: invalid worker");
uint64 worker = Miner._worker(_miner);
require(worker > 0, "Owner: invalid worker");
require(address(this).balance > amount, "Owner: insufficient funds - contract");
worker.transfer(amount);
Send.send(worker, amount);
}

function sendToPoStControl(uint256 amount) public onlyController {
require(_miner.exist, "Owner: there is no miner custodied");
address payable postControl = payable(Miner._postControl(_miner));
require(postControl != address(0), "Owner: invalid PoSt control");
uint64 postControl = Miner._postControl(_miner);
require(postControl > 0, "Owner: invalid PoSt control");
require(address(this).balance > amount, "Owner: insufficient funds - contract");
postControl.transfer(amount);
Send.send(postControl, amount);
}

function setBeneficiary(
Expand Down
12 changes: 6 additions & 6 deletions contracts/v0.1/miner/Miner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ library Miner {
uint64 custodyOwner;

// TODO: this two should be got from miner but we cannot get it now
address worker;
address postControl;
uint64 worker;
uint64 postControl;

bool exist;
}
Expand Down Expand Up @@ -156,19 +156,19 @@ library Miner {
return miner.percentBeneficiaries[beneficiary].balance;
}

function setWorker(_Miner storage miner, address newWorkerActorId) public {
function setWorker(_Miner storage miner, uint64 newWorkerActorId) public {
miner.worker = newWorkerActorId;
}

function _worker(_Miner storage miner) public view returns (address) {
function _worker(_Miner storage miner) public view returns (uint64) {
return miner.worker;
}

function setPoStControl(_Miner storage miner, address newControlActorId) public {
function setPoStControl(_Miner storage miner, uint64 newControlActorId) public {
miner.postControl = newControlActorId;
}

function _postControl(_Miner storage miner) public view returns (address) {
function _postControl(_Miner storage miner) public view returns (uint64) {
return miner.postControl;
}

Expand Down
14 changes: 14 additions & 0 deletions contracts/v0.1/send/Send.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity = 0.8.17;

import "https://github.com/Zondax/filecoin-solidity/blob/master/contracts/v0.8/SendAPI.sol";
import "https://github.com/Zondax/filecoin-solidity/blob/master/contracts/v0.8/types/CommonTypes.sol";

library Send {
function send(uint64 actorId, uint256 amount) public {
require(amount > 0, "Send: invalid amount");
require(address(this).balance > amount, "Send: insufficient funds");
CommonTypes.FilActorId _actorId = CommonTypes.FilActorId.wrap(actorId);
SendAPI.send(_actorId, amount);
}
}

0 comments on commit cd1bba1

Please sign in to comment.