Skip to content

Commit 274c56e

Browse files
authored
Merge pull request #50 from MVPWorkshop/remix-import-fix
[M4] Remix IDE contract flattening fix
2 parents 22c95a1 + c061636 commit 274c56e

File tree

5 files changed

+70
-45
lines changed

5 files changed

+70
-45
lines changed

contracts/v0.8/tests/account.test.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pragma solidity ^0.8.17;
2222
import "../types/AccountTypes.sol";
2323
import "../types/CommonTypes.sol";
2424
import "../AccountAPI.sol";
25-
import "../utils/Misc.sol";
25+
import "../utils/UtilsHandlers.sol";
2626
import "../utils/Errors.sol";
2727

2828
/// @notice This file is meant to serve as a deployable contract of the account actor API, as the library by itself is not.
@@ -36,7 +36,7 @@ contract AccountApiTest {
3636
}
3737

3838
function universal_receiver_hook(CommonTypes.FilActorId target, CommonTypes.UniversalReceiverParams memory params) public {
39-
(int256 exit_code, bytes memory result) = Misc.universalReceiverHook(target, params);
39+
(int256 exit_code, bytes memory result) = UtilsHandlers.universalReceiverHook(target, params);
4040

4141
Errors.revertOnError(exit_code);
4242
}

contracts/v0.8/tests/datacap.test.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import "../types/DataCapTypes.sol";
2323
import "../types/CommonTypes.sol";
2424
import "../cbor/BigIntCbor.sol";
2525
import "../DataCapAPI.sol";
26-
import "../utils/Misc.sol";
26+
import "../utils/UtilsHandlers.sol";
2727
import "../utils/Errors.sol";
2828

2929
/// @notice This file is meant to serve as a deployable contract of the datacap actor API, as the library by itself is not.
@@ -127,6 +127,6 @@ contract DataCapApiTest {
127127
}
128128

129129
function handle_filecoin_method(uint64 method, uint64 codec, bytes calldata params) public pure {
130-
Misc.handleFilecoinMethod(method, codec, params);
130+
UtilsHandlers.handleFilecoinMethod(method, codec, params);
131131
}
132132
}

contracts/v0.8/utils/Misc.sol

-36
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,10 @@
1919
pragma solidity ^0.8.17;
2020

2121
import "../types/CommonTypes.sol";
22-
import "../types/AccountTypes.sol";
23-
import "../types/DataCapTypes.sol";
24-
25-
import "../cbor/AccountCbor.sol";
26-
import "../cbor/BytesCbor.sol";
27-
import "../cbor/FilecoinCbor.sol";
28-
29-
import "../utils/Actor.sol";
3022

