0

I have two structs - property and owner.

struct owner {
    string ownerName;
    string ownerID;
}
struct property {
    string location;
    uint sqFeet;        
    owner[] owners;
}

I want to keep track of the owners of a property. So the current owner of a property will be the owner who was added last.

mapping(uint => property) selectedProperty;
function createProperty(string memory l,uint sf,string memory on,string memory OID,string memory PID) { //PID is calculated based on property information
     selectedProperty[PID].location = l;
     selectedProperty[PID].sqFeet = sf;
     selectedProperty[PID].owners.push(owner(on,OID));
}
function display(uint PID) public view returns(property memory) {
     return selectedProperty[PID]
} 

When I display the property details in remix, I get the following as output 0: tuple(string,uint,tuple(string,string)[]): London,4000,0,Mike,NTX670

Why 0 is displayed?

1
  • There is no reason to expect exactly that. Suggest you post a small complete contract that compiles including pragma for the precise compiler version. Mar 24, 2021 at 2:29

1 Answer 1

0

It looks to me like it's returning the result just fine. If you're just wondering why the 0 is there, that's just the index of the return. If you were to return two objects like the example:

function foo() external returns(uint, uint){
    return(7,12)
}

Then the output would look like:

decoded output: { "0": "uint: 7", "1": "uint: 12" }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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