}
/**
- * Initializes the node's state which sets it to 'init'
+ * Initializes the communicator's state which sets it to 'init'
*
* @return void
*/
* class.
*
* @return void
- * @todo 0% done
+ * @todo ~10% done
*/
protected function initProducer () {
$this->partialStub('Please implement this method.');
*
* @param $stateInstance An instance of a Stateable instance
* @return void
- * @todo 0% done
+ * @todo ~5% done
*/
public function prepareBlockProduction (Stateable $stateInstance) {
- $this->partialStub('Please implement this method, stateInstance=' . $stateInstance->__toString());
+ // The state must be 'booting'
+ $stateInstance->validateMinerStateIsBooting();
+
+ /*
+ * Now that the miner is booting a genesis block for testing purposes
+ * can be created. The "real" genesis block will be created differently
+ * to this.
+ */
}
}
// Return the prepared instance
return $stateInstance;
}
+
+ /**
+ * Executes the state with given Executor instance
+ *
+ * @param $executorInstance An instance of a Executor class
+ * @return void
+ * @todo 0% done?
+ */
+ public function executeState (Executor $executorInstance) {
+ }
}
// [EOF]
* @return void
*/
public function executeState (Executor $executorInstance) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('MINER-STATE: Calling prepareBlockProduction() on ' . $executorInstance->__toString() . ' ...');
+
// Now prepare the unit production to maybe become 'virgin' or 'active' if work/test units are there
$executorInstance->prepareBlockProduction($this);
}
} // END - if
}
+ /**
+ * Validates whether the state is 'booting' or throws an exception if
+ * it is every other state.
+ *
+ * @return void
+ * @throws InvalidStateException If the state is not 'booting'
+ */
+ public function validateMinerStateIsBooting () {
+ // Just compare it...
+ if (!$this instanceof MinerBootingState) {
+ // Throw the exception
+ throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE);
+ } // END - if
+ }
+
/**
* Checks if this state is 'virgin'
*
// Get the communicator instance
$communicatorInstance = CommunicatorFactory::createCommunicatorInstance('miner_node_communicator_class', 'node');
- // Get the current miner state from registry
- $stateInstance = Registry::getRegistry()->getInstance('miner')->getStateInstance();
+ // Get the current miner state from it
+ $stateInstance = $communicatorInstance->getStateInstance();
// Debug message
/* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TASK[' . __METHOD__ . ':' . __LINE__ . ']: Executing stateInstance=' . $stateInstance->__toString());
// Debug message
/* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Enabling DHT bootstrap requests ...');
- // Just update our record
- $this->updateLocalNode();
+ // Is the node already registered?
+ if ($this->isLocalNodeRegistered()) {
+ // Just update our record
+ $this->updateLocalNode();
+ } else {
+ // Register it
+ $this->registerLocalNode();
+ }
}
}
-Subproject commit 1efa4dc3d8bd367e85e5cecf13778d06e0418415
+Subproject commit d4a8a783029f708b1d67b44557b5387017bdd63f