Ist das möglich?
mapping(address => mapping(uint => customStruct[])) someName
Weil ich meinen Fehler nicht debuggen und finden kann ... gibt es nicht genug Gas, oder es stürzt bei diesem Code ab, während versucht wird, someName
.
Zum Beispiel:
uint length = someName[msg.sender][1].length;
someName[msg.sender][1][length].timestamp = block.timestamp;
Ich nehme an, customStruct ist eine Struktur mit timestamp-Eigenschaft. Dann sollte dein Code funktionieren. Aber hier mein Testszenario:
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`
}
}
Welche laufen mit dapple test --report
den folgenden Ausgaben:
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!
Weil ich nicht debuggen kann
...aber das ist sehr wichtig
Nick Johnson