Blockchain 具有抽象方法的智能合约

Blockchain 具有抽象方法的智能合约,blockchain,ethereum,solidity,Blockchain,Ethereum,Solidity,我遇到了一个问题,我正试图实现一个智能合约,并考虑到“未来可维护性”软件设计。假设有一个合同代表一个人personal.sol我们还有另一个合同名为record.col如果警察部门想向personal.sol发送一些数据并更改其状态,则该记录在开始时只需要由警察部门处理。稍后,需要修改此记录。sol,以便医院医院使用。sol 需要继承和抽象方法,现在我不知道该怎么做。下面的代码应该进一步阐明我试图实现的目标 Person.sol 唱片公司 警察,索尔 索尔医院 我不希望扩展Record.sol的

我遇到了一个问题,我正试图实现一个智能合约,并考虑到“未来可维护性”软件设计。假设有一个合同代表一个人
personal.sol
我们还有另一个合同名为
record.col
如果警察部门想向
personal.sol
发送一些数据并更改其状态,则该记录在开始时只需要由警察部门处理。稍后,需要修改此
记录。sol
,以便医院
医院使用。sol

需要继承和抽象方法,现在我不知道该怎么做。下面的代码应该进一步阐明我试图实现的目标

Person.sol

唱片公司

警察,索尔

索尔医院

我不希望扩展
Record.sol
的合同直接与
Person.sol
updateRecords()
方法交互。相反,应该执行一个检查来验证契约调用
updateRecords()
确实是solidity file
记录的扩展。sol
有没有办法像在Java
instanceOf
中一样检查这种类型


很抱歉格式不好,但我都是在编辑器中编写的。它不能平滑地转换缩进。简短的回答是否定的,至少在简单的实体中,你可以使用汇编来完成,但我不知道,你可以在Record.sol中放置一个函数,例如

function isRecord() public pure returns(bool){
    return true;
}
并从Person合约调用它,以验证调用合约是否包含record类。尽管这可能会使您面临安全漏洞,这取决于您将如何处理这些合同

contract Record{
 contract Person {
  struct Record{} // can this work? Object properties are defined in Person
 function updateRecords(string _name, uint _time){};
 }

function commit(address _personaddr, string _name, uint _time){
  _personaddr.transfer(address(this).balance;
  Person person = Person.at(_personaddr); // creates an instance of the Person contract located at _personaddr address
  person.updateRecords(_name,_time);   
}
function abstractMethod() {}
// an abstract method which must be defined in contracts extending this
}
}
contract Police is Record {
//inherits updateRecords & abstract abstractMethod

function policeNewMethod(address _personaddr, string _name, uint _time){
// does something neww
commit(address _personaddr, string _name, uint _time);    
}

function abstractMethod(){
  //police own implementation of the method
} 
}
contract Hospital is Record {
//inherits updateRecords & abstract abstractMethod

 function HospitalNewMethod{
 // does something
 commit(address _personaddr, string _name, uint _time);
 }

 function abstractMethod(){
  //police own implementation of the method
 }
}
function isRecord() public pure returns(bool){
    return true;
}