1

I have struct in an external contract that I need access to

Contract Ext{
 Struct user{
    uint dailybalance;
 }
 mapping ( address => user[] ) userDailyBalances;
}

How do I access the dailybalance for a specific index in the mapped array of structs?

Contract Need{

   function need(){
      Ext x = Ext ( Extcontractaddress );
      uint256 bal = x.userDailyBalances( msg.sender )[0].dailybalance;

  } 
}

Does not work nor does x.userDailyBalances( msg.sender[0].dailybalance ) nor x.userDailyBalances( msg.sender.[0].dailybalance )

Achala Dissanayake
  • 5,819
  • 15
  • 28
  • 38
Dino Anastos
  • 847
  • 1
  • 13
  • 22

1 Answers1

1

You are trying to access the storage of the external contract directly which is not allowed. Refer here.

You need to have a getter method implemented inside the external contract to make this feasible.

External Contract:

Contract Ext{
 Struct user{
    uint dailybalance;
 }
 mapping ( address => user[] ) userDailyBalances;

function getDailyBalance(user) constant returns(unit) {
        return userDailyBalances( user )[0].dailybalance;
    }

}

Your Contract:

Contract Need{

   function need(){
      Ext x = Ext ( Extcontractaddress );
      uint256 bal = x.getDailyBalance( msg.sender );

  }

}

Hope this helps.

Achala Dissanayake
  • 5,819
  • 15
  • 28
  • 38