]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/feature/hubcoin_reward/class_HubcoinRewardFeature.php
Better name for the miner: It "mines" for Hubcoins.
[hub.git] / application / hub / main / feature / hubcoin_reward / class_HubcoinRewardFeature.php
index d1607ac8cd51ddf2cb3c50dfb889b038b4c5f5c0..f868dd949e65facc13426387311c14c00c26f384 100644 (file)
@@ -35,10 +35,9 @@ class HubcoinRewardFeature extends BaseFeature implements Feature {
        /**
         * Creates an instance of this Feature class and prepares it for usage
         *
-        * @param       $appInstance            A manageable application
         * @return      $featureInstance        An instance of this Feature class
         */
-       public final static function createHubcoinRewardFeature (ManageableApplication $appInstance) {
+       public final static function createHubcoinRewardFeature () {
                // Get a new instance
                $featureInstance = new HubcoinRewardFeature();
 
@@ -52,8 +51,14 @@ class HubcoinRewardFeature extends BaseFeature implements Feature {
         * @return      $isAvailable    Whether this feature is available
         */
        public function isFeatureAvailable () {
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
+
                // Testing this feature is pretty simple:
-               $isAvailable = (($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === 'Y') && (extension_loaded('scrypt')) && (is_callable('scrypt')));
+               $isAvailable = (($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === TRUE) && (extension_loaded('scrypt')) && (is_callable('scrypt')));
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: isAvailable=%d - EXIT!', __METHOD__, __LINE__, intval($isAvailable)));
 
                // Return status
                return $isAvailable;
@@ -62,7 +67,49 @@ class HubcoinRewardFeature extends BaseFeature implements Feature {
        /**
         * Feature method 'generateHash'
         *
-        * @param
+        * @param       $data   Data to hash
+        * @return      $hash   Finished hash
+        */
+       public function featureMethodGenerateHash ($data) {
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: data()=%d - CALLED!', __METHOD__, __LINE__, strlen($data)));
+
+               // Make sure the feature is available
+               assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
+
+               // Call inner class
+               $hash = Scrypt::hashScrypt($data);
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: hash=%s - EXIT!', __METHOD__, __LINE__, $hash));
+
+               // Return generated hash
+               return $hash;
+       }
+
+       /**
+        * Feature method 'checkHash'
+        *
+        * @param       $data           Data to check hash for
+        * @param       $hash           Previously generated hash for valdiation
+        * @return      $isValid        Whether the given hash matches a new one from given data
+        */
+       public function featureMethodCheckHash ($data, $hash) {
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
+
+               // Make sure the feature is available
+               assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
+
+               // Determine it
+               $isValid = Scrypt::checkScrypt($data, $hash);
+
+               // Debug message
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d]: isValid=%d - EXIT!', __METHOD__, __LINE__, intval($isValid)));
+
+               // Return status
+               return $isValid;
+       }
 }
 
 // [EOF]