我的web3代码中出现Solidity Overflow,但可在oneclickdapp [Final Year Project]中使用

问题描述

这是运行https://oneclickdapp.com/center-east/的oneclickapp的链接

这是合同链接https://rinkeby.etherscan.io/address/0x33febb8f192941a87d87ef70cc5f4427c44bf29e#code

合同源代码

contract Patient is Hospital{
    
    uint256 public pindex=0;
    
    struct Records {
    string hname;
    string reason;
    string admittedOn;
    string dischargedOn;
    string ipfs;
    }
    
    struct patient{
        uint256 id;
        string name;
        string phone;
        string gender;
        string dob;
        string bloodgroup;
        string allergies;
        Records[] records;
        address addr;
    }

    address[] private patientList;
    mapping(address=>mapping(address=>bool)) isAuth;
    mapping(address=>patient) patients;
    mapping(address=>bool) isPatient;

    
    function addRecord(address _addr,string memory _hname,string memory _reason,string memory _admittedOn,string memory _dischargedOn,string memory _ipfs) public{
        require(isPatient[_addr],"User Not registered");
        require(isAuth[_addr][msg.sender],"No permission to add Records");
        patients[_addr].records.push(Records(_hname,_reason,_admittedOn,_dischargedOn,_ipfs));
        
    }
    
    function addPatient(string memory _name,string memory _phone,string memory _gender,string memory _dob,string memory _bloodgroup,string memory _allergies) public {
        require(!isPatient[msg.sender],"Already Patient account exists");
        patientList.push(msg.sender);
        pindex = pindex + 1;
        isPatient[msg.sender]=true;
        isAuth[msg.sender][msg.sender]=true;
        patients[msg.sender].id=pindex;
        patients[msg.sender].name=_name;
        patients[msg.sender].phone=_phone;
        patients[msg.sender].gender=_gender;
        patients[msg.sender].dob=_dob;
        patients[msg.sender].bloodgroup=_bloodgroup;
        patients[msg.sender].allergies=_allergies;
        patients[msg.sender].addr=msg.sender;
    }
    
    function getPatientDetails(address _addr) public view returns(string memory _name,string memory _allergies){
        require(isAuth[_addr][msg.sender],"No permission to get Records");
        require(isPatient[_addr],"No Patients found at the given address");
        patient memory tmp = patients[_addr];
        return (tmp.name,tmp.phone,tmp.gender,tmp.dob,tmp.bloodgroup,tmp.allergies);
    }
    
    function getPatientRecords(address _addr) public view returns(string[] memory _hname,string[] memory _reason,string[] memory _admittedOn,string[] memory _dischargedOn,string[] memory ipfs){
        require(isAuth[_addr][msg.sender],"patient not signed in to our network");
        require(patients[_addr].records.length>0,"patient record doesn't exist");
        string[] memory Hname = new string[](patients[_addr].records.length);
        string[] memory Reason = new string[](patients[_addr].records.length);
        string[] memory AdmOn = new string[](patients[_addr].records.length);
        string[] memory disOn = new string[](patients[_addr].records.length);
        string[] memory IPFS = new string[](patients[_addr].records.length);
        for(uint256 i=0;i<patients[_addr].records.length;i++){
            Hname[i]=patients[_addr].records[i].hname;
            Reason[i]=patients[_addr].records[i].reason;
            AdmOn[i]=patients[_addr].records[i].admittedOn;
            disOn[i]=patients[_addr].records[i].dischargedOn;
            IPFS[i]=patients[_addr].records[i].ipfs;
        }
        return(Hname,Reason,AdmOn,disOn,IPFS);
    }
    
    function addAuth(address _addr) public returns(bool success) {
        require(!isAuth[msg.sender][_addr],"Already Authorised");
        require(msg.sender!=_addr,"Cant add yourself");
        isAuth[msg.sender][_addr] = true;
        return true;
    }

    function revokeAuth(address _addr) public returns(bool success) {
        require(msg.sender!=_addr,"Cant remove yourself");
        require(isAuth[msg.sender][_addr],"Already Not Authorised");
        isAuth[msg.sender][_addr] = false;
        return true;
    }
    
    function addAuthFromTo(address _from,address _to) public returns(bool success) {
        require(!isAuth[_from][_to],"Already  Auth!!!");
        require(_from!=_to,"can't add same person");
        require(isAuth[_from][msg.sender],"You don't have permission to access");
        require(isPatient[_from],"User Not Registered yet");
        isAuth[_from][_to] = true;
        return true;
    }
    
    function removeAuthFromTo(address _from,address _to) public returns(bool success) {
        require(isAuth[_from][_to],"Already No Auth!!!");
        require(_from!=_to,"can't remove same person");
        require(isAuth[_from][msg.sender],"User Not Registered yet");
        isAuth[_from][_to] = false;
        return true;
    }
    

}

我自己的ReactJs代码

        try{
            await this.DMR.methods.getPatientDetails(this.state.account).call().then((res)=>{
                let result = res;
                console.log(result);
            });
        }
        catch(e){
            await this.setState({load:false});
            console.log(e);
        }

功能测试说明:

首先,您需要使用addPatient函数创建Patient,可以使用上面的oneclickapp链接来创建Patient。 然后使用getPatientDetails函数获取患者信息(应该是您自己创建患者的地址),您可以在oneclick应用中查看详细信息。

使用oneclickapp可以正常工作,但是我自己的web3源代码

给我错误

错误:溢出(fault =“ overflow”,operation =“ toNumber”,value =“ 3963877391197344453575983046348115674220740746820753546331534351508065746944”,代码= NUM​​ERIC_FAULT,版本= bignumber / 5.0.7)

我不明白为什么函数会返回所有字符串而导致溢出。

注意:DMR是我的合同实例,可以正常获取其他功能,因此可以正常工作。

解决方法

您不应该将promise结构混合在一起(异步/等待与.then),关于直接问题,您介意转储完整的堆栈跟踪信息吗?

        try{
            const res = await this.DMR.methods.getPatientDetails(this.state.account).call();
            console.log(res);
        }
        catch(e){
            await this.setState({load:false});
            console.log(e);
        }

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...