This repository has been archived by the owner on Dec 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
319 additions
and
421 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
pragma solidity 0.5.7; | ||
pragma experimental "ABIEncoderV2"; | ||
|
||
import "@counterfactual/contracts/contracts/interfaces/CounterfactualApp.sol"; | ||
|
||
|
||
contract PreimageApp is CounterfactualApp { | ||
|
||
struct AppState { | ||
bytes32 image; | ||
bool preimageRevealed; | ||
} | ||
|
||
struct Action { | ||
bytes preimage; | ||
} | ||
|
||
function isStateTerminal(bytes memory encodedState) | ||
public | ||
pure | ||
returns (bool) | ||
{ | ||
AppState memory state = abi.decode(encodedState, (AppState)); | ||
return state.preimageRevealed; | ||
} | ||
|
||
function getTurnTaker(bytes memory /* encodedState */, address[] memory signingKeys) | ||
public | ||
pure | ||
returns (address) | ||
{ | ||
return signingKeys[0]; | ||
} | ||
|
||
function applyAction(bytes memory encodedState, bytes memory encodedAction) | ||
public | ||
pure | ||
returns (bytes memory) | ||
{ | ||
AppState memory state = abi.decode(encodedState, (AppState)); | ||
Action memory action = abi.decode(encodedAction, (Action)); | ||
|
||
require(!state.preimageRevealed, "No actions possible after preimage revealed"); | ||
|
||
AppState memory nextState = state; | ||
|
||
if (keccak256(action.preimage) == state.image) { | ||
nextState.preimageRevealed = true; | ||
} | ||
return abi.encode(nextState); | ||
} | ||
|
||
function resolve(bytes memory encodedState) | ||
public | ||
pure | ||
returns (bytes memory) | ||
{ | ||
AppState memory state = abi.decode(encodedState, (AppState)); | ||
|
||
if (state.preimageRevealed) { | ||
return abi.encode(1); | ||
} else { | ||
return abi.encode(0); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.