1

Here's a problem. There's a contract with array of struct items. I need to for loop over every item in another contract.

pragma solidity ^0.4.4;
import 'common/Object.sol';
import 'token/Recipient.sol';

contract Congress is Object, Recipient {
...
    /**
     * @dev Archive of all member proposals 
     */
    Proposal[] public proposals;

    /**
     * @dev Count of proposals in archive 
     */
    function numProposals() constant returns (uint256)
    { return proposals.length; }

    struct Proposal {
        address recipient;
        uint256 amount;
        string  description;
        uint256 votingDeadline;
        bool    executed;
        bool    proposalPassed;
        uint256 numberOfVotes;
        int256  currentResult;
        bytes32 proposalHash;
        Vote[]  votes;
        mapping(address => bool) voted;
    }

  ...
}

and in other contract I need to do something like this

pragma solidity ^0.4.4;
import './Lesson.sol';
import 'foundation/Congress.sol';

contract Lesson_6 is Lesson {
    function Lesson_6(address _dealer, uint _reward)
             Lesson(_dealer, _reward) {}

    function execute(Congress _congress) {
        for(uint i = 0; i < _congress.numProposals(); ++i) {
            if(_congress.proposals[i].proposalPassed) {  // <-- here's the problem
                passed(msg.sender);
                break;
            }
        }
    }
}

Compiler says Error: Indexed expression has to be a type, mapping or array (is function (uint256) constant external returns (address,uint256,inaccessible dynamic type,uint256,bool,bool,uint256,int256,bytes32))

How can I solve this? Thanks

Vourhey
  • 21
  • 1
  • 6

1 Answers1

1

Basically, the struct has no visibility outside the contract, so you're going to have to write a function to unpack the struct and return multiple values, like this example.

ygh
  • 205
  • 1
  • 6