I'm trying to map with more than one structs. First mapping contains common details need to be mapped to every item and then second mapping should be carried out according to the item type.
pragma solidity ^0.4.11;
contract MyContract {
struct CommonDetails {
string name;
uint32 group;
mapping (string => SpecificDetails1) items;
}
struct SpecificDetails1{
uint32 capacity;
string owner;
}
struct SpecificDetails2{
uint32 capacity;
string owner;
}
mapping (address => CommonDetails) commonMapping;
mapping (string => address)specificMapping;
function setName(string _name, uint32 _group){
commonMapping[tx.origin] = CommonDetails(_name, _group);
if (_group == 1){
// add SpecificDetails1 along with existing common details
// if _group == 2 then add SpecificDetails2
}
}
function getName() constant returns(address, string, uint32) {
return (tx.origin, commonMapping[tx.origin].name,
commonMapping[tx.origin].group);
// also want SpecificDetails in getter function
}
Initially, common details should be mapped to every item and then according to the input (for the group), 2nd struct should be mapped.
I have tried to create an array within struct and then push the specific details to that array but no joy.
My question is how can we perform 2nd mapping to another struct that is based on the input getting from the initial mapping?
If this is not possible within the single contract, can we do this importing this contract function into another contract and then perform 2nd mapping? And also how to get the output of both mapping in getter function, also.
Any guidance would definitely be appreciated!