![](/img/trans.png)
[英]Smart Contract : .methods.request().send() doesn't display anything
[英]Smart Contract with Abstract Methods
我在尝试实现“未来可维护性”软件设计的智能合约时遇到问题。 假设有一个代表personal.sol
合同record.col
还有另一个称为record.col
合同。开始时,此记录只需要由警察局处理,如果他们想将一些数据发送到personal.sol
并更改其状态。 稍后,需要修改此record.sol
,以便医院hospital.sol
现在将需要继承和抽象方法,我现在不知道该怎么做。 以下代码应进一步阐明我要实现的目标。
Person.sol
contract Person
{
Record[] records
strut Record{
string name;
uint time;
}
function updateRecords(string _name, uint _time){
Record _record = Record({name:_name,time:_time});
records.push(_record);
}
}
Record.sol
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
}
}
Police.sol
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
}
}
Hospital.sol
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
}
}
我不希望扩展Record.sol
合同直接与Person.sol
的updateRecords()
方法进行交互。 相反,应该执行检查以验证调用updateRecords()
的约定确实是Record.sol
文件Record.sol
的扩展。是否可以像在Java instanceOf
或.getClass
那样检查此类型.getClass
对不起,格式不好,但我全都是在编辑器中写的。 它不能顺利地转换缩进
简短的答案至少不是很简单,您也许可以使用汇编来实现,但是我不知道,您可以在Record.sol中放置一个函数,例如
function isRecord() public pure returns(bool){
return true;
}
然后从“个人”合同中调用该命令,以验证调用合同是否确实包含记录类。 尽管这可能会使您容易受到安全漏洞的影响,具体取决于您将如何处理这些合同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.