Reach elements of a public mapping ( xxx => Struct ) from another contract ?

Adrien-VAdrien-V Member Posts: 11
Morning guys !

Based on the code bellow, how can I access the element tupple[].b in the contract Dummy from the contract DummyTest ?
I was hopping something like dummy.tupples(index)[index2] like in web3.js

Thanks!

contract Dummy { struct tupple { uint a; uint b; } mapping (uint => tupple ) public tupples; function Dummy() { for ( uint i =0; i<=9 ; i++) { tupples[i] = tupple(i+1,i); } } } contract DummyTest { function DummyTest(address _dummy) { dummy = Dummy(_dummy); } Dummy dummy; function Get_b(uint _index) { // the following will return the first value (a) of tupples at index _index; dummy.tupples(_index); // How to reach -b- ? (without writing an accessor to b in Dummy) } } </code>

Comments

  • Adrien-VAdrien-V Member Posts: 11
    edited September 2015
    I agree, i did write some accessors in my code. It's just a matter of keeping the code short.

    Let's say you have a contract with some structs composed of ten fields ( uint,int address and so on ) It start to be a lot of codes to access the elements..

    But my underlying question is why in web.js i can reach all the elements just by calling the public variables ?

    Am I right by saying :

    var dummy = eth.contract[ABI].at(@) So thanks to the ABI dummy knows the size of each elements so it can "point" to the right element ?
    If so, when I wrote dummy = Dummy(_dummy); is it the same behavior ?


    Post edited by Adrien-V on
  • hugojphugojp Member Posts: 2
    Hi, so just to make it clear. There is currently no way of accessing a public variable from another contract when coding in solidity? Just like Adrien-V, I would rather avoid having to write 10 different accessor functions. Thanks!
  • Adrien-VAdrien-V Member Posts: 11
    edited November 2015
    All the public variables can be GET; not SET;
Sign In or Register to comment.