Skip to content

Instantly share code, notes, and snippets.

@sergejmueller
Created September 9, 2019 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergejmueller/be841cf3e862893c319d6974dc9bf66f to your computer and use it in GitHub Desktop.
Save sergejmueller/be841cf3e862893c319d6974dc9bf66f to your computer and use it in GitHub Desktop.
Locations Smart Contract
pragma solidity 0.4.26;
contract Locations {
struct Location {
string lat;
string long;
}
Location[] locations;
mapping (address => uint256[]) accounts;
function addLocation(string lat, string long) public {
uint256 locationIndex = locations.push(
Location({
lat: lat,
long: long
})
) - 1;
accounts[msg.sender].push(locationIndex);
}
function getLocationByIndex(uint256 locationIndex) public view returns (
string lat,
string long
) {
return (
locations[locationIndex].lat,
locations[locationIndex].long
);
}
function getLocationsByAccount(address account) public view returns (uint256[] memory) {
return accounts[account];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment