目前,我对我的合同有点纠结,问题是:我定义了一个用于另一个地址的smartcontract (也称为smartcontract,它提供了指定的接口)问题是,是否有可能进行地址类型检查或将所述合同接口对象转换为address,因为它本质上就是这样的。虽然我知道,在存储方面,这些字节代表地址,但我似乎不知道如何从接口类型返回到裸地址类型,并对其进行适当的检查。我搜索了相当多,但没有找到任何样本,如何在网络上或在坚实的文档中完成这一点。
见下面的例子:
pragma solidity ^0.5.1;
contract SampleInterface {
function foo(uint256 someValue) external returns (uint256);
}
library SampleLibrary {
enum SampleType {
FIRST,
SECOND
}
}
contract SampleInterfaceManager {
mapping(uint => SampleInterface[]) public interfacesByType;
function processFoo(uint256 someValue, SampleLibrary.SampleType sampleType) external returns (uint256) {
SampleInterface[] storage sampleInterfaces = interfacesByType[uint(sampleType)];
uint temp = someValue;
for (uint i = 0; i < sampleInterfaces.length; i++) {
SampleInterface sampleInterface = sampleInterfaces[i];
//How to make this check work?
if (sampleInterface != address(0)) {
temp = sampleInterface.foo(temp);
}
}
return temp;
}
}此代码当前创建编译错误:
smartcontracts/Sample.sol:23:17: Error: Operator != not compatible with types contract SampleInterface and address payable
if (sampleInterface != address(0)) {
^---------------------------^任何关于如何解决这个问题的建议都是非常受欢迎的。我可以试着不做这个检查,但希望避免这种情况。
发布于 2019-04-11 15:43:51
只需转换到address:
if (address(sampleInterface) != address(0)) {https://ethereum.stackexchange.com/questions/69555
复制相似问题