guys why does getBal() in bbb contract returns the score.balance but not Score struct? how can i access the full Score struct (and in particular the scores mapping) in contract aaa from bbb without using functions getMap and getBal?
Feb 23, 2023, 11:35 AM
make something like this in contract aaa and just call it from contract bbb?
function getFulldata(uint256 votersNumb, uint256 scoresNumb) external view returns (uint256 voterBalance, uint256 voterScore) {
voterBalance = voters[votersNumb].balance;
voterScore = voters[votersNumb].scores[scoresNumb];
return (voterBalance, voterScore);
}
function getFulldata(uint256 votersNumb, uint256 scoresNumb) external view returns (uint256 voterBalance, uint256 voterScore) {
voterBalance = voters[votersNumb].balance;
voterScore = voters[votersNumb].scores[scoresNumb];
return (voterBalance, voterScore);
}
Feb 23, 2023, 12:20 PM
yeah but i can't access the aaa contract
i just want to read public data of aaa from bbb
Feb 23, 2023, 12:21 PM
you can via interface
this code works
interface ScoreContract {
function getFulldata(uint256 votersNumb, uint256 scoresNumb) external view returns (uint256,uint256);
}
contract readScores {
function readData(address scoreCA, uint256 voterNumb, uint256 scoreNumb) public view returns(uint256 voterBalanace, uint256 voterScore) {
(voterBalanace, voterScore) = ScoreContract(scoreCA).getFulldata(voterNumb, scoreNumb);
return (voterBalanace,voterScore);
}
}
interface ScoreContract {
function getFulldata(uint256 votersNumb, uint256 scoresNumb) external view returns (uint256,uint256);
}
contract readScores {
function readData(address scoreCA, uint256 voterNumb, uint256 scoreNumb) public view returns(uint256 voterBalanace, uint256 voterScore) {
(voterBalanace, voterScore) = ScoreContract(scoreCA).getFulldata(voterNumb, scoreNumb);
return (voterBalanace,voterScore);
}
}
i dont know if there is even getter created for mapping inside a struct like this
Feb 23, 2023, 12:26 PM
it reverts the transaction
and i kind of don't understand why it will work if there is no getFulldata in aaa contract
Feb 23, 2023, 12:27 PM
well make one
Feb 23, 2023, 12:27 PM
make what?) i don't have access to aaa
Feb 23, 2023, 12:28 PM
i see, cant help you then
Feb 23, 2023, 12:30 PM
it's really weird cuz
uint a = aaa(0xf8e81D47203A594245E36C48e151709F0C19fBe8).voters(1);
should return Score struct, but returns score.balance (if i do Score storage a then get an error "can't conver uint to Score")
uint a = aaa(0xf8e81D47203A594245E36C48e151709F0C19fBe8).voters(1);
should return Score struct, but returns score.balance (if i do Score storage a then get an error "can't conver uint to Score")
Feb 23, 2023, 12:32 PM
i think yes but you should create the getter inside the aaa
but in your case thats not helpful
Feb 23, 2023, 12:34 PM