Last active
May 22, 2019 15:10
-
-
Save tomclose/d475a050ca072fc78b28b247fb36a275 to your computer and use it in GitHub Desktop.
state-action style for force-move
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
pragma solidity ^0.5.2; | |
pragma experimental ABIEncoderV2; | |
import "fmg-core/contracts/Commitment.sol"; | |
library StateActionStyle { | |
using Commitment for Commitment.CommitmentStruct; | |
struct StateActionAttributes { | |
address stateActionLibrary; | |
bytes methodName; | |
bytes actionData; | |
bytes stateData; | |
} | |
function validTransition(Commitment memory state1, Commitment memory state2) external pure returns (bool) { | |
StateActionAttributes memory attrs1 = abi.decode(state1.appAttributes, (StateActionAttributes)); | |
StateActionAttributes memory attrs2 = abi.decode(state2.appAttributes, (StateActionAttributes)); | |
require(attrs1.stateActionLibrary == attrs2.stateActionLibrary, "App definition must not change"); | |
// call stateAction.methodName(stateData, actionData) => n | |
bytes calculatedStateData = static_call_magic(attrs2.stateActionLibrary, attrs2.methodName, attrs1.stateData, attrs2.actionData); | |
require(hash(calculatedStateData) == hash(attrs2.stateData), "Action must be correctly applied"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment