如何在 TRC20 中检查 Tron 地址是否是合约

时间:2021-04-15 07:08:09

标签: solidity smartcontracts tron

我正在尝试使此代码与 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 令牌中进行相同的检查,或者我的解决方案是否可行?

0 个答案:

没有答案