在上一章跟我一起阅读并修复某知名DEX交易所源码(3:编译工程,源码分析)之五_lixiaodog的博客-CSDN博客
中我们详细分析了 contract MdexPair的源码,本章将继续编译的进程,来吧,少年,出发吧!!
输入编译命令truffle compile
project:/contracts/mainnet/CoinChef.sol:48:43: TypeError: Operator ** not compatible with types int_const 100 and int_const 1000000000000000000
uint256 public constant mdxPerBlock = 100 ** 1e18;
**运算符无法用于这两个常数,我认为应该是写错了,修改为:
uint256 public constant mdxPerBlock = 100*10**18;
每区块产量100个。如果是100**1E18 ,是个多大的数大家可以想像。
再次编译,如下图:
> Duplicate contract names found for TransferHelper.
> This can cause errors and unknown behavior. Please rename one of your contracts.
> Duplicate contract names found for IWHT.
> This can cause errors and unknown behavior. Please rename one of your contracts.
> Duplicate contract names found for TransferHelper.
> This can cause errors and unknown behavior. Please rename one of your contracts.
> Duplicate contract names found for MdxToken.
> This can cause errors and unknown behavior. Please rename one of your contracts.
> Duplicate contract names found for SafeMath.
> This can cause errors and unknown behavior. Please rename one of your contracts.
合约名TransferHelper冲突了。在全局范围内搜索,如下图:
在 C:\work\blockchain\Mdex\contracts\assets\Airdrop.sol
9,9: library TransferHelper {
13,77: require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
19,77: require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
25,77: require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
87,9: TransferHelper.safeTransferFrom(address(wht), msg.sender, address(this), _whtAmount);
与
C:\work\blockchain\Mdex\contracts\assets\AirdropMDX.sol
10,9: library TransferHelper {
14,77: require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
20,77: require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
26,77: require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
83,9: TransferHelper.safeTransferFrom(mdx, msg.sender, address(this), _mdxAmount);
发现了同名定义,此时我们需要决定修改哪个定义,以解决冲突,通过对比我们发现这三处定义是一模一样的,所以我直接把这个库合并为一个库,在library新建文件TransferHelper.sol,如下图
同时删除其它两处的相关定义,并添加import "library/TransferHelper.sol";
pragma solidity ^0.6.0;
library TransferHelper {
function safeApprove(address token, address to, uint value) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED');
}
function safeTransfer(address token, address to, uint value) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
}
function safeTransferFrom(address token, address from, address to, uint value) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
}
function safeTransferETH(address to, uint value) internal {
(bool success,) = to.call{value : value}(new bytes(0));
require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
}
}
搜索library SafeMath
在oracle.sol中我们发的safemath只有定义,但实际上在这个文件中并未有实际使用,所以注释掉safeMath的定义和 //using SafeMathUint for uint;
搜索MdxToken,结果如下图:
我们发现在MdxToken.sol中的定义并未被引用过,全部注释掉
搜索IWHT,如下图
注释Airdrop.sol的定义,并在interface下新建文件IWHT.SOL,代码:
interface IWHT {
function balanceOf(address owner) external view returns (uint);
function deposit() external payable;
function transfer(address to, uint value) external returns (bool);
function withdraw(uint) external;
}
在上面两个文件中加入:import "../interface/IWHT.sol";
再次编译,结果如下图:
文章来源:https://www.toymoban.com/news/detail-497014.html
编译通过,至此,所有的编译问题已经全部解决,在下一章跟我一起阅读并修复某知名DEX交易所源码(4:部署工程,源码分析)_lixiaodog的博客-CSDN博客中,我们将会尝试布署MDEX至本地测试环境。敬请期待!!! 文章来源地址https://www.toymoban.com/news/detail-497014.html
到了这里,关于跟我一起阅读并修复源码(3:编译工程,源码分析)之六的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!