0
    pragma solidity ^0.4.4;


contract heheBox { 

    struct DataBox {
        mapping(address => string) Data_01;
        mapping(address => string) Data_02;
    }

    mapping(address => DataBox) DataBox_hehe;

    function save(string _InputData_01, string _InputData_02) public  {
        DataBox_hehe[msg.sender].Data_01[msg.sender] = _InputData_01;
        DataBox_hehe[msg.sender].Data_02[msg.sender] = _InputData_02;           
    }   

    function display(address _address) constant public returns (struct) {
        return DataBox_hehe[_address];         
    }   

}

I wish the function display to display the mapping DataBox_hehe but it doesn't. Can anyone can teach me how can do this?

thank you very much!! enter image description here

Shane Fontaine
  • 18,036
  • 20
  • 54
  • 82

1 Answers1

0

Instead of returning structs (which would be returns(DataBox)) return individual elements. This keeps it compatible with other contracts.

Try this:

contract heheBox { 

    struct DataBox {
        mapping(address => string) Data_01;
        mapping(address => string) Data_02;
    }

    mapping(address => DataBox) DataBox_hehe;

    function save(string _InputData_01, string _InputData_02) public  {
        DataBox_hehe[msg.sender].Data_01[msg.sender] = _InputData_01;
        DataBox_hehe[msg.sender].Data_02[msg.sender] = _InputData_02;
    }   

    function display(address addressBox, address addressMap) constant public returns(string, string) {
        return(DataBox_hehe[addressBox].Data_01[addressMap], DataBox_hehe[addressBox].Data_02[addressMap]);
    }   

}

Hope it helps.

Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145
  • Rob Hitchens my teacher thank you so much it is work but my original hope is get the one struct mapping i think this will thrift the gas Do you think it is ture? anyway i am thank you so much for you comment!! – i don't like tell you hehe Mar 24 '18 at 07:29
  • You should consider leaving 'mappings` where they are. Instead, consider passing keys around. It is possible to return a dynamic array (of keys) but there are non-trivial limitations and it would almost always be more costly than one-key-at-a-time, as needed. You may be looking for a Mapped Structs with Index over here: https://ethereum.stackexchange.com/questions/13167/are-there-well-solved-and-simple-storage-patterns-for-solidity or even thinking about https://medium.com/@robhitchens/enforcing-referential-integrity-in-ethereum-smart-contracts-a9ab1427ff42 – Rob Hitchens Mar 24 '18 at 16:27
  • thank you very much ,this complete is my need answer medium.com/@robhitchens/… – i don't like tell you hehe Mar 25 '18 at 04:56