¿Es posible tener asignaciones dentro de asignaciones?

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;
Sí, es posible tener asignaciones dentro de las asignaciones, que puede determinar porque no recibió un error de compilación. Si tiene otros problemas, debe proporcionar más información sobre cuáles son.

Respuestas (1)

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 --reportsalidas 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

Gracias, me diste una pista sobre cómo incrementar la longitud de customStruct[], y ese era el problema.