3123
/// @title Library containing miscellaneous functions used on the project
3224
/// @author Zondax AG
3325
library Misc {
34-
using AccountCBOR for *;
35-
using FilecoinCBOR for *;
36-
using BytesCBOR for bytes;
37-
3826
/// @notice the codec received is not valid
3927
error InvalidCodec(uint64);
4028

@@ -108,28 +96,4 @@ library Misc {
10896
function getBoolSize() internal pure returns (uint256) {
10997
return getPrefixSize(1);
11098
}
111-
112-
/// @notice utility function meant to handle calls from other builtin actors. Arguments are passed as cbor serialized data (in filecoin native format)
113-
/// @param method the filecoin method id that is being called
114-
/// @param params raw data (in bytes) passed as arguments to the method call
115-
function handleFilecoinMethod(uint64 method, uint64 codec, bytes calldata params) internal pure returns (CommonTypes.UniversalReceiverParams memory) {
116-
if (method == CommonTypes.UniversalReceiverHookMethodNum) {
117-
if (codec != Misc.CBOR_CODEC) {
118-
revert InvalidCodec(codec);
119-
}
120-
121-
return params.deserializeUniversalReceiverParams();
122-
} else {
123-
revert MethodNotHandled(method);
124-
}
125-
}
126-
127-
/// @param target The actor id you want to interact with
128-
function universalReceiverHook(CommonTypes.FilActorId target, CommonTypes.UniversalReceiverParams memory params) internal returns (int256, bytes memory) {
129-
bytes memory raw_request = params.serializeUniversalReceiverParams();
130-
131-
(int256 exit_code, bytes memory result) = Actor.callByID(target, CommonTypes.UniversalReceiverHookMethodNum, Misc.CBOR_CODEC, raw_request, 0, false);
132-
133-
return (exit_code, result);
134-
}
13599
}
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*******************************************************************************
2+
* (c) 2022 Zondax AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
********************************************************************************/
16+
// THIS CODE WAS SECURITY REVIEWED BY KUDELSKI SECURITY, BUT NOT FORMALLY AUDITED
17+
18+
// SPDX-License-Identifier: Apache-2.0
19+
pragma solidity ^0.8.17;
20+
21+
import "../types/CommonTypes.sol";
22+
23+
import "../cbor/FilecoinCbor.sol";
24+
25+
import "../utils/Actor.sol";
26+
27+
/// @title Library containing common handler functions used in the project
28+
/// @author Zondax AG
29+
library UtilsHandlers {
30+
using FilecoinCBOR for *;
31+
32+
/// @notice the codec received is not valid
33+
error InvalidCodec(uint64);
34+
35+
/// @notice filecoin method not handled
36+
error MethodNotHandled(uint64);
37+
38+
/// @notice utility function meant to handle calls from other builtin actors. Arguments are passed as cbor serialized data (in filecoin native format)
39+
/// @param method the filecoin method id that is being called
40+
/// @param params raw data (in bytes) passed as arguments to the method call
41+
function handleFilecoinMethod(uint64 method, uint64 codec, bytes calldata params) internal pure returns (CommonTypes.UniversalReceiverParams memory) {
42+
if (method == CommonTypes.UniversalReceiverHookMethodNum) {
43+
if (codec != Misc.CBOR_CODEC) {
44+
revert InvalidCodec(codec);
45+
}
46+
47+
return params.deserializeUniversalReceiverParams();
48+
} else {
49+
revert MethodNotHandled(method);
50+
}
51+
}
52+
53+
/// @param target The actor id you want to interact with
54+
function universalReceiverHook(CommonTypes.FilActorId target, CommonTypes.UniversalReceiverParams memory params) internal returns (int256, bytes memory) {
55+
bytes memory raw_request = params.serializeUniversalReceiverParams();
56+
57+
(int256 exit_code, bytes memory result) = Actor.callByID(target, CommonTypes.UniversalReceiverHookMethodNum, Misc.CBOR_CODEC, raw_request, 0, false);
58+
59+
return (exit_code, result);
60+
}
61+
}

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "filecoin-solidity-api",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Filecoin EVM Solidity APIs",
55
"main": "",
66
"directories": {
@@ -43,9 +43,7 @@
4343
"hardhat": "^2.11.2",
4444
"prettier": "^2.7.1",
4545
"prettier-plugin-solidity": "^1.0.0",
46-
"typechain": "^8.3.1"
47-
},
48-
"dependencies": {
46+
"typechain": "^8.3.1",
4947
"@glif/filecoin-address": "^2.0.43",
5048
"@nomiclabs/hardhat-etherscan": "^3.1.7",
5149
"@typechain/ethers-v5": "^11.1.1",
@@ -56,8 +54,10 @@
5654
"cids": "^1.1.9",
5755
"hardhat-contract-sizer": "^2.10.0",
5856
"hardhat-deploy-ethers": "^0.3.0-beta.13",
59-
"solidity-cborutils": "^2.0.0",
6057
"ts-node": "^10.9.1",
6158
"typescript": "^5.2.2"
59+
},
60+
"dependencies": {
61+
"solidity-cborutils": "^2.0.0"
6262
}
6363
}

0 commit comments

Comments
 (0)