es posible?
mapping(address => mapping(uint => customStruct[])) someName
Debido a que no puedo depurar y encontrar mi error ... ¿no hay suficiente gasolina o se bloquea en este código al intentar llenar someName
.
Por ejemplo:
uint length = someName[msg.sender][1].length;
someName[msg.sender][1][length].timestamp = block.timestamp;
Supongo que customStruct es una estructura con propiedad de marca de tiempo. Entonces tu código debería funcionar. Sin embargo, aquí mi escenario de prueba:
import "dapple/test.sol";
contract MyTest is Test {
struct Struct {
uint timestamp;
}
// Mapping test
mapping(uint => mapping(uint => uint)) mymap;
mapping(address => mapping(uint => Struct[])) someName;
function testNestedMappings() {
//@log test nested mappings
mymap[1][2] = 42;
//@log mymap[1][2] = `uint mymap[1][2]`
//@log test struct array:
//@log someName[msg.sender][1].length = `uint someName[msg.sender][1].length`
//@log incrementing length
someName[msg.sender][1].length++;
//@log saving timestamp to last entry
someName[msg.sender][1][someName[msg.sender][1].length - 1].timestamp = block.timestamp;
//@log `uint someName[msg.sender][1][someName[msg.sender][1].length-1].timestamp`
}
}
Que se ejecutan con dapple test --report
salidas de la siguiente:
MyTest
test nested mappings
LOG: test nested mappings
LOG: mymap[1][2] = 42
LOG: test struct array:
LOG: someName[msg.sender][1].length = 0
LOG: incrementing length
LOG: saving timestamp to last entry
LOG: 1460035092
Passed!
Porque no puedo depurar
...pero esto es muy importante
nick johnson