mirror of
https://github.com/kvazar-network/crawler-full-node.git
synced 2025-02-08 13:14:34 +00:00
init sqlite edition
This commit is contained in:
parent
c29e0d6b58
commit
2a8792e57b
@ -10,9 +10,7 @@ define('STEP_BLOCK_LIMIT', 50); // Blocks per query
|
|||||||
define('CRAWLER_DEBUG', true); // Debug output
|
define('CRAWLER_DEBUG', true); // Debug output
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
define('DB_HOST', '127.0.0.1');
|
define('DB_NAME', 'kvazar.dat');
|
||||||
define('DB_PORT', '3306');
|
|
||||||
define('DB_NAME', '');
|
|
||||||
define('DB_USERNAME', '');
|
define('DB_USERNAME', '');
|
||||||
define('DB_PASSWORD', '');
|
define('DB_PASSWORD', '');
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ $semaphore = sem_get(1);
|
|||||||
if (false !== sem_acquire($semaphore, 1)) {
|
if (false !== sem_acquire($semaphore, 1)) {
|
||||||
|
|
||||||
require_once('config.php');
|
require_once('config.php');
|
||||||
require_once('library/mysql.php');
|
require_once('library/sqlite.php');
|
||||||
require_once('library/kevacoin.php');
|
require_once('library/kevacoin.php');
|
||||||
require_once('library/hash.php');
|
require_once('library/hash.php');
|
||||||
require_once('library/base58.php');
|
require_once('library/base58.php');
|
||||||
@ -13,7 +13,7 @@ if (false !== sem_acquire($semaphore, 1)) {
|
|||||||
require_once('library/crypto.php');
|
require_once('library/crypto.php');
|
||||||
require_once('library/helper.php');
|
require_once('library/helper.php');
|
||||||
|
|
||||||
$db = new MySQL(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
|
$db = new SQLite(DB_NAME, DB_USERNAME, DB_PASSWORD);
|
||||||
$kevaCoin = new KevaCoin(KEVA_PROTOCOL, KEVA_HOST, KEVA_PORT, KEVA_USERNAME, KEVA_PASSWORD);
|
$kevaCoin = new KevaCoin(KEVA_PROTOCOL, KEVA_HOST, KEVA_PORT, KEVA_USERNAME, KEVA_PASSWORD);
|
||||||
|
|
||||||
$blockLast = $db->getLastBlock();
|
$blockLast = $db->getLastBlock();
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class MySQL {
|
class SQLite {
|
||||||
|
|
||||||
public function __construct($host, $port, $database, $username, $password) {
|
public function __construct($database, $username, $password) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$this->_db = new PDO('mysql:dbname=' . $database . ';host=' . $host . ';port=' . $port . ';charset=utf8', $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
|
$this->_db = new PDO('sqlite:' . $database, $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
|
||||||
$this->_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
$this->_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||||
$this->_db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
$this->_db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||||
$this->_db->setAttribute(PDO::ATTR_TIMEOUT, 600);
|
$this->_db->setAttribute(PDO::ATTR_TIMEOUT, 600);
|
||||||
@ -38,7 +38,9 @@ class MySQL {
|
|||||||
|
|
||||||
$query->execute([$blockId]);
|
$query->execute([$blockId]);
|
||||||
|
|
||||||
return $query->rowCount() ? $query->fetch()['blockId'] : false;
|
$result = $query->fetch();
|
||||||
|
|
||||||
|
return $result ? $result['blockId'] : false;
|
||||||
|
|
||||||
} catch(PDOException $e) {
|
} catch(PDOException $e) {
|
||||||
trigger_error($e->getMessage());
|
trigger_error($e->getMessage());
|
||||||
@ -54,7 +56,9 @@ class MySQL {
|
|||||||
|
|
||||||
$query->execute([$hash]);
|
$query->execute([$hash]);
|
||||||
|
|
||||||
return $query->rowCount() ? $query->fetch()['nameSpaceId'] : false;
|
$result = $query->fetch();
|
||||||
|
|
||||||
|
return $result ? $result['nameSpaceId'] : false;
|
||||||
|
|
||||||
} catch(PDOException $e) {
|
} catch(PDOException $e) {
|
||||||
trigger_error($e->getMessage());
|
trigger_error($e->getMessage());
|
||||||
@ -70,7 +74,9 @@ class MySQL {
|
|||||||
|
|
||||||
$query->execute([$txId]);
|
$query->execute([$txId]);
|
||||||
|
|
||||||
return $query->rowCount() ? $query->fetch()['dataId'] : false;
|
$result = $query->fetch();
|
||||||
|
|
||||||
|
return $result ? $result['dataId'] : false;
|
||||||
|
|
||||||
} catch(PDOException $e) {
|
} catch(PDOException $e) {
|
||||||
trigger_error($e->getMessage());
|
trigger_error($e->getMessage());
|
||||||
@ -82,11 +88,10 @@ class MySQL {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$query = $this->_db->prepare('INSERT INTO `block` SET `blockId` = ?,
|
$query = $this->_db->prepare('INSERT INTO `block` (`blockId`, `lostTransactions`, `timeIndexed`)
|
||||||
`lostTransactions` = 0,
|
VALUES (?, 0, ?)');
|
||||||
`timeIndexed` = UNIX_TIMESTAMP()');
|
|
||||||
|
|
||||||
$query->execute([$blockId]);
|
$query->execute([$blockId, time()]);
|
||||||
|
|
||||||
return $blockId;
|
return $blockId;
|
||||||
|
|
||||||
@ -116,10 +121,10 @@ class MySQL {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$query = $this->_db->prepare('INSERT INTO `namespace` SET `hash` = ?,
|
$query = $this->_db->prepare('INSERT INTO `namespace` (`hash`, `timeIndexed`)
|
||||||
`timeIndexed` = UNIX_TIMESTAMP()');
|
VALUES (?, ?)');
|
||||||
|
|
||||||
$query->execute([$hash]);
|
$query->execute([$hash, time()]);
|
||||||
|
|
||||||
return $this->_db->lastInsertId();
|
return $this->_db->lastInsertId();
|
||||||
|
|
||||||
@ -133,16 +138,35 @@ class MySQL {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$query = $this->_db->prepare('INSERT INTO `data` SET `blockId` = :blockId,
|
$query = $this->_db->prepare('INSERT INTO `data` (
|
||||||
`nameSpaceId` = :nameSpaceId,
|
|
||||||
`time` = :time,
|
`blockId`,
|
||||||
`size` = :size,
|
`nameSpaceId`,
|
||||||
`txid` = :txid,
|
`time`,
|
||||||
`key` = :key,
|
`size`,
|
||||||
`value` = :value,
|
`txid`,
|
||||||
`deleted` = :deleted,
|
`key`,
|
||||||
`ns` = :ns,
|
`value`,
|
||||||
`timeIndexed` = UNIX_TIMESTAMP()');
|
`deleted`,
|
||||||
|
`ns`,
|
||||||
|
`timeIndexed`
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
VALUES (
|
||||||
|
|
||||||
|
:blockId,
|
||||||
|
:nameSpaceId,
|
||||||
|
:time,
|
||||||
|
:size,
|
||||||
|
:txid,
|
||||||
|
:key,
|
||||||
|
:value,
|
||||||
|
:deleted,
|
||||||
|
:ns,
|
||||||
|
:timeIndexed
|
||||||
|
|
||||||
|
)');
|
||||||
|
|
||||||
$query->bindValue(':blockId', $blockId, PDO::PARAM_INT);
|
$query->bindValue(':blockId', $blockId, PDO::PARAM_INT);
|
||||||
$query->bindValue(':nameSpaceId', $nameSpaceId, PDO::PARAM_INT);
|
$query->bindValue(':nameSpaceId', $nameSpaceId, PDO::PARAM_INT);
|
||||||
@ -153,6 +177,7 @@ class MySQL {
|
|||||||
$query->bindValue(':value', $value, PDO::PARAM_STR);
|
$query->bindValue(':value', $value, PDO::PARAM_STR);
|
||||||
$query->bindValue(':deleted', (int) $deleted, PDO::PARAM_STR);
|
$query->bindValue(':deleted', (int) $deleted, PDO::PARAM_STR);
|
||||||
$query->bindValue(':ns', (int) $ns, PDO::PARAM_STR);
|
$query->bindValue(':ns', (int) $ns, PDO::PARAM_STR);
|
||||||
|
$query->bindValue(':timeIndexed', time(), PDO::PARAM_INT);
|
||||||
|
|
||||||
$query->execute();
|
$query->execute();
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user