get_next_address_index($mpk); $address = AGC_Electrum::create_electrum_address($cryptoId, $mpk, $startIndex); try { while (AGC_Blockchain::is_dirty_address($cryptoId, $address)) { $repo->insert_address_into_db($address, $startIndex, 'dirty'); $startIndex = $startIndex + 1; $address = AGC_Electrum::create_electrum_address($cryptoId, $mpk, $startIndex); set_time_limit(30); } } catch ( \Exception $e ) { AGC_Util::log(__FILE__, __LINE__, 'Could not create new addresses: ' . $e->getMessage()); throw new \Exception($e); } $repo->insert_address_into_db($address, $startIndex, 'ready'); } public static function log($fileName, $lineNumber, $message) { $logFileName = dirname(__DIR__) . '/agc.log'; if (file_exists($logFileName)) { $file = fopen($logFileName, 'r+'); if ($file) { fseek($file, 0, SEEK_END); } } else { $file = fopen($logFileName, 'w'); } if ($file) { fwrite($file, "\r\n" . date("m-d-Y, G:i:s T") . "$fileName - $lineNumber: " . $message); fclose($file); } } public static function serialize_buffer($buffer) { return self::safe_string_escape(serialize($buffer)); } // credit: http://www.php.net/manual/en/function.mysql-real-escape-string.php#100854 private static function safe_string_escape ($str) { $len=strlen($str); $escapeCount=0; $targetString=''; for ($offset=0; $offset<$len; $offset++) { switch($c=$str{$offset}) { case "'": // Escapes this quote only if its not preceded by an unescaped backslash if($escapeCount % 2 == 0) $targetString.="\\"; $escapeCount=0; $targetString.=$c; break; case '"': // Escapes this quote only if its not preceded by an unescaped backslash if($escapeCount % 2 == 0) $targetString.="\\"; $escapeCount=0; $targetString.=$c; break; case '\\': $escapeCount++; $targetString.=$c; break; default: $escapeCount=0; $targetString.=$c; } } return $targetString; } } ?>