Permalink
Browse files

add liskstats contribution

add liskstats contribution
  • Loading branch information...
karek314 committed May 8, 2017
1 parent fb0471d commit e962dcb43adcf11cbdd3e8896f3448b795a913d0
Showing with 710 additions and 58 deletions.
  1. +177 −57 lisk_pool_scheme_db.sql
  2. +34 −0 private/liskstats.php
  3. +25 −1 private/processing.php
  4. +290 −0 private/wss/Base.php
  5. +184 −0 private/wss/Client.php
View
@@ -1,11 +1,11 @@
-- phpMyAdmin SQL Dump
-- version 4.0.10deb1
-- version 4.5.4.1deb2ubuntu2
-- http://www.phpmyadmin.net
--
-- Host: localhost:3306
-- Generation Time: May 27, 2016 at 06:54 AM
-- Server version: 5.5.49-MariaDB-1ubuntu0.14.04.1
-- PHP Version: 5.5.9-1ubuntu4.16
-- Host: localhost
-- Generation Time: May 08, 2017 at 07:23 PM
-- Server version: 10.0.29-MariaDB-0ubuntu0.16.04.1
-- PHP Version: 7.0.15-0ubuntu0.16.04.4
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
@@ -14,10 +14,10 @@ SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `lisk_pool_scheme_db`
-- Database: `lisk_template`
--
-- --------------------------------------------------------
@@ -26,127 +26,247 @@ SET time_zone = "+00:00";
-- Table structure for table `blocks`
--
CREATE TABLE IF NOT EXISTS `blocks` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`blockid` int(19) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE `blocks` (
`id` int(11) NOT NULL,
`blockid` int(19) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `liskstats`
--
CREATE TABLE `liskstats` (
`id` int(11) NOT NULL,
`object` varchar(64) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `miners`
--
CREATE TABLE IF NOT EXISTS `miners` (
`id` int(11) NOT NULL AUTO_INCREMENT,
CREATE TABLE `miners` (
`id` int(11) NOT NULL,
`address` varchar(64) NOT NULL,
`balance` bigint(19) NOT NULL,
PRIMARY KEY (`id`),
KEY `address` (`address`),
KEY `balance` (`balance`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
`balance` bigint(19) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `miner_balance`
--
CREATE TABLE IF NOT EXISTS `miner_balance` (
`id` int(11) NOT NULL AUTO_INCREMENT,
CREATE TABLE `miner_balance` (
`id` int(11) NOT NULL,
`miner` varchar(64) NOT NULL,
`value` varchar(64) NOT NULL,
`var_timestamp` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
`var_timestamp` varchar(64) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `payout_history`
--
CREATE TABLE IF NOT EXISTS `payout_history` (
`id` int(11) NOT NULL AUTO_INCREMENT,
CREATE TABLE `payout_history` (
`id` int(11) NOT NULL,
`address` varchar(64) NOT NULL,
`balance` varchar(64) NOT NULL,
`time` varchar(32) NOT NULL,
`txid` varchar(128) NOT NULL,
`fee` varchar(64) NOT NULL,
PRIMARY KEY (`id`),
KEY `address` (`address`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
`fee` varchar(64) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `pool_balance`
--
CREATE TABLE IF NOT EXISTS `pool_balance` (
`id` int(11) NOT NULL AUTO_INCREMENT,
CREATE TABLE `pool_balance` (
`id` int(11) NOT NULL,
`value` varchar(64) NOT NULL,
`var_timestamp` varchar(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
`var_timestamp` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `pool_rank`
--
CREATE TABLE IF NOT EXISTS `pool_rank` (
`id` int(11) NOT NULL AUTO_INCREMENT,
CREATE TABLE `pool_rank` (
`id` int(11) NOT NULL,
`value` varchar(64) NOT NULL,
`var_timestamp` varchar(32) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
`var_timestamp` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `pool_votepower`
--
CREATE TABLE IF NOT EXISTS `pool_votepower` (
`id` int(11) NOT NULL AUTO_INCREMENT,
CREATE TABLE `pool_votepower` (
`id` int(11) NOT NULL,
`votepower` varchar(64) NOT NULL,
`val_timestamp` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
`val_timestamp` varchar(64) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `pool_voters`
--
CREATE TABLE IF NOT EXISTS `pool_voters` (
`id` int(11) NOT NULL AUTO_INCREMENT,
CREATE TABLE `pool_voters` (
`id` int(11) NOT NULL,
`value` varchar(64) NOT NULL,
`var_timestamp` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
`var_timestamp` varchar(64) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `stats`
--
CREATE TABLE IF NOT EXISTS `stats` (
`id` bigint(11) NOT NULL AUTO_INCREMENT,
CREATE TABLE `stats` (
`id` bigint(11) NOT NULL,
`user` varchar(64) NOT NULL,
`userid` varchar(16) NOT NULL,
`hashrate` varchar(64) NOT NULL,
`val_timestamp` varchar(32) NOT NULL,
PRIMARY KEY (`id`),
KEY `user` (`user`),
KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
`val_timestamp` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `blocks`
--
ALTER TABLE `blocks`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `liskstats`
--
ALTER TABLE `liskstats`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `miners`
--
ALTER TABLE `miners`
ADD PRIMARY KEY (`id`),
ADD KEY `address` (`address`),
ADD KEY `balance` (`balance`);
--
-- Indexes for table `miner_balance`
--
ALTER TABLE `miner_balance`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `payout_history`
--
ALTER TABLE `payout_history`
ADD PRIMARY KEY (`id`),
ADD KEY `address` (`address`);
--
-- Indexes for table `pool_balance`
--
ALTER TABLE `pool_balance`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `pool_rank`
--
ALTER TABLE `pool_rank`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `pool_votepower`
--
ALTER TABLE `pool_votepower`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `pool_voters`
--
ALTER TABLE `pool_voters`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `stats`
--
ALTER TABLE `stats`
ADD PRIMARY KEY (`id`),
ADD KEY `user` (`user`),
ADD KEY `id` (`id`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `blocks`
--
ALTER TABLE `blocks`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `liskstats`
--
ALTER TABLE `liskstats`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `miners`
--
ALTER TABLE `miners`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `miner_balance`
--
ALTER TABLE `miner_balance`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `payout_history`
--
ALTER TABLE `payout_history`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `pool_balance`
--
ALTER TABLE `pool_balance`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `pool_rank`
--
ALTER TABLE `pool_rank`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `pool_votepower`
--
ALTER TABLE `pool_votepower`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `pool_voters`
--
ALTER TABLE `pool_voters`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `stats`
--
ALTER TABLE `stats`
MODIFY `id` bigint(11) NOT NULL AUTO_INCREMENT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
View
@@ -0,0 +1,34 @@
<?php
error_reporting(error_reporting() & ~E_NOTICE);
$config = include('../config.php');
require('wss/Client.php');
use WebSocket\Client;
$timestamp_ms = time()*1000;
$client = new Client("ws://liskstats.net:3000/primus/?_primuscb=".$timestamp_ms."-0");
$client->send('{"emit":["ready"]}');
$mysqli=mysqli_connect($config['host'], $config['username'], $config['password'], $config['bdd']) or die(mysqli_error($mysqli));
while (1) {
if ($x > 3600) {
echo "\nCleaning everything (once per hour)";
$task = "TRUNCATE TABLE `liskstats`";
$query = mysqli_query($mysqli,$task) or die(mysqli_error($mysqli));
}
$response = json_decode($client->receive(),true);
if (isset($response['data'])) {
if (isset($response['data']['id'])) {
$object = $response['data']['id'];
echo "\n".$object;
$task = "INSERT INTO liskstats (object) SELECT * FROM (SELECT '$object') AS tmp WHERE NOT EXISTS (SELECT * FROM liskstats WHERE object = '$object' LIMIT 1)";
$query = mysqli_query($mysqli,$task) or die(mysqli_error($mysqli));
}
}
sleep(1);
}
?>
Oops, something went wrong.

0 comments on commit e962dcb

Please sign in to comment.