0

I've created a consortium based network where I have two contracts deployed.

pragma solidity ^0.4.4;

contract ScoreStore{
    mapping(string => int) PersonScores;

    function AddPersonScore(string name, int startingScore){
        if(PersonScores[name]>0){
            throw;
        } else {
            PersonScores[name] = startingScore;
        }
    }

    function GetScore(string name) returns (int){
        return PersonScores[name];
    }
}

This contract works no problem when interacting with it directly. The second contract:

pragma solidity ^0.4.4;
contract IScoreStore{
    function GetScore(string name) returns (int);
}

contract MyGame{
    function ShowScore(string name) returns (int)
    {
        IScoreStore scoreStore = IScoreStore(0xEB058f7E140991811ff815335DA5bB7e593c8359);
        return scoreStore.GetScore(name);
    }
}

When I make a call to the MyGame contract to ShowScore("Oliver") it returns

{ [String: '0'] s: 1, e: 0, c: [ 0 ] } 

When I call GetScore("Oliver") through the ScoreStore contract I get the expected result

{ [String: '15'] s: 1, e: 1, c: [ 15 ] }

What is it that I'm missing?

1 Answer 1

0

This works as expected in Remix. The only possibility is that you wrote the wrong address when instantiating the MyGame.

However, your code needs improvement, many warnings appear. I did a bit of housekeeping:

pragma solidity ^0.4.24;

contract ScoreStore{
    mapping(string => uint) PersonScores;

    function AddPersonScore(string name, uint startingScore) public {
        require(PersonScores[name]>0);
        PersonScores[name] = startingScore;
    }

    function GetScore(string name) public view returns (uint){
        return PersonScores[name];
    }
}

And for the second:

pragma solidity ^0.4.24;

contract IScoreStore{
    function GetScore(string name) public view returns (int);
}

contract MyGame{
    function ShowScore(string name) public view returns (int) {
        IScoreStore scoreStore = IScoreStore(0xEB058f7E140991811ff815335DA5bB7e593c8359);
        return scoreStore.GetScore(name);
    }
}

Hope this helps

3
  • Hmmm the address being wrong is what I am thinking what the problem is however I would have assumed it would have thrown an exception when I call MyGame.ShowScore("Oliver") as the ref would be invalid no? I'm going to make your changes and play around with it some more.
    – GingerYeti
    Jun 10, 2018 at 23:24
  • Yes the only possible problem is the address I run this and it works without changing anything in your code except the address, because it change when I deploy. On the other side I think removing warnings is healthy because this could lead to unexpected behaviors. If this answer your question please accept the answer.
    – Jaime
    Jun 11, 2018 at 6:11
  • Totally. I think there is/was something wrong with my network deployment. The original ScoreStore contract was no longer function correctly. There appears to be a deeper seeded issue. At least I have validation that it's not the contracts themselves. Thanks for the help.
    – GingerYeti
    Jun 13, 2018 at 3:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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