Ethereum 用于字节操作的Solidity代码无法使用Solidity为0.8.0的hardhat编译器编译

Ethereum 用于字节操作的Solidity代码无法使用Solidity为0.8.0的hardhat编译器编译,ethereum,solidity,truffle,hardhat,Ethereum,Solidity,Truffle,Hardhat,我正在使用0.8.0编译器编译OpenSea项目中使用Sol 0.5.0编写的代码,我发现错误: ParserError: Expected primary expression. --> contracts/Strings.sol:53:25: | 53 | bstr[k--] = byte(uint8(48 + _i % 10)); | ^^^^ Error HH600: Compilation fai

我正在使用
0.8.0
编译器编译OpenSea项目中使用
Sol 0.5.0
编写的代码,我发现错误:

  ParserError: Expected primary expression.
--> contracts/Strings.sol:53:25:
 |
53 |             bstr[k--] = byte(uint8(48 + _i % 10));
 |                         ^^^^


Error HH600: Compilation failed
原始代码位于:,它使用
Sol 0.5.0
,大概是用truffle编译的。我正在尝试使用
Hardhat
0.8.0
。代码复制如下:

pragma solidity ^0.8.0;

library Strings {
  // via https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol
  function strConcat(string memory _a, string memory _b, string memory _c, string memory _d, string memory _e) internal pure returns (string memory) {
      bytes memory _ba = bytes(_a);
      bytes memory _bb = bytes(_b);
      bytes memory _bc = bytes(_c);
      bytes memory _bd = bytes(_d);
      bytes memory _be = bytes(_e);
      string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);
      bytes memory babcde = bytes(abcde);
      uint k = 0;
      for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
      for (uint i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
      for (uint i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];
      for (uint i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];
      for (uint i = 0; i < _be.length; i++) babcde[k++] = _be[i];
      return string(babcde);
    }

    function strConcat(string memory _a, string memory _b, string memory _c, string memory _d) internal pure returns (string memory) {
        return strConcat(_a, _b, _c, _d, "");
    }

    function strConcat(string memory _a, string memory _b, string memory _c) internal pure returns (string memory) {
        return strConcat(_a, _b, _c, "", "");
    }

    function strConcat(string memory _a, string memory _b) internal pure returns (string memory) {
        return strConcat(_a, _b, "", "", "");
    }

    function uint2str(uint _i) internal pure returns (string memory _uintAsString) {
        if (_i == 0) {
            return "0";
        }
        uint j = _i;
        uint len;
        while (j != 0) {
            len++;
            j /= 10;
        }
        bytes memory bstr = new bytes(len);
        uint k = len - 1;
        while (_i != 0) {
            bstr[k--] = byte(uint8(48 + _i % 10));
            _i /= 10;
        }
        return string(bstr);
    }
}
pragma-solidity^0.8.0;
库字符串{
//通过https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol
函数strConcat(字符串内存a、字符串内存b、字符串内存c、字符串内存d、字符串内存e)内部纯返回(字符串内存){
字节内存_ba=字节(_a);
字节内存_bb=字节(_b);
字节内存_bc=字节(_c);
字节内存_bd=字节(_d);
字节内存_be=字节(_e);
字符串内存abcde=新字符串(_ba.length+_bb.length+_bc.length+_bd.length+_be.length);
字节内存babcde=字节(abcde);
uint k=0;
对于(uint i=0;i<_ba.length;i++)babcde[k++]=_ba[i];
对于(uint i=0;i<_bb.length;i++)babcde[k++]=_bb[i];
对于(uint i=0;i<_bc.length;i++)babcde[k++]=_bc[i];
对于(uint i=0;i<_bd.length;i++)babcde[k++]=_bd[i];
对于(uint i=0;i<\u be.length;i++)babcde[k++]=\u be[i];
返回字符串(babcde);
}
函数strConcat(字符串内存a、字符串内存b、字符串内存c、字符串内存d)内部纯返回(字符串内存){
返回strConcat(_a,_b,_c,_d,“”);
}
函数strConcat(字符串内存a、字符串内存b、字符串内存c)内部纯返回(字符串内存){
返回strConcat(_a,_b,_c,“,”);
}
函数strConcat(字符串内存a,字符串内存b)内部纯返回(字符串内存){
返回strConcat(_a,_b,,,,);
}
函数uint2str(uint _i)内部纯返回(字符串内存uintAsString){
如果(_i==0){
返回“0”;
}
uint j=_i;
单透镜;
而(j!=0){
len++;
j/=10;
}
字节内存bstr=新字节(len);
uint k=len-1;
而(_i!=0){
bstr[k--]=字节(uint8(48+_i%10));
_i/=10;
}
返回字符串(bstr);
}
}

注:我在顶部更改了
杂注
。我觉得一切都很好,所以我不确定问题在哪里,除了它在这一行之外:
bstr[k--]=byte(uint8(48+_I%10))

使用
字节1
而不是
字节


类型
字节
已被删除。它是
bytes1
的别名


来源:

使用
字节1
而不是
字节


类型
字节
已被删除。它是
bytes1
的别名

资料来源: