0

I've two contracts deployed one is UserRegistration and another is Exam

I've getUser(uint id) method to fetch data of particular user using users mapping,

function getUser(uint _id) public constant returns(uint,string,string,uint,uint) { User memory c = users[_id]; return( c.id, c.name, c.class, c.age, c.pincode); } 

Now, I've another contract Exam in which I want to call getUser() function from UserRegistration contract so, I've done it like this,

pragma solidity 0.4.25; contract UserRegistration { function getUserCount() public returns(uint); function getUser(uint) public returns(uint,string,string,uint,uint); } contract Exam { address private addrUsr; uint public count; UserRegistration r; constructor(address _addrUsr) { addrUsr=_addrUsr; r = UserRegistration(addrUsr); } function updateCount() public { count=r.getUserCount(); } function getUserData(uint _id) public { //WHAT to do HERE//; } } 

But, how to parse the values returned by getUser() function into getUserData() so that if I call getUserData() function it should return all the values returned by getUser(), and as the values returned by getUser() function are of different data type I can't store them in an array.

Please help me

1 Answer 1

0

I noticed you're using constant in the registry. If that's right for the compiler you're using, stick with that, otherwise view for a newer compiler.

In any case, use it in both:

You should add view to the getter functions in both contracts.

function getUserData(uint _id) public view returns (uint,string,string,uint,uint) { // or constant //WHAT to do HERE// uint id; string name; string class; uint age; uint pincode; (id, name, class, age, pincode) = r.getUser(_id); return(id, name, class, age, pincode); } 

Hope it helps.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.