Skip to content

Instantly share code, notes, and snippets.

@tomclose
Last active May 22, 2019 15:10
Show Gist options
  • Save tomclose/d475a050ca072fc78b28b247fb36a275 to your computer and use it in GitHub Desktop.
Save tomclose/d475a050ca072fc78b28b247fb36a275 to your computer and use it in GitHub Desktop.
state-action style for force-move
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