Commit acd3fa6f authored by Nicolas "Norswap" Laurent's avatar Nicolas "Norswap" Laurent Committed by norswap

move function

parent 483bca00
...@@ -69,30 +69,8 @@ contract Challenge { ...@@ -69,30 +69,8 @@ contract Challenge {
// create challenge // create challenge
uint256 public lastChallengeId = 0; uint256 public lastChallengeId = 0;
// Emitted when a new challenge is created.
event ChallengeCreate(uint256 challengeId); event ChallengeCreate(uint256 challengeId);
function newChallengeTrusted(uint256 blockNumberN, bytes32 startState, bytes32 finalSystemState, uint256 stepCount) internal returns (uint256) {
uint256 challengeId = lastChallengeId;
Chal storage c = challenges[challengeId];
lastChallengeId += 1;
// the challenger arrives
c.challenger = msg.sender;
// the state is set
c.blockNumberN = blockNumberN;
// NOTE: if they disagree on the start, 0->1 will fail
c.assertedState[0] = startState;
c.defendedState[0] = startState;
c.assertedState[stepCount] = finalSystemState;
// init the binary search
c.L = 0;
c.R = stepCount;
// find me later
emit ChallengeCreate(challengeId);
return challengeId;
}
// helper function to determine what nodes we need // helper function to determine what nodes we need
function CallWithTrieNodes(address target, bytes calldata dat, bytes[] calldata nodes) public { function CallWithTrieNodes(address target, bytes calldata dat, bytes[] calldata nodes) public {
...@@ -180,6 +158,34 @@ contract Challenge { ...@@ -180,6 +158,34 @@ contract Challenge {
return newChallengeTrusted(blockNumberN, startState, finalSystemState, stepCount); return newChallengeTrusted(blockNumberN, startState, finalSystemState, stepCount);
} }
function newChallengeTrusted(
uint256 blockNumberN, bytes32 startState, bytes32 finalSystemState, uint256 stepCount)
internal
returns (uint256)
{
uint256 challengeId = lastChallengeId;
Chal storage c = challenges[challengeId];
lastChallengeId += 1;
// the challenger arrives
c.challenger = msg.sender;
// the state is set
c.blockNumberN = blockNumberN;
// NOTE: if they disagree on the start, 0->1 will fail
c.assertedState[0] = startState;
c.defendedState[0] = startState;
c.assertedState[stepCount] = finalSystemState;
// init the binary search
c.L = 0;
c.R = stepCount;
// find me later
emit ChallengeCreate(challengeId);
return challengeId;
}
// binary search // binary search
function isSearching(uint256 challengeId) view public returns (bool) { function isSearching(uint256 challengeId) view public returns (bool) {
...@@ -252,7 +258,7 @@ contract Challenge { ...@@ -252,7 +258,7 @@ contract Challenge {
// pay out bounty!! // pay out bounty!!
(bool sent, ) = c.challenger.call{value: address(this).balance}(""); (bool sent, ) = c.challenger.call{value: address(this).balance}("");
require(sent, "Failed to send Ether"); require(sent, "Failed to send Ether");
emit ChallengerWins(challengeId); emit ChallengerWins(challengeId);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment