Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
add methods with actor id as parameter for non-singleton actors (#211)
Browse files Browse the repository at this point in the history
* feat: add miner actor methods with actor id as parameter
* feat: add account actor methods with actor id as parameter
* feat: add multisig actor methods with actor id as parameter
* feat: add tests for new account methods
  • Loading branch information
emmanuelm41 authored Feb 3, 2023
1 parent 5849acc commit 8e48de5
Show file tree
Hide file tree
Showing 8 changed files with 487 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"useTabs": false,
"semi": false,
"singleQuote": false,
"printWidth": 140
"printWidth": 160
}
40 changes: 24 additions & 16 deletions contracts/v0.8/AccountAPI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ library AccountAPI {
function authenticateMessage(bytes memory target, AccountTypes.AuthenticateMessageParams memory params) internal {
bytes memory raw_request = params.serializeAuthenticateMessageParams();

bytes memory raw_response = Actor.call(
AccountTypes.AuthenticateMessageMethodNum,
target,
raw_request,
Misc.CBOR_CODEC,
msg.value,
false
);
bytes memory raw_response = Actor.call(AccountTypes.AuthenticateMessageMethodNum, target, raw_request, Misc.CBOR_CODEC, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill this a proper description
/// @param target The account actor id you want to interact with
function authenticateMessage(uint64 target, AccountTypes.AuthenticateMessageParams memory params) internal {
bytes memory raw_request = params.serializeAuthenticateMessageParams();

bytes memory raw_response = Actor.callByID(target, AccountTypes.AuthenticateMessageMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
Expand All @@ -54,14 +58,18 @@ library AccountAPI {
function universalReceiverHook(bytes memory target, AccountTypes.UniversalReceiverParams memory params) internal {
bytes memory raw_request = params.serializeUniversalReceiverParams();

bytes memory raw_response = Actor.call(
AccountTypes.UniversalReceiverHookMethodNum,
target,
raw_request,
Misc.CBOR_CODEC,
msg.value,
false
);
bytes memory raw_response = Actor.call(AccountTypes.UniversalReceiverHookMethodNum, target, raw_request, Misc.CBOR_CODEC, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill this a proper description
/// @param target The account actor id you want to interact with
function universalReceiverHook(uint64 target, AccountTypes.UniversalReceiverParams memory params) internal {
bytes memory raw_request = params.serializeUniversalReceiverParams();

bytes memory raw_response = Actor.callByID(target, AccountTypes.UniversalReceiverHookMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
Expand Down
265 changes: 205 additions & 60 deletions contracts/v0.8/MinerAPI.sol

Large diffs are not rendered by default.

119 changes: 103 additions & 16 deletions contracts/v0.8/MultisigAPI.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ library MultisigAPI {
return result.deserializeProposeReturn();
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function propose(uint64 target, MultisigTypes.ProposeParams memory params) internal returns (MultisigTypes.ProposeReturn memory) {
bytes memory raw_request = params.serializeProposeParams();

bytes memory raw_response = Actor.callByID(target, MultisigTypes.ProposeMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);

return result.deserializeProposeReturn();
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function approve(bytes memory target, MultisigTypes.TxnIDParams memory params) internal returns (MultisigTypes.ApproveReturn memory) {
Expand All @@ -55,6 +67,18 @@ library MultisigAPI {
return result.deserializeApproveReturn();
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function approve(uint64 target, MultisigTypes.TxnIDParams memory params) internal returns (MultisigTypes.ApproveReturn memory) {
bytes memory raw_request = params.serializeTxnIDParams();

bytes memory raw_response = Actor.callByID(target, MultisigTypes.ApproveMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);

return result.deserializeApproveReturn();
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function cancel(bytes memory target, MultisigTypes.TxnIDParams memory params) internal {
Expand All @@ -66,6 +90,17 @@ library MultisigAPI {
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function cancel(uint64 target, MultisigTypes.TxnIDParams memory params) internal {
bytes memory raw_request = params.serializeTxnIDParams();

bytes memory raw_response = Actor.callByID(target, MultisigTypes.CancelMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function addSigner(bytes memory target, MultisigTypes.AddSignerParams memory params) internal {
Expand All @@ -77,6 +112,17 @@ library MultisigAPI {
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function addSigner(uint64 target, MultisigTypes.AddSignerParams memory params) internal {
bytes memory raw_request = params.serializeAddSignerParams();

bytes memory raw_response = Actor.callByID(target, MultisigTypes.AddSignerMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function removeSigner(bytes memory target, MultisigTypes.RemoveSignerParams memory params) internal {
Expand All @@ -88,6 +134,17 @@ library MultisigAPI {
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function removeSigner(uint64 target, MultisigTypes.RemoveSignerParams memory params) internal {
bytes memory raw_request = params.serializeRemoveSignerParams();

bytes memory raw_response = Actor.callByID(target, MultisigTypes.RemoveSignerMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function swapSigner(bytes memory target, MultisigTypes.SwapSignerParams memory params) internal {
Expand All @@ -99,19 +156,34 @@ library MultisigAPI {
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function swapSigner(uint64 target, MultisigTypes.SwapSignerParams memory params) internal {
bytes memory raw_request = params.serializeSwapSignerParams();

bytes memory raw_response = Actor.callByID(target, MultisigTypes.SwapSignerMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function changeNumApprovalsThreshold(bytes memory target, MultisigTypes.ChangeNumApprovalsThresholdParams memory params) internal {
bytes memory raw_request = params.serializeChangeNumApprovalsThresholdParams();

bytes memory raw_response = Actor.call(
MultisigTypes.ChangeNumApprovalsThresholdMethodNum,
target,
raw_request,
Misc.CBOR_CODEC,
msg.value,
false
);
bytes memory raw_response = Actor.call(MultisigTypes.ChangeNumApprovalsThresholdMethodNum, target, raw_request, Misc.CBOR_CODEC, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function changeNumApprovalsThreshold(uint64 target, MultisigTypes.ChangeNumApprovalsThresholdParams memory params) internal {
bytes memory raw_request = params.serializeChangeNumApprovalsThresholdParams();

bytes memory raw_response = Actor.callByID(target, MultisigTypes.ChangeNumApprovalsThresholdMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
Expand All @@ -128,19 +200,34 @@ library MultisigAPI {
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function lockBalance(uint64 target, MultisigTypes.LockBalanceParams memory params) internal {
bytes memory raw_request = params.serializeLockBalanceParams();

bytes memory raw_response = Actor.callByID(target, MultisigTypes.LockBalanceMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function universalReceiverHook(bytes memory target, bytes memory params) internal {
bytes memory raw_request = params.serializeBytes();

bytes memory raw_response = Actor.call(
MultisigTypes.UniversalReceiverHookMethodNum,
target,
raw_request,
Misc.CBOR_CODEC,
msg.value,
false
);
bytes memory raw_response = Actor.call(MultisigTypes.UniversalReceiverHookMethodNum, target, raw_request, Misc.CBOR_CODEC, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
}

/// @notice TODO fill me up
/// @param target The multisig address (filecoin bytes format) you want to interact with
function universalReceiverHook(uint64 target, bytes memory params) internal {
bytes memory raw_request = params.serializeBytes();

bytes memory raw_response = Actor.callByID(target, MultisigTypes.UniversalReceiverHookMethodNum, Misc.CBOR_CODEC, raw_request, msg.value, false);

bytes memory result = Actor.readRespData(raw_response);
require(result.length == 0, "unexpected response received");
Expand Down
8 changes: 8 additions & 0 deletions contracts/v0.8/tests/account.test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ contract AccountApiTest {
AccountAPI.authenticateMessage(target, params);
}

function authenticate_message(uint64 target, AccountTypes.AuthenticateMessageParams memory params) public {
AccountAPI.authenticateMessage(target, params);
}

function universal_receiver_hook(bytes memory target, AccountTypes.UniversalReceiverParams memory params) public {
AccountAPI.universalReceiverHook(target, params);
}

function universal_receiver_hook(uint64 target, AccountTypes.UniversalReceiverParams memory params) public {
AccountAPI.universalReceiverHook(target, params);
}
}
69 changes: 65 additions & 4 deletions contracts/v0.8/tests/miner.test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,66 +28,127 @@ contract MinerApiTest {
return MinerAPI.getOwner(target);
}

function get_owner(uint64 target) public returns (MinerTypes.GetOwnerReturn memory) {
return MinerAPI.getOwner(target);
}

function change_owner_address(bytes memory target, bytes memory addr) public {
MinerAPI.changeOwnerAddress(target, addr);
}

function change_owner_address(uint64 target, bytes memory addr) public {
MinerAPI.changeOwnerAddress(target, addr);
}

function is_controlling_address(bytes memory target, bytes memory addr) public returns (MinerTypes.IsControllingAddressReturn memory) {
return MinerAPI.isControllingAddress(target, addr);
}

function is_controlling_address(uint64 target, bytes memory addr) public returns (MinerTypes.IsControllingAddressReturn memory) {
return MinerAPI.isControllingAddress(target, addr);
}

function get_sector_size(bytes memory target) public returns (MinerTypes.GetSectorSizeReturn memory) {
return MinerAPI.getSectorSize(target);
}

function get_sector_size(uint64 target) public returns (MinerTypes.GetSectorSizeReturn memory) {
return MinerAPI.getSectorSize(target);
}

function get_available_balance(bytes memory target) public returns (MinerTypes.GetAvailableBalanceReturn memory) {
return MinerAPI.getAvailableBalance(target);
}

function get_available_balance(uint64 target) public returns (MinerTypes.GetAvailableBalanceReturn memory) {
return MinerAPI.getAvailableBalance(target);
}

function get_vesting_funds(bytes memory target) public returns (MinerTypes.GetVestingFundsReturn memory) {
return MinerAPI.getVestingFunds(target);
}

function get_vesting_funds(uint64 target) public returns (MinerTypes.GetVestingFundsReturn memory) {
return MinerAPI.getVestingFunds(target);
}

function change_beneficiary(bytes memory target, MinerTypes.ChangeBeneficiaryParams memory params) public {
return MinerAPI.changeBeneficiary(target, params);
}

function change_beneficiary(uint64 target, MinerTypes.ChangeBeneficiaryParams memory params) public {
return MinerAPI.changeBeneficiary(target, params);
}

function get_beneficiary(bytes memory target) public returns (MinerTypes.GetBeneficiaryReturn memory) {
return MinerAPI.getBeneficiary(target);
}

function get_beneficiary(uint64 target) public returns (MinerTypes.GetBeneficiaryReturn memory) {
return MinerAPI.getBeneficiary(target);
}

function change_worker_address(bytes memory target, MinerTypes.ChangeWorkerAddressParams memory params) public {
MinerAPI.changeWorkerAddress(target, params);
}

function change_worker_address(uint64 target, MinerTypes.ChangeWorkerAddressParams memory params) public {
MinerAPI.changeWorkerAddress(target, params);
}

function change_peer_id(bytes memory target, MinerTypes.ChangePeerIDParams memory params) public {
MinerAPI.changePeerId(target, params);
}

function change_peer_id(uint64 target, MinerTypes.ChangePeerIDParams memory params) public {
MinerAPI.changePeerId(target, params);
}

function change_multiaddresses(bytes memory target, MinerTypes.ChangeMultiaddrsParams memory params) public {
MinerAPI.changeMultiaddresses(target, params);
}

function change_multiaddresses(uint64 target, MinerTypes.ChangeMultiaddrsParams memory params) public {
MinerAPI.changeMultiaddresses(target, params);
}

function repay_debt(bytes memory target) public {
MinerAPI.repayDebt(target);
}

function repay_debt(uint64 target) public {
MinerAPI.repayDebt(target);
}

function confirm_change_worker_address(bytes memory target) public {
MinerAPI.confirmChangeWorkerAddress(target);
}

function confirm_change_worker_address(uint64 target) public {
MinerAPI.confirmChangeWorkerAddress(target);
}

function get_peer_id(bytes memory target) public returns (MinerTypes.GetPeerIDReturn memory) {
return MinerAPI.getPeerId(target);
}

function get_peer_id(uint64 target) public returns (MinerTypes.GetPeerIDReturn memory) {
return MinerAPI.getPeerId(target);
}

function get_multiaddresses(bytes memory target) public returns (MinerTypes.GetMultiaddrsReturn memory) {
return MinerAPI.getMultiaddresses(target);
}

function withdraw_balance(
bytes memory target,
MinerTypes.WithdrawBalanceParams memory params
) public returns (MinerTypes.WithdrawBalanceReturn memory) {
function get_multiaddresses(uint64 target) public returns (MinerTypes.GetMultiaddrsReturn memory) {
return MinerAPI.getMultiaddresses(target);
}

function withdraw_balance(bytes memory target, MinerTypes.WithdrawBalanceParams memory params) public returns (MinerTypes.WithdrawBalanceReturn memory) {
return MinerAPI.withdrawBalance(target, params);
}

function withdraw_balance(uint64 target, MinerTypes.WithdrawBalanceParams memory params) public returns (MinerTypes.WithdrawBalanceReturn memory) {
return MinerAPI.withdrawBalance(target, params);
}
}
Loading

0 comments on commit 8e48de5

Please sign in to comment.