2
   struct list{
       string typo;  // name of dataset
       address head;
   }

  mapping (string => list) _list;

 struct node{
     address add;
     address next; 
 }

 mapping (string =>mapping(address=>node)) _node;

 function add(string _typo1,address _addr){
        addToList(_typo1);
        addToNodes(_typo1 , _addr);

}

function addToList(string _typo){
    _list[_typo].typo = _typo;
}

function addToNodes(string _typo,address _addr){

    _node[_typo][_addr].next = _addr;
    _node[_typo][_addr].add =_addr;

}

Above is the code snippet of the contract I have been trying to make work but somehow I am not getting anywhere. If I call only on function either addToList() or addToNodes() then it works fine but if I call both the same time it won't work.

PS: I am using private testnet here.

gas limitation is not an issue here I tried to provide maximum gas but it won't work.

  • 1
    I may be out-of-date here but using a string as a mapping key feels icky. Try making your mapping key bytes32 instead of string, and make it with something like _node[keccak256(_typo)][_addr].next = _addr; – Edmund Edgar Feb 16 '17 at 5:28
1

There's a typo in _typo :-)

"_typo" is undefined in:

addToNodes(_typo , _addr);

Maybe should be

addToNodes(_typo1 , _addr);

It looks like you're after something more intricate but I'm unsure of the goal.

Compiles and works:

contract X {

  struct list{
       string typo;  // name of dataset
       address head;
   }

  mapping (string => list) _list;

  struct node{
     address add;
     address next; 
  }

  mapping (string =>mapping(address=>node)) _node;

  function add(string _typo1,address _addr){
        addToList(_typo1);
        addToNodes(_typo1 , _addr);
  }

  function addToList(string _typo){
    _list[_typo].typo = _typo;
  }

  function addToNodes(string _typo,address _addr){

    _node[_typo][_addr].next = _addr;
    _node[_typo][_addr].add =_addr;

  }

}

In Remix to show it working:

enter image description here

Hope it helps.

  • I am doing the same as above and blocks are being mined and added to the blockchain but data is not getting updated. So whenever I try to get the data of struct node it returns nothing. Any suggestions on debugging. I tried eth.getTransactionReceipt() but all looks fine there. I am using private chain here. – Shirish Patel Feb 23 '17 at 4:54
  • You have no getter function(s) to actually retrieve values. I was going to put one together but I got lost in some things that seem to need correction. Can you plainly describe the structure and purpose? I will make it easier hit the mark. – Rob Hitchens - B9lab Feb 23 '17 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.