Created
September 9, 2019 15:04
-
-
Save sergejmueller/be841cf3e862893c319d6974dc9bf66f to your computer and use it in GitHub Desktop.
Locations Smart Contract
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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