我正在尝试使此代码与 Tron 网络一起使用,这是我在网上看到的示例
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
这是我在 Tron 中的实现
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = convertFromTronInt(THgQd3Z3nZuvVNBL9HcAyiutrpsigVKPT1);
//THgQd3Z3nZuvVNBL9HcAyiutrpsigVKPT1;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return true;
}
function convertFromTronInt(uint256 tronAddress) public view returns(address){
return address(tronAddress);
}
有没有更好的方法可以从 Tron 令牌中进行相同的检查,或者我的解决方案是否可行?