Created
June 19, 2018 14:17
-
-
Save lismore/ce16b58ce6bde568c2862f682af143b8 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
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
/** | |
* =============Copyright 2018 Siemens Mobility Ltd======== | |
* | |
* Author: Patrick Lismore - [email protected] | |
* | |
* =============Mobility Smart Contract==================== | |
* | |
* Incentivised commuter Journeys via Smart Contract | |
* & Cryptocurrency | |
* | |
* Mobile App calls and updates way points on route to change | |
* SmartContract state | |
* | |
* When all way points hit along journey the cohtract is | |
* fulfiled and the transfer of crypto moves from the Client | |
* to the commuter | |
* | |
* / | |
pragma solidity ^0.4.0; | |
contract FuturelandSiecoin { | |
/* Define commuter address of type address */ | |
address public commuter; | |
/* Define variable owner of the type address*/ | |
address public owner; | |
/* Define jobidentifer of type string */ | |
string public jouneryidentifer; | |
/* Define client address of type address */ | |
address public client; | |
enum WayPointStatus { JourneyNotStarted, JourneyStarted, JourneyCompleted, JourneyNotCompleted, JourneyAborted } | |
/* State of waypoint status */ | |
WayPointStatus public WayPointState; | |
//Number of Way Points in Journey | |
int32 public JourneyWayPoints = 2; | |
//Way Points | |
string constant WayPointJupiter = "jupiter"; | |
string constant WayPointMars = "mars"; | |
event Aborted(); | |
event Complete(); | |
event JourneyAborted(); | |
event CommuterConfirmed(); | |
event JourneyStarted(); | |
event JourneyCompleted(); | |
event JourneyNotStarted(); | |
event JourneyNotCompleted(); | |
//update waypoint - takes a way point name passed from Mobility App | |
function updateWayPoint(string wayPoint)public returns(bool){ | |
bool result = validateWayPoint(wayPoint); | |
if(result){ | |
//if journey not started | |
if(JourneyWayPoints == 2){ | |
//update journey | |
WayPointState = WayPointStatus.JourneyStarted; | |
//update way point count -1 from total way points hit | |
JourneyWayPoints = JourneyWayPoints -1; | |
return result; | |
} | |
//update way point count -1 from total way points hit | |
JourneyWayPoints = JourneyWayPoints -1; | |
} | |
return result; | |
} | |
//update way point state | |
function validateWayPoint(string wayPoint) private view returns (bool){ | |
if(keccak256(wayPoint) == keccak256(WayPointJupiter)){ | |
return true; | |
} | |
if(keccak256(wayPoint) == keccak256(WayPointMars)){ | |
return true; | |
} | |
return false; | |
} | |
/* authorised address */ | |
address public authorised; | |
/* State of Smart Contract */ | |
enum State { Created, InProgress, CommuterAborted, JourneyCompleted, NotCompleted, Complete, Inactive } | |
/* State of contract status */ | |
State public state; | |
modifier condition(bool _condition) { | |
require(_condition); | |
_; | |
} | |
modifier onlyClient() { | |
require( | |
msg.sender == client, | |
"Only client can call this." | |
); | |
_; | |
} | |
modifier onlyCommuter() { | |
require( | |
msg.sender == commuter, | |
"Only commuter can call this." | |
); | |
_; | |
} | |
modifier inState(State _state) { | |
require( | |
state == _state, | |
"Invalid state." | |
); | |
_; | |
} | |
/* Contract constructor for basic journey smart contract */ | |
constructor(string jId) payable{ | |
jouneryidentifer = jId; | |
client = msg.sender; | |
owner = msg.sender; | |
} | |
/// Abort the smart contract and reclaim the Coins. | |
/// Can only be called by the seller before | |
/// the contract is locked. | |
function abort() public onlyClient inState(State.Created) | |
{ | |
if(WayPointState == WayPointStatus.JourneyAborted){ | |
emit Aborted(); | |
state = State.Inactive; | |
client.transfer(this.balance); | |
} | |
} | |
function journeyAbort() public onlyCommuter inState(State.InProgress){ | |
emit JourneyAborted(); | |
state = State.CommuterAborted; | |
WayPointState = WayPointStatus.JourneyAborted; | |
} | |
/// Confirm the Commuter as the commuter in the contract | |
/// The coin will be locked until confirmJourneyCompleted | |
/// is called. | |
function acceptSmartJourney() public inState(State.Created) payable returns(bool) | |
{ | |
emit CommuterConfirmed(); | |
state = State.InProgress; | |
WayPointState = WayPointStatus.JourneyNotStarted; | |
commuter = msg.sender; | |
return true; | |
} | |
/// Confirm that you (the Client) received the work commissioned. | |
/// This will release the locked WORK. | |
function confirmJourneyCompleted() public onlyCommuter inState(State.InProgress) returns(bool) | |
{ | |
if(JourneyWayPoints == 0){ | |
emit JourneyCompleted(); | |
state = State.JourneyCompleted; | |
WayPointState = WayPointStatus.JourneyCompleted; | |
return true; | |
} | |
return false; | |
} | |
/// Confirm that you (the Client) received the work commissioned. | |
/// This will release the locked WORK. | |
function confirmJourneyCompletedClient() public onlyClient inState(State.JourneyCompleted) payable returns(string) | |
{ | |
emit Complete(); | |
// It is important to change the state first because | |
// otherwise, the contracts called using `send` below | |
// can call in again here. | |
state = State.Complete; | |
//worker.transfer(value); | |
commuter.transfer(this.balance); | |
return "Commuter Incentivised with SieCoin"; | |
} | |
/* Returns the value of WORK locked in contract */ | |
function contractBalance() constant returns (uint256 amount){ return this.balance; } | |
/* Function to recover the funds on the contract */ | |
function KillRecoverDispute() public { if (msg.sender == owner) selfdestruct(owner); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment