1

I want to reuse on type DateRange in two contracts. However, I fail with multiple errors. Currently I have one error:

G21FE98E9 Member "endTicks" not found or not visible after argument-dependent lookup in tuple(uint64,uint64)

I didn't find any related info that could help solve this issue.

Here is complete contract code:

pragma solidity ^0.4.21;

contract SeasonFactory {    
    address public owner;
    address[] public seasons;

    event SeasonCreated(uint64 indexed beginTicks, uint64 indexed endTicks, address season);

    function SeasonFactory() public {
        owner = msg.sender;
    }

    function newSeason(uint64 beginTicks, uint64 endTicks) public restricted {
        require(beginTicks < endTicks);
        require(seasons.length == 0 || Season(seasons[seasons.length - 1]).period().endTicks() < beginTicks);

        Season season = new Season(owner, beginTicks, endTicks);
        seasons.push(season);
        emit SeasonCreated(beginTicks, endTicks, season);
    }

    function getSeasonsCount() public view returns(uint) {
        return seasons.length;
    }

    function getSeasonForDate(uint64 ticks) public view returns(address) {
        for (uint i = seasons.length - 1; i >= 0; i--) {
            Season season = Season(seasons[i]);
            if (ticks >= season.period.beginTicks() && ticks <= season.period.endTicks())
                return season;
        }
        return 0;
    }

    modifier restricted {
        require(owner == msg.sender);
        _;
    }
}

contract Season {
    address public owner;
    SharedTypes.DateRange public period;

    function Season(address owner_, uint64 beginTicks, uint64 endTicks) public {
        owner = owner_;
        period = SharedTypes.DateRange(beginTicks, endTicks);
    }
}

library SharedTypes {
    struct DateRange {    
        uint64 beginTicks;
        uint64 endTicks;
    }
}

What could be wrong here?

Alex Zhukovskiy
  • 491
  • 1
  • 5
  • 14
  • What is the purpose of Season(seasons[seasons.length - 1]).period().endTicks() < beginTicks) and Season season = Season(seasons[i]) when Season needs 3 parameters? – ReyHaynes Apr 24 '18 at 15:15
  • Also, if you're inheriting the Season function from contract Season, you need to place that contract above the SeasonFactory and inherit it properly with contract SeasonFactory is Season {} – ReyHaynes Apr 24 '18 at 15:18
  • @ReyHaynes usage with single parameter should be a cast, I guess. I found it somewhere on the internet. There is no inheritance, Factory is obviosly not an object. – Alex Zhukovskiy Apr 24 '18 at 15:20
  • Functions are explicit in use, if it has 3 parameters, you need 3 parameters. You can, however, create multiple functions with the same name and different amount of parameters, which is called Function Overloading – ReyHaynes Apr 24 '18 at 15:28
  • I'm just casting some address which is known to be a contract T. See https://dappsforbeginners.wordpress.com/tutorials/interactions-between-contracts/ – Alex Zhukovskiy Apr 24 '18 at 15:57

1 Answers1

1

According to this post, a contract cannot access another contract's storage directly.

You probably need to implement a getter function, as described in this post.

I tried using the following function in your Season contract and it worked fine:

function getTicks(uint ind) view public returns( uint64 ){
    if(ind == 1) return period.endTicks;
    else return period.beginTicks;
}
sfmiller940
  • 498
  • 1
  • 3
  • 9