ACTUALIZADO A CONTINUACIÓN: (Lo que funcionó para mí)
Mientras compila y ejecuta el siguiente código en Remix. Cuando intento inicializar Master con _ownerName, aparece el siguiente error "Este contrato no implementa todas las funciones y, por lo tanto, no se puede crear".
Quería crear nuevos contratos de cliente utilizando el contrato de plantilla de cliente
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);
}
}
(ACTUALIZAR) Lo siguiente funcionó para mí:
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;
}
}
Debe proporcionar todos los argumentos necesarios para la clase principal. De los documentos de solidez aquí ,
Los contratos derivados deben proporcionar todos los argumentos necesarios para los constructores básicos.
Entonces el constructor maestro se vería así,
function Master (bytes32 _ownerName, bytes32 _loc) CustomerTemplate(_ownerName, _loc) {
owner = msg.sender;
ownerName = _ownerName;
}
CustomerTemplate()
todavía arroja "Este contrato no implementa todas las funciones"Tuve el mismo problema. Podría suceder si usa la herencia.
La solución es bastante trivial. Hay un menú desplegable cerca del botón "Crear" en Remix (también conocido como Browser-Solidity). Solo necesita seleccionar la implementación del contrato real para implementar, no la interfaz.
Achala Dissanayake
usuarioDSSR
Achala Dissanayake
usuarioDSSR
Achala Dissanayake
usuarioDSSR
Rob Hitchens
contractAddress
sea necesaria. Uno necesitaría saber elcontractAddress
para invocar la función getter. Si uno sabe, ¿por qué pregunta?usuarioDSSR