Tengo una función que devuelve una lista de BetProposition
contratos inteligentes:
function getBetsForMatchup(uint matchupIdentifier) public returns (BetProposition[]) {
return bets[matchupIdentifier];
}
Más tarde, inicializo una matriz de variables locales como tal, para poder recorrerlas:
BetProposition[] betsToCancel = getBetsForMatchup(matchupIdentifier);
Sin embargo, esto no parece funcionar y me sale este error:
TypeError: Type contract BetProposition[] memory is not implicitly convertible to expected type contract BetProposition[] storage pointer.
BetProposition[] betsToCancel = getBetsForMatchup(matchupIdentifier);
^------------------------------------------------------------------^
No estoy totalmente seguro de lo que esto significa. Cualquier ayuda apreciada. Gracias
El compilador cree que está tratando de almacenar el valor de retorno de getBetsForMatchup en almacenamiento de contrato (permanente).
Intenta cambiar
BetProposition[] betsToCancel = getBetsForMatchup(matchupIdentifier);
a
BetProposition[] memory betsToCancel = getBetsForMatchup(matchupIdentifier);
Esto compilado en remix:
pragma solidity ^0.4.20;
contract BetProposition {
uint public somevar;
function BetProposition(uint _some) public {
somevar = _some;
}
}
contract Tester2 {
mapping(uint => BetProposition[]) bets;
function getBetsForMatchup(uint matchupIdentifier) public view returns (BetProposition[]) {
return bets[matchupIdentifier];
}
function other(uint matchupIdentifier) public view returns(uint) {
uint total = 0;
BetProposition[] memory betsToCancel = getBetsForMatchup(matchupIdentifier);
for (uint i = 0; i < betsToCancel.length; i++) {
total = total + betsToCancel[i].somevar();
}
return total;
}
}
usuario339946
Howard
fred douglis
Howard