I am developing a smart contract which I have two contracts(A and B). I have an array variable in A and fill it with values but when I get that variable from B, the array address is empty.
pragma solidity ^0.4.10;
contract Censo{
struct Persona{
string name;
uint age;
uint weight;
uint number;
uint position;
address[] propuestasVotadas;
}
address personaAutorizada;
mapping(address => Persona) public personas;
address[] public personasList;
function Censo(){
personaAutorizada = msg.sender;
}
function existePersona(address _address) public constant returns(bool){
if(personasList.length == 0) return false;
return (personasList[personas[_address].position] == _address);
}
function addPersona(address _address, string _name, uint _age, uint _weight, uint _number) public{
require(!existePersona(_address));
personas[_address].name = _name;
personas[_address].age = _age;
personas[_address].weight = _weight;
personas[_address].number = _number;
personas[_address].position = personasList.push(_address) - 1;
}
function getNumPersonas() public returns(uint){
return personasList.length;
}
}
contract MinisterioInterior{
struct Propuesta{
string nombre;
string descripcion;
uint numVotos;
uint position;
}
event PropuestaAdded(address _address, uint now);
event PersonaVotePropuesta(address _addressPropuesta, address _addressPersona, uint now);
mapping(address => Propuesta) propuestas;
address[] propuestasList;
address personaAutorizadaMinisterio;
function MinisterioInterior(){
personaAutorizadaMinisterio = msg.sender;
}
function existePropuesta(address _address) returns(bool){
if(propuestasList.length == 0) return false;
return (propuestasList[propuestas[_address].position] == _address);
}
function crearPropuesta(address _address, string _nombre, string _descripcion) returns(bool){
require(!existePersona(_address));
propuestas[_address].nombre = _nombre;
propuestas[_address].descripcion = _descripcion;
propuestas[_address].numVotos = 0;
propuestas[_address].position = propuestasList.push(_address) - 1;
return true;
}
}
if(propuestasList.length == 0) return false;. you should avoid this. You should fail fast and hard. If the array length is zero, it should not be called because your are spending gas here. IMHO, you should userequire(propuestasList.length>0)– Luiz Soares Dec 01 '17 at 11:09