Changed exchange rate refresh interval to 15 minutes
This commit is contained in:
parent
361a5ff2db
commit
3d5cfac462
3 changed files with 89 additions and 67 deletions
|
@ -1,4 +1,4 @@
|
||||||
--DROP DATABASE IF EXISTS lbry;
|
l--DROP DATABASE IF EXISTS lbry;
|
||||||
CREATE DATABASE lbry DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;
|
CREATE DATABASE lbry DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
USE lbry;
|
USE lbry;
|
||||||
|
|
||||||
|
@ -7,22 +7,22 @@ CREATE TABLE `Blocks`
|
||||||
`Id` SERIAL,
|
`Id` SERIAL,
|
||||||
|
|
||||||
`Bits` VARCHAR(20) NOT NULL,
|
`Bits` VARCHAR(20) NOT NULL,
|
||||||
`Chainwork` VARCHAR(70) NOT NULL,
|
`Chainwork` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||||
`Confirmations` INTEGER UNSIGNED NOT NULL,
|
`Confirmations` INTEGER UNSIGNED NOT NULL,
|
||||||
`Difficulty` DECIMAL(18,8) NOT NULL,
|
`Difficulty` DECIMAL(18,8) NOT NULL,
|
||||||
`Hash` VARCHAR(70) NOT NULL,
|
`Hash` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL ,
|
||||||
`Height` BIGINT UNSIGNED NOT NULL,
|
`Height` BIGINT UNSIGNED NOT NULL,
|
||||||
`MedianTime` BIGINT UNSIGNED NOT NULL,
|
`MedianTime` BIGINT UNSIGNED NOT NULL,
|
||||||
`MerkleRoot` VARCHAR(70) NOT NULL,
|
`MerkleRoot` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||||
`NameClaimRoot` VARCHAR(70) NOT NULL,
|
`NameClaimRoot` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||||
`Nonce` BIGINT UNSIGNED NOT NULL,
|
`Nonce` BIGINT UNSIGNED NOT NULL,
|
||||||
`PreviousBlockHash` VARCHAR(70),
|
`PreviousBlockHash` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`NextBlockHash` VARCHAR(70),
|
`NextBlockHash` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`BlockSize` BIGINT UNSIGNED NOT NULL,
|
`BlockSize` BIGINT UNSIGNED NOT NULL,
|
||||||
`Target` VARCHAR(70) NOT NULL,
|
`Target` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||||
`BlockTime` BIGINT UNSIGNED NOT NULL,
|
`BlockTime` BIGINT UNSIGNED NOT NULL,
|
||||||
`Version` BIGINT UNSIGNED NOT NULL,
|
`Version` BIGINT UNSIGNED NOT NULL,
|
||||||
`VersionHex` VARCHAR(10) NOT NULL,
|
`VersionHex` VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||||
`TransactionHashes` TEXT,
|
`TransactionHashes` TEXT,
|
||||||
`TransactionsProcessed` TINYINT(1) DEFAULT 0 NOT NULL,
|
`TransactionsProcessed` TINYINT(1) DEFAULT 0 NOT NULL,
|
||||||
|
|
||||||
|
@ -43,14 +43,14 @@ CREATE TABLE `Blocks`
|
||||||
CREATE TABLE `Transactions`
|
CREATE TABLE `Transactions`
|
||||||
(
|
(
|
||||||
`Id` SERIAL,
|
`Id` SERIAL,
|
||||||
`BlockHash` VARCHAR(70),
|
`BlockHash` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`InputCount` INTEGER UNSIGNED NOT NULL,
|
`InputCount` INTEGER UNSIGNED NOT NULL,
|
||||||
`OutputCount` INTEGER UNSIGNED NOT NULL,
|
`OutputCount` INTEGER UNSIGNED NOT NULL,
|
||||||
`Value` DECIMAL(18,8) NOT NULL,
|
`Value` DECIMAL(18,8) NOT NULL,
|
||||||
`Fee` DECIMAL(18,8) DEFAULT 0 NOT NULL,
|
`Fee` DECIMAL(18,8) DEFAULT 0 NOT NULL,
|
||||||
`TransactionTime` BIGINT UNSIGNED,
|
`TransactionTime` BIGINT UNSIGNED,
|
||||||
`TransactionSize` BIGINT UNSIGNED NOT NULL,
|
`TransactionSize` BIGINT UNSIGNED NOT NULL,
|
||||||
`Hash` VARCHAR(70) NOT NULL,
|
`Hash` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||||
`Version` INTEGER NOT NULL,
|
`Version` INTEGER NOT NULL,
|
||||||
`LockTime` INTEGER UNSIGNED NOT NULL,
|
`LockTime` INTEGER UNSIGNED NOT NULL,
|
||||||
`Raw` TEXT,
|
`Raw` TEXT,
|
||||||
|
@ -69,7 +69,7 @@ CREATE TABLE `Transactions`
|
||||||
CREATE TABLE `Addresses`
|
CREATE TABLE `Addresses`
|
||||||
(
|
(
|
||||||
`Id` SERIAL,
|
`Id` SERIAL,
|
||||||
`Address` VARCHAR(40) NOT NULL,
|
`Address` VARCHAR(40) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||||
`FirstSeen` DATETIME,
|
`FirstSeen` DATETIME,
|
||||||
`TotalReceived` DECIMAL(18,8) DEFAULT 0 NOT NULL,
|
`TotalReceived` DECIMAL(18,8) DEFAULT 0 NOT NULL,
|
||||||
`TotalSent` DECIMAL(18,8) DEFAULT 0 NOT NULL,
|
`TotalSent` DECIMAL(18,8) DEFAULT 0 NOT NULL,
|
||||||
|
@ -90,17 +90,17 @@ CREATE TABLE `Inputs`
|
||||||
(
|
(
|
||||||
`Id` SERIAL,
|
`Id` SERIAL,
|
||||||
`TransactionId` BIGINT UNSIGNED NOT NULL,
|
`TransactionId` BIGINT UNSIGNED NOT NULL,
|
||||||
`TransactionHash` VARCHAR(70) NOT NULL,
|
`TransactionHash` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||||
`AddressId` BIGINT UNSIGNED,
|
`AddressId` BIGINT UNSIGNED,
|
||||||
`IsCoinbase` TINYINT(1) DEFAULT 0 NOT NULL,
|
`IsCoinbase` TINYINT(1) DEFAULT 0 NOT NULL,
|
||||||
`Coinbase` VARCHAR(70),
|
`Coinbase` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`PrevoutHash` VARCHAR(70),
|
`PrevoutHash` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`PrevoutN` INTEGER UNSIGNED,
|
`PrevoutN` INTEGER UNSIGNED,
|
||||||
`PrevoutSpendUpdated` TINYINT(1) DEFAULT 0 NOT NULL,
|
`PrevoutSpendUpdated` TINYINT(1) DEFAULT 0 NOT NULL,
|
||||||
`Sequence` INTEGER UNSIGNED,
|
`Sequence` INTEGER UNSIGNED,
|
||||||
`Value` DECIMAL(18,8),
|
`Value` DECIMAL(18,8),
|
||||||
`ScriptSigAsm` TEXT,
|
`ScriptSigAsm` TEXT CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`ScriptSigHex` TEXT,
|
`ScriptSigHex` TEXT CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`Created` DATETIME NOT NULL,
|
`Created` DATETIME NOT NULL,
|
||||||
`Modified` DATETIME NOT NULL,
|
`Modified` DATETIME NOT NULL,
|
||||||
PRIMARY KEY `PK_Input` (`Id`),
|
PRIMARY KEY `PK_Input` (`Id`),
|
||||||
|
@ -127,12 +127,12 @@ CREATE TABLE `Outputs`
|
||||||
`TransactionId` BIGINT UNSIGNED NOT NULL,
|
`TransactionId` BIGINT UNSIGNED NOT NULL,
|
||||||
`Value` DECIMAL(18,8),
|
`Value` DECIMAL(18,8),
|
||||||
`Vout` INTEGER UNSIGNED,
|
`Vout` INTEGER UNSIGNED,
|
||||||
`Type` VARCHAR(20),
|
`Type` VARCHAR(20) CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`ScriptPubKeyAsm` TEXT,
|
`ScriptPubKeyAsm` TEXT CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`ScriptPubKeyHex` TEXT,
|
`ScriptPubKeyHex` TEXT CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`RequiredSignatures` INTEGER UNSIGNED,
|
`RequiredSignatures` INTEGER UNSIGNED,
|
||||||
`Hash160` VARCHAR(50),
|
`Hash160` VARCHAR(50) CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`Addresses` TEXT,
|
`Addresses` TEXT CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
`IsSpent` TINYINT(1) DEFAULT 0 NOT NULL,
|
`IsSpent` TINYINT(1) DEFAULT 0 NOT NULL,
|
||||||
`SpentByInputId` BIGINT UNSIGNED,
|
`SpentByInputId` BIGINT UNSIGNED,
|
||||||
`Created` DATETIME NOT NULL,
|
`Created` DATETIME NOT NULL,
|
||||||
|
@ -170,17 +170,28 @@ CREATE TABLE `TransactionsAddresses`
|
||||||
INDEX `Idx_TransactionsAddressesCredit` (`CreditAmount`)
|
INDEX `Idx_TransactionsAddressesCredit` (`CreditAmount`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
|
||||||
|
|
||||||
ALTER TABLE TransactionsAddresses ADD COLUMN TransactionTime DATETIME DEFAULT UTC_TIMESTAMP() NOT NULL AFTER CreditAmount;
|
CREATE TABLE `Claims`
|
||||||
ALTER TABLE TransactionsAddresses ADD INDEX `Idx_TransactionsAddressesTransactionTime` (`TransactionTime`);
|
(
|
||||||
|
`Id` SERIAL,
|
||||||
ALTER TABLE Addresses ADD COLUMN TotalReceived DECIMAL(18,8) DEFAULT 0 NOT NULL AFTER FirstSeen;
|
`TransactionHash` VARCHAR(70) CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
ALTER TABLE Addresses ADD COLUMN TotalSent DECIMAL(18,8) DEFAULT 0 NOT NULL AFTER TotalReceived;
|
`Name` VARCHAR(200) NOT NULL,
|
||||||
ALTER TABLE Addresses ADD INDEX Idx_AddressTotalReceived (TotalReceived);
|
`ClaimId` CHAR(40) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||||
ALTER TABLE Addresses ADD INDEX Idx_AddressTotalSent (TotalSent);
|
`ClaimType` TINYINT(1) NOT NULL, -- 1 - CertificateType, 2 - StreamType
|
||||||
|
`PublisherId` CHAR(40) CHARACTER SET latin1 COLLATE latin1_general_ci COMMENT 'references a ClaimId with CertificateType',
|
||||||
ALTER TABLE Addresses ADD COLUMN `Tag` VARCHAR(30) AFTER TotalSent;
|
`PublisherSig` VARCHAR(200) CHARACTER SET latin1 COLLATE latin1_general_ci,
|
||||||
ALTER TABLE Addresses ADD COLUMN `TagUrl` VARCHAR(200) AFTER Tag;
|
`Certificate` TEXT,
|
||||||
ALTER TABLE Addresses ADD UNIQUE KEY `Idx_AddressTag` (`Tag`);
|
`Stream` TEXT,
|
||||||
|
`TransactionTime` INTEGER UNSIGNED,
|
||||||
|
`Version` VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
|
||||||
ALTER TABLE Transactions ADD INDEX `Idx_TransactionSize` (`TransactionSize`);
|
`Created` DATETIME NOT NULL,
|
||||||
|
`Modified` DATETIME NOT NULL,
|
||||||
|
PRIMARY KEY `PK_Claim` (`Id`),
|
||||||
|
FOREIGN KEY `FK_ClaimTransaction` (`TransactionHash`) REFERENCES `Transactions` (`Hash`),
|
||||||
|
FOREIGN KEY `FK_ClaimPublisher` (`PublisherId`) REFERENCES `Claims` (`ClaimId`),
|
||||||
|
CHECK((`ClaimType` = 1 AND JSON_VALID(`Certificate`)) -- certificate type
|
||||||
|
OR (`ClaimType` = 2 AND JSON_VALID(`Stream`))), -- stream type
|
||||||
|
INDEX `Idx_Claim` (`ClaimId`),
|
||||||
|
INDEX `Idx_ClaimTransactionTime` (`TransactionTime`),
|
||||||
|
INDEX `Idx_ClaimCreated` (`Created`),
|
||||||
|
INDEX `Idx_ClaimModified` (`Modified`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=4;
|
|
@ -29,8 +29,12 @@ class MainController extends AppController {
|
||||||
|
|
||||||
public function initialize() {
|
public function initialize() {
|
||||||
parent::initialize();
|
parent::initialize();
|
||||||
|
|
||||||
$this->redis = new \Predis\Client('tcp://127.0.0.1:6379');
|
$this->redis = new \Predis\Client('tcp://127.0.0.1:6379');
|
||||||
|
try {
|
||||||
|
$this->redis->info('mem');
|
||||||
|
} catch (\Predis\Connection\ConnectionException $e) {
|
||||||
|
$this->redis = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function _getLatestPrice() {
|
protected function _getLatestPrice() {
|
||||||
|
@ -39,16 +43,26 @@ class MainController extends AppController {
|
||||||
$priceInfo->time = $now->format('c');
|
$priceInfo->time = $now->format('c');
|
||||||
|
|
||||||
$shouldRefreshPrice = false;
|
$shouldRefreshPrice = false;
|
||||||
if (!$this->redis->exists(self::lbcPriceKey)) {
|
if (!$this->redis) {
|
||||||
$shouldRefreshPrice = true;
|
$shouldRefreshPrice = true;
|
||||||
} else {
|
} else {
|
||||||
$priceInfo = json_decode($this->redis->get(self::lbcPriceKey));
|
if (!$this->redis->exists(self::lbcPriceKey)) {
|
||||||
$lastPriceDt = new \DateTime($priceInfo->time);
|
|
||||||
$diff = $now->diff($lastPriceDt);
|
|
||||||
$diffHours = $diff->h;
|
|
||||||
$diffHours = $diffHours + ($diff->days * 24);
|
|
||||||
if ($diffHours >= 3) {
|
|
||||||
$shouldRefreshPrice = true;
|
$shouldRefreshPrice = true;
|
||||||
|
} else {
|
||||||
|
$priceInfo = json_decode($this->redis->get(self::lbcPriceKey));
|
||||||
|
$lastPriceDt = new \DateTime($priceInfo->time);
|
||||||
|
$diff = $now->diff($lastPriceDt);
|
||||||
|
$diffMinutes = $diff->i;
|
||||||
|
if ($diffMinutes >= 15) { // 15 minutes
|
||||||
|
$shouldRefreshPrice = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
$diffHours = $diff->h;
|
||||||
|
$diffHours = $diffHours + ($diff->days * 24);
|
||||||
|
if ($diffHours >= 3) {
|
||||||
|
$shouldRefreshPrice = true;
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,13 +71,15 @@ class MainController extends AppController {
|
||||||
$blckjson = json_decode(self::curl_get(self::blockchainTickerUrl));
|
$blckjson = json_decode(self::curl_get(self::blockchainTickerUrl));
|
||||||
|
|
||||||
if ($btrxjson->success) {
|
if ($btrxjson->success) {
|
||||||
$onelbc = $btrxjson->result->Ask;
|
$onelbc = $btrxjson->result->Bid;
|
||||||
$lbcPrice = 0;
|
$lbcPrice = 0;
|
||||||
if (isset($blckjson->USD)) {
|
if (isset($blckjson->USD)) {
|
||||||
$lbcPrice = $onelbc * $blckjson->USD->buy;
|
$lbcPrice = $onelbc * $blckjson->USD->buy;
|
||||||
$priceInfo->price = number_format($lbcPrice, 2, '.', '');
|
$priceInfo->price = number_format($lbcPrice, 2, '.', '');
|
||||||
$priceInfo->time = $now->format('c');
|
$priceInfo->time = $now->format('c');
|
||||||
$this->redis->set(self::lbcPriceKey, json_encode($priceInfo));
|
if ($this->redis) {
|
||||||
|
$this->redis->set(self::lbcPriceKey, json_encode($priceInfo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ class BlockShell extends Shell {
|
||||||
public function fixzerooutputs() {
|
public function fixzerooutputs() {
|
||||||
self::lock('zerooutputs');
|
self::lock('zerooutputs');
|
||||||
|
|
||||||
$redis = new \Predis\Client(self::redisurl);
|
$redis = self::_init_redis();
|
||||||
$conn = ConnectionManager::get('default');
|
$conn = ConnectionManager::get('default');
|
||||||
|
|
||||||
/** 2017-06-12 21:38:07 **/
|
/** 2017-06-12 21:38:07 **/
|
||||||
|
@ -520,13 +520,7 @@ class BlockShell extends Shell {
|
||||||
//$conn->execute('SET foreign_key_checks = 0');
|
//$conn->execute('SET foreign_key_checks = 0');
|
||||||
//$conn->execute('SET unique_checks = 0');
|
//$conn->execute('SET unique_checks = 0');
|
||||||
|
|
||||||
$redis = null;
|
$redis = self::_init_redis();
|
||||||
try {
|
|
||||||
$redis = new \Predis\Client(self::redisurl);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
// redis unavailable
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$unproc_blocks = $this->Blocks->find()->select(['Id', 'Height', 'Hash', 'TransactionHashes', 'BlockTime'])->where(['TransactionsProcessed' => 0])->order(['Height' => 'asc'])->toArray();
|
$unproc_blocks = $this->Blocks->find()->select(['Id', 'Height', 'Hash', 'TransactionHashes', 'BlockTime'])->where(['TransactionsProcessed' => 0])->order(['Height' => 'asc'])->toArray();
|
||||||
foreach ($unproc_blocks as $min_block) {
|
foreach ($unproc_blocks as $min_block) {
|
||||||
|
@ -630,14 +624,8 @@ class BlockShell extends Shell {
|
||||||
self::lock('parsenewblocks');
|
self::lock('parsenewblocks');
|
||||||
|
|
||||||
echo "Parsing new blocks...\n";
|
echo "Parsing new blocks...\n";
|
||||||
$redis = null;
|
$redis = self::_init_redis();
|
||||||
try {
|
try {
|
||||||
try {
|
|
||||||
$redis = new \Predis\Client();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
// redis not available
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the best block hash
|
// Get the best block hash
|
||||||
$req = ['method' => 'getbestblockhash', 'params' => []];
|
$req = ['method' => 'getbestblockhash', 'params' => []];
|
||||||
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
$response = self::curl_json_post(self::rpcurl, json_encode($req));
|
||||||
|
@ -803,12 +791,7 @@ class BlockShell extends Shell {
|
||||||
self::lock('forevermempool');
|
self::lock('forevermempool');
|
||||||
|
|
||||||
$conn = ConnectionManager::get('default');
|
$conn = ConnectionManager::get('default');
|
||||||
$redis = null;
|
$redis = self::_init_redis();
|
||||||
try {
|
|
||||||
$redis = new \Predis\Client(self::redisurl);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
// redis not available
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
|
@ -1608,6 +1591,18 @@ class BlockShell extends Shell {
|
||||||
return implode('', array_reverse(str_split($bytes, 2)));
|
return implode('', array_reverse(str_split($bytes, 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function _init_redis() {
|
||||||
|
$redis = new \Predis\Client(self::redisurl);
|
||||||
|
try {
|
||||||
|
$redis->info('mem');
|
||||||
|
} catch (\Predis\Connection\ConnectionException $e) {
|
||||||
|
// redis not available
|
||||||
|
$redis = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $redis;
|
||||||
|
}
|
||||||
|
|
||||||
/*public function parsehistoryblocks() {
|
/*public function parsehistoryblocks() {
|
||||||
set_time_limit(0);
|
set_time_limit(0);
|
||||||
header('Content-type: text/plain');
|
header('Content-type: text/plain');
|
||||||
|
|
Loading…
Reference in a new issue