plugin icon indicating copy to clipboard operation
plugin copied to clipboard

EVM交易日志打印信息优化(低优先级)

Open andyYuanFZM opened this issue 4 years ago • 0 comments

在solidity合约中定义出错信息: only authorized owner can store files. EVM交易中打印的信息中会多出一些空格符号,有时间可以优化下:

receipt": { "ty": 1, "tyName": "ExecPack", "logs": [ { "ty": 1, "tyName": "LogErr", "log": "evm: execution reverted,detail: \u0008\ufffdy\ufffd\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000 \u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0026only authorized owner can store files.\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000", "rawLog": "0x65766d3a20657865637574696f6e2072657665727465642c64657461696c3a2008c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000266f6e6c7920617574686f72697a6564206f776e65722063616e2073746f72652066696c65732e0000000000000000000000000000000000000000000000000000" } ] },

solidity合约参考代码如下: ==== BasicAuth.sol contract BasicAuth { address public _owner;

constructor() public {
    _owner = msg.sender;
}

function setOwner(address owner)
    public onlyOwner {
    _owner = owner;
}

modifier onlyOwner() { 
    require(msg.sender == _owner, "only authorized owner can store files.");
    _; 
}

}

===== FileStore.sol pragma solidity >=0.6.2 <0.7.0;

import "./BasicAuth.sol";

contract FileStore is BasicAuth { mapping(string => string) _fileStockByID;

modifier validFileId(string memory fileId) {
    require(bytes(fileId).length > 0, "fileId is invalid!");
    _;
}

function setFileStockById(string memory fileId, string memory content) 
    onlyOwner validFileId(fileId) external {
    _fileStockByID[fileId] = content;
}

function getFileById(string memory fileId) external view  returns(string memory) {
    return _fileStockByID[fileId];
}

}

andyYuanFZM avatar Aug 05 '21 02:08 andyYuanFZM