UNTEN AKTUALISIERT: (Was bei mir funktioniert hat)
Beim Kompilieren und Ausführen des folgenden Codes auf Remix. Wenn ich versuche, den Master mit _ownerName zu initialisieren, erhalte ich die folgende Fehlermeldung „Dieser Vertrag implementiert nicht alle Funktionen und kann daher nicht erstellt werden“.
Ich wollte neue Kundenverträge mit dem CustomerTemplate Contract erstellen
pragma solidity ^0.4.11;
//------------------------------------------------------------------------------------
//----- Templates
//-----
//------------------------------------------------------------------------------------
contract CustomerTemplate {
bytes32 public customerName;
bytes32 public customerLoc;
function CustomerTemplate (bytes32 _customerName, bytes32 _customerLoc) {
customerName = _customerName;
customerLoc = _customerLoc;
}
}
//------------------------------------------------------------------------------------
//----- Master
//----- Initialize Customer Master with Customer Name and Total Budget
//------------------------------------------------------------------------------------
contract Master is CustomerTemplate{
address public owner;
bytes32 public ownerName;
address[] newCustomers;
modifier onlyByMaster() {
require(msg.sender == owner);
_;
}
function Master (bytes32 _ownerName) {
owner = msg.sender;
ownerName = _ownerName;
}
function createCustomer (bytes32 _customerName, bytes32 _customerLoc) {
address myCustomer = new CustomerTemplate(_customerName, _customerLoc);
newCustomers.push(myCustomer);
}
function killContract() constant onlyByMaster {
if (msg.sender == owner) selfdestruct(owner);
}
}
(UPDATE) Folgendes hat bei mir funktioniert:
pragma solidity ^0.4.15;
contract Template {
bytes32 public custName;
bytes32 public custLoc;
address public contractAddress;
function Template () {
custName = "0xDEFAULT";
custLoc = "0xDEFAULT";
contractAddress = address(this);
}
function AssignCustomerAttributes (bytes32 _custName, bytes32 _custLoc)
returns (bool isSuccess) {
custName = _custName;
custLoc = _custLoc;
contractAddress = address(this);
return true;
}
}
//------------------------------------------------------------------------------------
//----- Master
//----- Initialize Customer Master with Customer Name and Total Budget
//------------------------------------------------------------------------------------
pragma solidity ^0.4.15;
contract Template {
bytes32 public custName;
bytes32 public custLoc;
address public contractAddress;
function Template () {
custName = "0xDEFAULT";
custLoc = "0xDEFAULT";
contractAddress = address(this);
}
function AssignCustomerAttributes (bytes32 _custName, bytes32 _custLoc)
returns (bool isSuccess) {
custName = _custName;
custLoc = _custLoc;
contractAddress = address(this);
return true;
}
}
//------------------------------------------------------------------------------------
//----- Master
//----- Initialize Customer Master with Customer Name and Total Budget
//------------------------------------------------------------------------------------
contract Master {
address public masterContractAddress;
bytes32 public masterName = "";
Template myCustTemp;
function Master () {
masterContractAddress = address(this);
}
function updateOwnerName (bytes32 _masterName) {
masterName = _masterName;
}
function createCustomer (bytes32 _custName, bytes32 _custLoc) returns (bool flag) {
Template myCust = new Template();
if (myCust.AssignCustomerAttributes(_custName, _custLoc)) {
return true;
} else return false;
}
}
Sie müssen alle für die übergeordnete Klasse erforderlichen Argumente bereitstellen. Aus den Solidity-Dokumenten hier ,
Abgeleitete Verträge müssen alle für die Basiskonstruktoren erforderlichen Argumente bereitstellen.
So würde der Baumeister aussehen,
function Master (bytes32 _ownerName, bytes32 _loc) CustomerTemplate(_ownerName, _loc) {
owner = msg.sender;
ownerName = _ownerName;
}
CustomerTemplate()
still wirft "Dieser Vertrag implementiert nicht alle Funktionen"Ich hatte das gleiche Problem. Dies kann passieren, wenn Sie die Vererbung verwenden.
Die Lösung ist ziemlich trivial. In Remix (auch bekannt als Browser-Solidity) befindet sich neben der Schaltfläche "Erstellen" ein Dropdown-Menü. Sie müssen nur die tatsächlich bereitzustellende Vertragsimplementierung auswählen, nicht die Schnittstelle.
Achala Dissanayake
userDSSR
Achala Dissanayake
userDSSR
Achala Dissanayake
userDSSR
Rob Hitchens
contractAddress
es notwendig ist. Man müsste die kennencontractAddress
, um die Getter-Funktion aufzurufen. Wenn man es weiß, warum fragen sie?userDSSR