Skip to content

Instantly share code, notes, and snippets.

@brynbellomy
Last active July 11, 2017 21:39
Show Gist options
  • Save brynbellomy/9d4ef5606e4d101cd538bfc8d1b63f3d to your computer and use it in GitHub Desktop.
Save brynbellomy/9d4ef5606e4d101cd538bfc8d1b63f3d to your computer and use it in GitHub Desktop.
medium-return-struct-public-func-3.sol
pragma solidity ^0.4.13;
contract Project
{
struct Person {
string name;
uint funds;
}
// this is the mapping for which we want the
// compiler to automatically generate a getter.
mapping(address => Person) public people;
// this is what the automatically generated getter
// looks like (we don't need to implement this ourselves).
function getPerson(address id)
public
returns (string name, uint funds)
{
// copy the data into memory
Person memory p = people[id];
// break the struct's members out into a tuple
// in the same order that they appear in the struct
return (p.name, p.funds);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment