我正在使用一个Tron智能合约,但我有toruble从修饰符获取错误值。这是一份与问题相关的简短合同:
pragma solidity >= 0.8.4;
contract EnumTest {
address private _owner;
enum ErrStatus {
NO_ERROR,
ERR_PLAYER_REQUIRED,
ERR_OWNER_REQUIRED
}
uint256 private _amount;
error ErrHandle(uint8 errstatus);
modifier OnlyOwner(){
if(msg.sender != _owner)
revert ErrHandle({errstatus:1});
_;
}
modifier OnlyPlayer() {
if(msg.sender == _owner)
revert ErrHandle({errstatus:2});
_;
}
constructor(){
_owner = msg.sender;
}
function setAmount() public payable OnlyOwner returns (uint8) {
_amount = msg.value;
return uint8(ErrStatus.NO_ERROR);
}
function getAmount() public view OnlyPlayer returns (uint256) {
return _amount;
}
}
当我用TronWeb调用getAmount()时,调用转到了catch(),但我无法恢复error语句的值。
我尝试过:
modifier OnlyOwner(){
require(msg.sender == _owner, "ERR_OWNER_EXPECTED");
_;
}
但我无法用TronWeb恢复值“ERR\u OWNER\u EXPECTED”。
是否有办法使用TronWeb从合同中获取错误状态或值?