Merge pull request #1 from jhoenicke/master

Pull in updates
This commit is contained in:
J62 2020-11-07 04:10:02 -08:00 committed by GitHub
commit b3dd26cf2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 1912 additions and 151 deletions

View File

@ -63,3 +63,6 @@ root. Finally link to the dynamic js files in `/dev/shm/mempool-btc`.
cd $HOME/mempool/web/queue
sudo ln -s $HOME/mempool/web/* /var/www/html
ln -s /dev/shm/mempool-btc/*.js $HOME/mempool/web/queue/
You then need to open `$HOME/mempool/web/queue/mempool.js` in your favorite
editor and change the config array to include your web server configuration.

View File

@ -1,60 +0,0 @@
#!/usr/bin/perl
use List::Util qw[min max];
my $SQLITE="sqlite3";
my $MYSQL="mysql";
my $MEMPOOLLOG="mempool.log";
my $MYSQLMEMPOOLDB="btc_mempool";
my @feelimit=(0.0001,1,2,3,4,5,6,7,8,10,12,14,17,20,25,30,40,50,60,70,80,100,120,140,170,200,250,300,400,500,600,700,800,1000,1200,1400,1700,2000,2500,3000,4000,5000,6000,7000,8000,10000,2100000000000000);
my @total=();
my @count=();
my @fees=();
my $time = time();
for ($i = 0; $i< @feelimit - 1; $i++) {
$total[$i] = 0;
$count[$i] = 0;
$fees[$i] = 0;
}
my $found = 0;
while(<>) {
/"size": (\d+)/ and $size = $1;
/"ancestorsize": (\d+)/ and $asize = $1;
/"descendantsize": (\d+)/ and $dsize = $1;
/"fee": (\d*\.\d+)/ and $fee = int($1*1e8 + .5);
/"ancestorfees": (\d+)/ and $afees = $1;
/"descendantfees": (\d+)/ and $dfees = $1;
if (/},/) {
$afpb = $afees / $asize; # ancestor fee (includes current)
$fpb = $fee / $size; # current fee
$dfpb = $dfees / $dsize; # descendant fee (includes current)
# total average fee for mining all ancestors and descendants.
$tfpb = ($afees + $dfees - $fee) / ($asize + $dsize - $size);
# the "min"s ensure we take the fee level of ancestors in account
# if and only if they pay less (like a miner would do).
# the "max" ensures we take the descendants into account for CPFP.
$feeperbyte = max(min($dfpb, $tfpb), min($fpb, $afpb));
for ($i = 0; $i< @feelimit-1; $i++) {
if ($feeperbyte >= $feelimit[$i] && $feeperbyte < $feelimit[$i+1]) {
$total[$i] += $size;
$count[$i]++;
$fees[$i] += $fee;
}
}
$found = 1;
}
}
if ($found) {
my $cnt = join(",", @count);
my $size = join(",", @total);
my $fee = join(",", @fees);
open(LOG, ">>$MEMPOOLLOG");
print LOG "[$time,[$cnt],[$size],[$fee]],\n";
close(LOG);
open(SQL, "|$MYSQL $MYSQLMEMPOOLDB");
$line = "INSERT INTO mempool VALUES($time,$cnt,$size,$fee);\n";
print SQL $line;
close SQL;
}

View File

@ -1,13 +1,33 @@
#!/bin/bash
DESTDIR=/dev/shm/mempool-btc
BITCOINCLI=/home/bitcoin/bin/bitcoin-cli
MEMPOOLHOME=/home/mempool/mempool
TMPFILE=/dev/shm/mempool-btc/rawdump.txt
mkdir -p /dev/shm/mempool-btc
TMPFILE=$DESTDIR/rawdump.txt
export DESTDIR MEMPOOLHOME
cd $MEMPOOLHOME
rm -f $TMPFILE
$BITCOINCLI getrawmempool true > $TMPFILE
perl mempool-sql.pl < $TMPFILE
./mkdata.sh
# create ram-disk directory if it does not exists
if [ ! -e $DESTDIR ]; then
mkdir -p $DESTDIR/LOCK
# read mempool.log once sequentially to quickly load it in buffers
cat mempool.log > /dev/null
./mkdata.sh
rmdir $DESTDIR/LOCK
fi
# create mempool statistics, protected by LOCK
if ! mkdir $DESTDIR/LOCK 2>/dev/null; then
exit
fi
$BITCOINCLI getrawmempool true > $TMPFILE
python3 mempool_sql.py < $TMPFILE
rmdir $DESTDIR/LOCK
# update ram-disk directory, protected by DATALOCK
if ! mkdir $DESTDIR/DATALOCK 2>/dev/null; then
exit
fi
./updatedata.sh
rmdir $DESTDIR/DATALOCK

71
mempool_sql.py Normal file
View File

@ -0,0 +1,71 @@
#!/usr/bin/env python3
import json
import sys
import time
from subprocess import PIPE, Popen
MYSQL = "/usr/bin/mysql"
MEMPOOLLOG = "mempool.log"
MYSQLMEMPOOLDB = "btc_mempool"
FEELIMIT = [0.0001, 1, 2, 3, 4, 5, 6, 7, 8, 10,
12, 14, 17, 20, 25, 30, 40, 50, 60, 70, 80, 100,
120, 140, 170, 200, 250, 300, 400, 500, 600, 700, 800, 1000,
1200, 1400, 1700, 2000, 2500, 3000, 4000, 5000, 6000, 7000, 8000, 10000]
sizes = [0] * len(FEELIMIT)
count = [0] * len(FEELIMIT)
fees = [0] * len(FEELIMIT)
found = False
def parse_txdata(obj):
global sizes, count, fees, found
if "size" in obj:
size = obj["size"]
fee = int(obj["fee"]*100000000)
if "ancestorsize" in obj:
asize = obj["ancestorsize"]
afees = obj["ancestorfees"]
else:
asize = size
afees = fee
dsize = obj["descendantsize"]
dfees = obj["descendantfees"]
afpb = afees / asize # ancestor fee (includes current)
fpb = fee / size # current fee
dfpb = dfees / dsize # descendant fee (includes current)
# total average fee for mining all ancestors and descendants.
tfpb = (afees + dfees - fee) / (asize + dsize - size)
feeperbyte = max(min(dfpb, tfpb), min(fpb, afpb))
found = True
for i, limit in enumerate(FEELIMIT):
if (feeperbyte >= limit and
(i == len(FEELIMIT) - 1 or feeperbyte < FEELIMIT[i+1])):
sizes[i] += size
count[i] += 1
fees[i] += fee
break
return None
return obj
def dump_data(timestamp, sizes, count, fees):
sizesstr = ",".join(str(x) for x in sizes)
countstr = ",".join(str(x) for x in count)
feesstr = ",".join(str(x) for x in fees)
with open(MEMPOOLLOG, "a") as logfile:
logfile.write("[{:d},[{}],[{}],[{}]],\n"
.format(timestamp, countstr, sizesstr, feesstr))
proc = Popen([MYSQL, MYSQLMEMPOOLDB], stdin=PIPE, stdout=PIPE)
proc.communicate("INSERT INTO mempool VALUES({:d},{},{},{});\n"
.format(timestamp, countstr, sizesstr, feesstr)
.encode("ascii"))
def main():
global sizes, count, fees, found
timestamp = int(time.time())
json.load(sys.stdin, object_hook=parse_txdata)
if found:
dump_data(timestamp, sizes, count, fees)
main()

View File

@ -1,8 +1,8 @@
#!/bin/bash
# create the JSON files delivering the summarized mempool
MEMPOOL=mempool.log
DESTDIR=/dev/shm/mempool-btc
mkdir -p $DESTDIR
createfile() {
(echo 'call(['; eval "$CMD"; echo '])') > $DESTDIR/$NAME.js.new

View File

@ -6,18 +6,18 @@ use Data::Dumper;
my $port = 8332;
if (open COOKIE, "<$ENV{HOME}/.bitcoin/.cookie") {
$_=<COOKIE>;
($user,$pwd) = split ":", $_;
close COOKIE;
$_=<COOKIE>;
($user,$pwd) = split ":", $_;
close COOKIE;
} elsif (open CONFIG, "<$ENV{HOME}/.bitcoin/bitcoin.conf") {
while (<CONFIG>) {
/rpcuser=(.*)/ and $user = $1;
/rpcpassword=(.*)/ and $pwd = $1;
}
close CONFIG;
while (<CONFIG>) {
/rpcuser=(.*)/ and $user = $1;
/rpcpassword=(.*)/ and $pwd = $1;
}
close CONFIG;
} else {
print "Cannot find credentials!";
exit;
print "Cannot find credentials!";
exit;
}
my $client = new JSON::RPC::Legacy::Client;
@ -33,7 +33,7 @@ while(<>) {
});
if ($res) {
if ($res->is_error) {
print "Tx: $_ \n";
print "Tx: $_ \n";
print "Error: ", Dumper($res->error_message);
}
} else {

47
updatedata.sh Executable file
View File

@ -0,0 +1,47 @@
#!/bin/bash
# update the JSON files delivering the summarized mempool
#
# LINE is set to the last line in mempool.
# for each file:
# check if current minute divisible by IVAL
# if divisible:
# remove first line (after 'call([').
# add LINE to this file (before last line '])').
MEMPOOL=mempool.log
LINE=`tail -1 $MEMPOOL`
SECOND=`date +%s`
MINUTE=`expr $SECOND / 60`
updatefile() {
NAME=$1
MINUTES=$2
IVAL=$3
if [ `expr $MINUTE % $IVAL` -eq "0" ]; then
(echo 'call(['; tail -n +3 $DESTDIR/$NAME.js | head -n -1; echo "$LINE"; echo '])') > $DESTDIR/$NAME.js.new
mv $DESTDIR/$NAME.js.new $DESTDIR/$NAME.js
fi
}
updatefile_all() {
NAME=all
IVAL=$1
if [ `expr $MINUTE % $IVAL` -eq "0" ]; then
(head -n -1 $DESTDIR/$NAME.js; echo "$LINE"; echo '])') > $DESTDIR/$NAME.js.new
mv $DESTDIR/$NAME.js.new $DESTDIR/$NAME.js
fi
}
updatefile 2h 120 1
updatefile 8h 480 1
updatefile 24h 1440 1
updatefile 2d 2880 2
updatefile 4d 5760 4
updatefile 1w 10080 7
updatefile 2w 20160 14
updatefile 30d 43200 30
updatefile 3m 131040 90
updatefile 6m 262080 180
updatefile 1y 524160 360
updatefile_all 360

46
web/lightning/README.md Normal file
View File

@ -0,0 +1,46 @@
Johoe's lightning setup
=======================
The web/lnd directory contains two python scripts that connect to an instance
of lnd running on the current machine and handle invoices. They mostly follow
the lnd grpc tutorial for python.
To use, follow the directions from the [lnd documentation][1] and setup
python in a virtualenv. I copied the `rpc_pb*` files into the site-packages
directory of the virtual environment. Use the python from this directory
in your httpd cgi configuration. I use lighttpd with:
```
$HTTP["url"] =~ "^/lnd/" {
cgi.assign = ( ".py" => "/home/lnd/lnd/bin/python" )
}
```
Make sure the `invoice.macaroon` file and `tls.cert` are world readable. LND
already sets their permissions correctly, but you have to set executable
permissions for the directories so they are allowed to be traversed.
The script `invoice-mp.py` creates an invoice without any amount (so that
the client will ask for the amount) and with a fixed memo text (that is shown
in the payment history of the client. If you want to make memo and amount a
parameter you can use `REQUEST_URI` to parse the parameter or better yet,
use the cgi python package. But proceed at your own risk and take care to
sanitize user input.
The script `check-invoice.py` checks for the settlement status of an invoice.
It will repeatedly query the status every second until it is settled or until
a timeout is reached. I thought about using the SubscribeInvoices API, but
you cannot subscribe to a specific invoice and this polling method seemed to
be simpler in the end. The javascript part takes care to recheck on timeout
and display the paid message if invoice is settled.
The file `index.html` in this directory contains the client side logic in
javascript. I use XMLHttpRequest with `POST` as method, mainly to avoid that
intermediate components cache the result. The result is sent as JSON, so
JSON.parse can be used to parse it.
The file `qrcodegen.min.js` that generates QR-codes is from
[Project Nayuki][2]. It is under the MIT license.
[1]: https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md
[2]: https://www.nayuki.io/page/qr-code-generator-library

245
web/lightning/index.html Normal file
View File

@ -0,0 +1,245 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Johoe's Lightning Donation Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css"/>
<script src="qrcodegen.min.js"></script>
</head>
<body onload="loadDoc()">
<div class="tab">
<button class="tablinks" onclick="selectTab(event.currentTarget, 'channel')">Open Channel</button>
<button id="btninvoice" class="tablinks" onclick="selectTab(event.currentTarget, 'invoice')">Payment Request</button>
<button id="defaulttab" class="tablinks" onclick="selectTab(event.currentTarget, 'setamount')">Set Amount</button>
</div>
<div id="channel" class="tabcontent" onclick="copyclipboard('textnode')">
<p>Scan this QRCode to open a channel to my node. Click to copy to clipboard.</p>
<div class="lncontainer"><canvas id="qrnode" class="lnqrcode"></canvas></div>
<textarea id="textnode" class="lntext" rows="2"></textarea>
</div>
<div id="invoice" class="tabcontent">
<p>Scan or click this QRCode to start a payment.</p>
<div class="lncontainer">
<div id="qrwait" class="lnwait">creating payment request<br/>please wait...</div>
<a id="qrlink" href="#"><canvas id="qrinvoice" class="lnqrcode"></canvas></a>
<div id="qrpayed" class="lnsettled">PAID<br/>Thank You</div>
</div>
<textarea id="textinvoice" rows="5" class="lntext"></textarea>
<input type="button" value="Copy to Clipboard"
onclick="copyclipboard('textinvoice')"/>
</div>
<div id="setamount" class="tabcontent">
Pay for server time <span class="footnotebox"><a href="#" onclick="toggle('footnote1')">[*]</a><span id="footnote1" class="footnote" style="display:none;">
Server cost is 48 €/month.<br/>
So one day costs 1.60 €.
</span></span>:
<input type="button" value="1 hour" onclick="setvalue(.07, 'EUR')" />
<input type="button" value="1 day" onclick="setvalue(1.60, 'EUR')" />
<input type="button" value="1 week" onclick="setvalue(11.20, 'EUR')" />
<input type="button" value="1 month" onclick="setvalue(48.00, 'EUR')" /><br/>
<p>Amount: <input type="number" id="value" value="" onchange="updateValue()" style="text-align:right;" />
<select id="unit" value="sat" onchange="updateValue()">
<option value="sat">sat</option>
<option value="bit">bit</option>
<option value="USD">USD</option>
<option value="EUR">EUR</option>
<option value="BTC">BTC</option>
</select></p>
<p style="text-align:right;"> =
<span id="btcvalue">0</span> BTC
(<span id="factor">1</span> <span id="unit2">BTC</span>/BTC).</p>
<p>Memo: <input type="text" id="memo" size="30" value="Donation for Johoe's mempool" /></p>
<input type="button" value="Get invoice" onclick="invoice()" />
</div>
<script>
var btceur = 10138;
var btcusd = 11397;
var valueinsat = 0;
var border = 4;
var scale = 4;
var uri = "0358327cb80ab2a8db36a5924c62966c7b4a753045600df594aa3863ecb618cc5d@37.221.198.57:9735";
var qruri = qrcodegen.QrCode.encodeText(uri, qrcodegen.QrCode.Ecc.MEDIUM);
qruri.drawCanvas(scale, border, document.getElementById("qrnode"));
document.getElementById("textnode").value = uri;
var paymentrhash;
function setvalue(value, unit) {
document.getElementById("value").value = value;
document.getElementById("unit").value = unit;
updateValue();
}
function updateValue() {
var value = document.getElementById("value").value;
var unit = document.getElementById("unit").value;
var factor = 1.0;
switch(unit) {
case "BTC":
factor = 1.0;
break;
case "EUR":
factor = btceur;
break;
case "USD":
factor = btcusd;
break;
case "bit":
factor = 1000000.0;
break;
case "sat":
factor = 100000000.0;
break;
}
valueinsat = Math.floor((value * 100000000.0 / factor) + 0.5);
document.getElementById("btcvalue").innerHTML = (valueinsat/100000000.0).toFixed(8);
document.getElementById("factor").innerHTML = factor;
document.getElementById("unit2").innerHTML = unit;
}
function invoice() {
var value = ~~valueinsat;
var memo = document.getElementById("memo").value;
if (value < 0) {
alert("Nice try :) Please enter a positive value");
return;
}
if (value > 4294967) {
alert("Please keep amount to less than 0.04 BTC");
return;
}
requestInvoice(value, memo);
selectTab(document.getElementById("btninvoice"), "invoice");
}
function waitfor(rhash) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (rhash != paymentrhash) {
return;
}
if (this.readyState == 4) {
if (this.status == 200) {
var response = JSON.parse(this.responseText);
if (!response.settled) {
waitfor(rhash);
} else {
document.getElementById("qrinvoice").style.opacity = 0.2;
document.getElementById("qrpayed").style.display = "block";
}
} else if (this.status != 0) {
alert("Cannot check payment status: "+ this.status + " state: "+this.readyState+"text: "+this.responseText);
}
}
}
xhttp.open("POST", "/lnd/check-invoice.py?r_hash="+rhash, true);
xhttp.send();
}
function requestInvoice(value, memo) {
document.getElementById("qrwait").style.display = "block";
document.getElementById("qrlink").href = "#";
document.getElementById("textinvoice").value = "";
var canvas = document.getElementById("qrinvoice");
var context = canvas.getContext('2d');
context.clearRect(0, 0, canvas.width, canvas.height);
paymentrhash = 0;
var xhttp = new XMLHttpRequest();
function handleInvoice(invoice) {
var rhash = invoice.r_hash;
paymentrhash = rhash;
paymentrequest = invoice.payment_request;
var qrcode = qrcodegen.QrCode.encodeText(paymentrequest.toUpperCase(), qrcodegen.QrCode.Ecc.LOW);
document.getElementById("qrwait").style.display = "none";
qrcode.drawCanvas(scale, border, document.getElementById("qrinvoice"));
document.getElementById("qrlink").href = "lightning:" + paymentrequest;
document.getElementById("textinvoice").value = paymentrequest;
waitfor(rhash);
}
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
handleInvoice(JSON.parse(this.responseText));
} else {
document.getElementById("textinvoice").value = "Failed to get payment request";
}
}
}
var params = "memo="+encodeURIComponent(memo)+"&value="+~~value;
xhttp.open("POST", "/lnd/invoice.py?"+params, true);
xhttp.send();
}
var xhttpbtc = new XMLHttpRequest();
xhttpbtc.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var response = JSON.parse(this.responseText);
btcusd = response.bpi.USD.rate_float;
btceur = response.bpi.EUR.rate_float;
updateValue();
}
}
function loadDoc() {
var donationfor = "Johoe's mempool";
if (location.hash.length > 0) {
donationfor = location.hash.substring(1);
}
document.getElementById("memo").value = "Donation for " + donationfor;
requestInvoice(0, "Donation to " + donationfor);
xhttpbtc.open("GET", "https://api.coindesk.com/v1/bpi/currentprice.json", true);
xhttpbtc.send();
updateValue();
}
function selectTab(button, name) {
// Declare all variables
var i, tabcontent, tablinks;
// Get all elements with class="tabcontent" and hide them
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
// Get all elements with class="tablinks" and remove the class "active"
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
// Show the current tab, and add an "active" class to the button that opened the tab
document.getElementById(name).style.display = "block";
button.className += " active";
}
function copyclipboard(id) {
var copyText = document.getElementById(id);
copyText.select();
document.execCommand("copy");
}
function toggle(id) {
var block = document.getElementById(id);
var count = 0;
if (block.style.display == "none") {
block.style.display="block";
var hidefootnote = function (event) {
if (count++ >= 1) {
block.style.display="none";
document.removeEventListener('click', hidefootnote);
}
};
document.addEventListener('click', hidefootnote);
}
}
document.getElementById("defaulttab").click();
</script>
<div class="centered" style="font-size: 13px; margin: 20px;">
Source code on github: <a href="https://github.com/jhoenicke/mempool/tree/master/web/lightning/" target="_blank">https://github.com/jhoenicke/mempool</a><br/>
© 2018 <a href="https://jochen-hoenicke.de/">Jochen Hoenicke</a>
</div>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

982
web/lightning/qrcodegen.js Normal file
View File

@ -0,0 +1,982 @@
/*
* QR Code generator library (JavaScript)
*
* Copyright (c) Project Nayuki. (MIT License)
* https://www.nayuki.io/page/qr-code-generator-library
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
* - The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* - The Software is provided "as is", without warranty of any kind, express or
* implied, including but not limited to the warranties of merchantability,
* fitness for a particular purpose and noninfringement. In no event shall the
* authors or copyright holders be liable for any claim, damages or other
* liability, whether in an action of contract, tort or otherwise, arising from,
* out of or in connection with the Software or the use or other dealings in the
* Software.
*/
"use strict";
/*
* Module "qrcodegen", public members:
* - Class QrCode:
* - Function encodeText(str text, QrCode.Ecc ecl) -> QrCode
* - Function encodeBinary(list<byte> data, QrCode.Ecc ecl) -> QrCode
* - Function encodeSegments(list<QrSegment> segs, QrCode.Ecc ecl,
* int minVersion=1, int maxVersion=40, mask=-1, boostEcl=true) -> QrCode
* - Constants int MIN_VERSION, MAX_VERSION
* - Constructor QrCode(list<int> datacodewords, int mask, int version, QrCode.Ecc ecl)
* - Fields int version, size, mask
* - Field QrCode.Ecc errorCorrectionLevel
* - Method getModule(int x, int y) -> bool
* - Method drawCanvas(int scale, int border, HTMLCanvasElement canvas) -> void
* - Method toSvgString(int border) -> str
* - Enum Ecc:
* - Constants LOW, MEDIUM, QUARTILE, HIGH
* - Field int ordinal
* - Class QrSegment:
* - Function makeBytes(list<int> data) -> QrSegment
* - Function makeNumeric(str data) -> QrSegment
* - Function makeAlphanumeric(str data) -> QrSegment
* - Function makeSegments(str text) -> list<QrSegment>
* - Function makeEci(int assignVal) -> QrSegment
* - Constructor QrSegment(QrSegment.Mode mode, int numChars, list<int> bitData)
* - Field QrSegment.Mode mode
* - Field int numChars
* - Method getBits() -> list<int>
* - Constants RegExp NUMERIC_REGEX, ALPHANUMERIC_REGEX
* - Enum Mode:
* - Constants NUMERIC, ALPHANUMERIC, BYTE, KANJI, ECI
*/
var qrcodegen = new function() {
/*---- QR Code symbol class ----*/
/*
* A class that represents an immutable square grid of black and white cells for a QR Code symbol,
* with associated static functions to create a QR Code from user-supplied textual or binary data.
* This class covers the QR Code model 2 specification, supporting all versions (sizes)
* from 1 to 40, all 4 error correction levels.
* This constructor creates a new QR Code symbol with the given version number, error correction level, binary data array,
* and mask number. mask = -1 is for automatic choice, or 0 to 7 for fixed choice. This is a cumbersome low-level constructor
* that should not be invoked directly by the user. To go one level up, see the QrCode.encodeSegments() function.
*/
this.QrCode = function(datacodewords, mask, version, errCorLvl) {
/*---- Constructor ----*/
// Check arguments and handle simple scalar fields
if (mask < -1 || mask > 7)
throw "Mask value out of range";
if (version < MIN_VERSION || version > MAX_VERSION)
throw "Version value out of range";
var size = version * 4 + 17;
// Initialize both grids to be size*size arrays of Boolean false
var row = [];
for (var i = 0; i < size; i++)
row.push(false);
var modules = [];
var isFunction = [];
for (var i = 0; i < size; i++) {
modules.push(row.slice());
isFunction.push(row.slice());
}
// Handle grid fields, draw function patterns, draw all codewords
drawFunctionPatterns();
var allCodewords = addEccAndInterleave(datacodewords);
drawCodewords(allCodewords);
// Handle masking
if (mask == -1) { // Automatically choose best mask
var minPenalty = Infinity;
for (var i = 0; i < 8; i++) {
drawFormatBits(i);
applyMask(i);
var penalty = getPenaltyScore();
if (penalty < minPenalty) {
mask = i;
minPenalty = penalty;
}
applyMask(i); // Undoes the mask due to XOR
}
}
if (mask < 0 || mask > 7)
throw "Assertion error";
drawFormatBits(mask); // Overwrite old format bits
applyMask(mask); // Apply the final choice of mask
isFunction = null;
/*---- Read-only instance properties ----*/
// This QR Code symbol's version number, which is always between 1 and 40 (inclusive).
Object.defineProperty(this, "version", {value:version});
// The width and height of this QR Code symbol, measured in modules.
// Always equal to version * 4 + 17, in the range 21 to 177.
Object.defineProperty(this, "size", {value:size});
// The error correction level used in this QR Code symbol.
Object.defineProperty(this, "errorCorrectionLevel", {value:errCorLvl});
// The mask pattern used in this QR Code symbol, in the range 0 to 7 (i.e. unsigned 3-bit integer).
// Note that even if the constructor was called with automatic masking requested
// (mask = -1), the resulting object will still have a mask value between 0 and 7.
Object.defineProperty(this, "mask", {value:mask});
/*---- Accessor methods ----*/
// (Public) Returns the color of the module (pixel) at the given coordinates, which is either
// false for white or true for black. The top left corner has the coordinates (x=0, y=0).
// If the given coordinates are out of bounds, then false (white) is returned.
this.getModule = function(x, y) {
return 0 <= x && x < size && 0 <= y && y < size && modules[y][x];
};
/*---- Public instance methods ----*/
// Draws this QR Code symbol with the given module scale and number of modules onto the given HTML canvas element.
// The canvas will be resized to a width and height of (this.size + border * 2) * scale. The painted image will be purely
// black and white with no transparent regions. The scale must be a positive integer, and the border must be a non-negative integer.
this.drawCanvas = function(scale, border, canvas) {
if (scale <= 0 || border < 0)
throw "Value out of range";
var width = (size + border * 2) * scale;
canvas.width = width;
canvas.height = width;
var ctx = canvas.getContext("2d");
for (var y = -border; y < size + border; y++) {
for (var x = -border; x < size + border; x++) {
ctx.fillStyle = this.getModule(x, y) ? "#000000" : "#FFFFFF";
ctx.fillRect((x + border) * scale, (y + border) * scale, scale, scale);
}
}
};
// Returns a string of SVG XML code representing an image of this QR Code symbol with the given
// number of border modules. Note that Unix newlines (\n) are always used, regardless of the platform.
this.toSvgString = function(border) {
if (border < 0)
throw "Border must be non-negative";
var parts = [];
for (var y = 0; y < size; y++) {
for (var x = 0; x < size; x++) {
if (this.getModule(x, y))
parts.push("M" + (x + border) + "," + (y + border) + "h1v1h-1z");
}
}
return '<?xml version="1.0" encoding="UTF-8"?>\n' +
'<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' +
'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 ' +
(size + border * 2) + ' ' + (size + border * 2) + '" stroke="none">\n' +
'\t<rect width="100%" height="100%" fill="#FFFFFF"/>\n' +
'\t<path d="' + parts.join(" ") + '" fill="#000000"/>\n' +
'</svg>\n';
};
/*---- Private helper methods for constructor: Drawing function modules ----*/
// Reads this object's version field, and draws and marks all function modules.
function drawFunctionPatterns() {
// Draw horizontal and vertical timing patterns
for (var i = 0; i < size; i++) {
setFunctionModule(6, i, i % 2 == 0);
setFunctionModule(i, 6, i % 2 == 0);
}
// Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
drawFinderPattern(3, 3);
drawFinderPattern(size - 4, 3);
drawFinderPattern(3, size - 4);
// Draw numerous alignment patterns
var alignPatPos = getAlignmentPatternPositions();
var numAlign = alignPatPos.length;
for (var i = 0; i < numAlign; i++) {
for (var j = 0; j < numAlign; j++) {
// Don't draw on the three finder corners
if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0))
drawAlignmentPattern(alignPatPos[i], alignPatPos[j]);
}
}
// Draw configuration data
drawFormatBits(0); // Dummy mask value; overwritten later in the constructor
drawVersion();
}
// Draws two copies of the format bits (with its own error correction code)
// based on the given mask and this object's error correction level field.
function drawFormatBits(mask) {
// Calculate error correction code and pack bits
var data = errCorLvl.formatBits << 3 | mask; // errCorrLvl is uint2, mask is uint3
var rem = data;
for (var i = 0; i < 10; i++)
rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
var bits = (data << 10 | rem) ^ 0x5412; // uint15
if (bits >>> 15 != 0)
throw "Assertion error";
// Draw first copy
for (var i = 0; i <= 5; i++)
setFunctionModule(8, i, getBit(bits, i));
setFunctionModule(8, 7, getBit(bits, 6));
setFunctionModule(8, 8, getBit(bits, 7));
setFunctionModule(7, 8, getBit(bits, 8));
for (var i = 9; i < 15; i++)
setFunctionModule(14 - i, 8, getBit(bits, i));
// Draw second copy
for (var i = 0; i <= 7; i++)
setFunctionModule(size - 1 - i, 8, getBit(bits, i));
for (var i = 8; i < 15; i++)
setFunctionModule(8, size - 15 + i, getBit(bits, i));
setFunctionModule(8, size - 8, true); // Always black
}
// Draws two copies of the version bits (with its own error correction code),
// based on this object's version field, iff 7 <= version <= 40.
function drawVersion() {
if (version < 7)
return;
// Calculate error correction code and pack bits
var rem = version; // version is uint6, in the range [7, 40]
for (var i = 0; i < 12; i++)
rem = (rem << 1) ^ ((rem >>> 11) * 0x1F25);
var bits = version << 12 | rem; // uint18
if (bits >>> 18 != 0)
throw "Assertion error";
// Draw two copies
for (var i = 0; i < 18; i++) {
var bit = getBit(bits, i);
var a = size - 11 + i % 3;
var b = Math.floor(i / 3);
setFunctionModule(a, b, bit);
setFunctionModule(b, a, bit);
}
}
// Draws a 9*9 finder pattern including the border separator,
// with the center module at (x, y). Modules can be out of bounds.
function drawFinderPattern(x, y) {
for (var dy = -4; dy <= 4; dy++) {
for (var dx = -4; dx <= 4; dx++) {
var dist = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm
var xx = x + dx, yy = y + dy;
if (0 <= xx && xx < size && 0 <= yy && yy < size)
setFunctionModule(xx, yy, dist != 2 && dist != 4);
}
}
}
// Draws a 5*5 alignment pattern, with the center module
// at (x, y). All modules must be in bounds.
function drawAlignmentPattern(x, y) {
for (var dy = -2; dy <= 2; dy++) {
for (var dx = -2; dx <= 2; dx++)
setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1);
}
}
// Sets the color of a module and marks it as a function module.
// Only used by the constructor. Coordinates must be in bounds.
function setFunctionModule(x, y, isBlack) {
modules[y][x] = isBlack;
isFunction[y][x] = true;
}
/*---- Private helper methods for constructor: Codewords and masking ----*/
// Returns a new byte string representing the given data with the appropriate error correction
// codewords appended to it, based on this object's version and error correction level.
function addEccAndInterleave(data) {
if (data.length != QrCode.getNumDataCodewords(version, errCorLvl))
throw "Invalid argument";
// Calculate parameter numbers
var numBlocks = QrCode.NUM_ERROR_CORRECTION_BLOCKS[errCorLvl.ordinal][version];
var blockEccLen = QrCode.ECC_CODEWORDS_PER_BLOCK [errCorLvl.ordinal][version];
var rawCodewords = Math.floor(QrCode.getNumRawDataModules(version) / 8);
var numShortBlocks = numBlocks - rawCodewords % numBlocks;
var shortBlockLen = Math.floor(rawCodewords / numBlocks);
// Split data into blocks and append ECC to each block
var blocks = [];
var rs = new ReedSolomonGenerator(blockEccLen);
for (var i = 0, k = 0; i < numBlocks; i++) {
var dat = data.slice(k, k + shortBlockLen - blockEccLen + (i < numShortBlocks ? 0 : 1));
k += dat.length;
var ecc = rs.getRemainder(dat);
if (i < numShortBlocks)
dat.push(0);
blocks.push(dat.concat(ecc));
}
// Interleave (not concatenate) the bytes from every block into a single sequence
var result = [];
for (var i = 0; i < blocks[0].length; i++) {
for (var j = 0; j < blocks.length; j++) {
// Skip the padding byte in short blocks
if (i != shortBlockLen - blockEccLen || j >= numShortBlocks)
result.push(blocks[j][i]);
}
}
if (result.length != rawCodewords)
throw "Assertion error";
return result;
}
// Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
// data area of this QR Code symbol. Function modules need to be marked off before this is called.
function drawCodewords(data) {
if (data.length != Math.floor(QrCode.getNumRawDataModules(version) / 8))
throw "Invalid argument";
var i = 0; // Bit index into the data
// Do the funny zigzag scan
for (var right = size - 1; right >= 1; right -= 2) { // Index of right column in each column pair
if (right == 6)
right = 5;
for (var vert = 0; vert < size; vert++) { // Vertical counter
for (var j = 0; j < 2; j++) {
var x = right - j; // Actual x coordinate
var upward = ((right + 1) & 2) == 0;
var y = upward ? size - 1 - vert : vert; // Actual y coordinate
if (!isFunction[y][x] && i < data.length * 8) {
modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
i++;
}
// If this QR Code has any remainder bits (0 to 7), they were assigned as
// 0/false/white by the constructor and are left unchanged by this method
}
}
}
if (i != data.length * 8)
throw "Assertion error";
}
// XORs the codeword modules in this QR Code with the given mask pattern.
// The function modules must be marked and the codeword bits must be drawn
// before masking. Due to the arithmetic of XOR, calling applyMask() with
// the same mask value a second time will undo the mask. A final well-formed
// QR Code symbol needs exactly one (not zero, two, etc.) mask applied.
function applyMask(mask) {
if (mask < 0 || mask > 7)
throw "Mask value out of range";
for (var y = 0; y < size; y++) {
for (var x = 0; x < size; x++) {
var invert;
switch (mask) {
case 0: invert = (x + y) % 2 == 0; break;
case 1: invert = y % 2 == 0; break;
case 2: invert = x % 3 == 0; break;
case 3: invert = (x + y) % 3 == 0; break;
case 4: invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0; break;
case 5: invert = x * y % 2 + x * y % 3 == 0; break;
case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break;
case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break;
default: throw "Assertion error";
}
if (!isFunction[y][x] && invert)
modules[y][x] = !modules[y][x];
}
}
}
// Calculates and returns the penalty score based on state of this QR Code's current modules.
// This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
function getPenaltyScore() {
var result = 0;
// Adjacent modules in row having same color
for (var y = 0; y < size; y++) {
for (var x = 0, runX, colorX; x < size; x++) {
if (x == 0 || modules[y][x] != colorX) {
colorX = modules[y][x];
runX = 1;
} else {
runX++;
if (runX == 5)
result += QrCode.PENALTY_N1;
else if (runX > 5)
result++;
}
}
}
// Adjacent modules in column having same color
for (var x = 0; x < size; x++) {
for (var y = 0, runY, colorY; y < size; y++) {
if (y == 0 || modules[y][x] != colorY) {
colorY = modules[y][x];
runY = 1;
} else {
runY++;
if (runY == 5)
result += QrCode.PENALTY_N1;
else if (runY > 5)
result++;
}
}
}
// 2*2 blocks of modules having same color
for (var y = 0; y < size - 1; y++) {
for (var x = 0; x < size - 1; x++) {
var color = modules[y][x];
if ( color == modules[y][x + 1] &&
color == modules[y + 1][x] &&
color == modules[y + 1][x + 1])
result += QrCode.PENALTY_N2;
}
}
// Finder-like pattern in rows
for (var y = 0; y < size; y++) {
for (var x = 0, bits = 0; x < size; x++) {
bits = ((bits << 1) & 0x7FF) | (modules[y][x] ? 1 : 0);
if (x >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
result += QrCode.PENALTY_N3;
}
}
// Finder-like pattern in columns
for (var x = 0; x < size; x++) {
for (var y = 0, bits = 0; y < size; y++) {
bits = ((bits << 1) & 0x7FF) | (modules[y][x] ? 1 : 0);
if (y >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
result += QrCode.PENALTY_N3;
}
}
// Balance of black and white modules
var black = 0;
modules.forEach(function(row) {
row.forEach(function(color) {
if (color)
black++;
});
});
var total = size * size; // Note that size is odd, so black/total != 1/2
// Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)%
var k = Math.ceil(Math.abs(black * 20 - total * 10) / total) - 1;
result += k * QrCode.PENALTY_N4;
return result;
}
// Returns an ascending list of positions of alignment patterns for this version number.
// Each position is in the range [0,177), and are used on both the x and y axes.
// This could be implemented as lookup table of 40 variable-length lists of integers.
function getAlignmentPatternPositions() {
if (version == 1)
return [];
else {
var numAlign = Math.floor(version / 7) + 2;
var step = (version == 32) ? 26 :
Math.ceil((size - 13) / (numAlign*2 - 2)) * 2;
var result = [6];
for (var i = 0, pos = size - 7; i < numAlign - 1; i++, pos -= step)
result.splice(1, 0, pos);
return result;
}
}
// Returns true iff the i'th bit of x is set to 1.
function getBit(x, i) {
return ((x >>> i) & 1) != 0;
}
};
/*---- Public static factory functions for QrCode ----*/
/*
* Returns a QR Code symbol representing the given Unicode text string at the given error correction level.
* As a conservative upper bound, this function is guaranteed to succeed for strings that have 738 or fewer
* Unicode code points (not UTF-16 code units) if the low error correction level is used. The smallest possible
* QR Code version is automatically chosen for the output. The ECC level of the result may be higher than the
* ecl argument if it can be done without increasing the version.
*/
this.QrCode.encodeText = function(text, ecl) {
var segs = qrcodegen.QrSegment.makeSegments(text);
return this.encodeSegments(segs, ecl);
};
/*
* Returns a QR Code symbol representing the given binary data string at the given error correction level.
* This function always encodes using the binary segment mode, not any text mode. The maximum number of
* bytes allowed is 2953. The smallest possible QR Code version is automatically chosen for the output.
* The ECC level of the result may be higher than the ecl argument if it can be done without increasing the version.
*/
this.QrCode.encodeBinary = function(data, ecl) {
var seg = qrcodegen.QrSegment.makeBytes(data);
return this.encodeSegments([seg], ecl);
};
/*
* Returns a QR Code symbol representing the given segments with the given encoding parameters.
* The smallest possible QR Code version within the given range is automatically chosen for the output.
* This function allows the user to create a custom sequence of segments that switches
* between modes (such as alphanumeric and binary) to encode text more efficiently.
* This function is considered to be lower level than simply encoding text or binary data.
*/
this.QrCode.encodeSegments = function(segs, ecl, minVersion, maxVersion, mask, boostEcl) {
if (minVersion == undefined) minVersion = MIN_VERSION;
if (maxVersion == undefined) maxVersion = MAX_VERSION;
if (mask == undefined) mask = -1;
if (boostEcl == undefined) boostEcl = true;
if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7)
throw "Invalid value";
// Find the minimal version number to use
var version, dataUsedBits;
for (version = minVersion; ; version++) {
var dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8; // Number of data bits available
dataUsedBits = qrcodegen.QrSegment.getTotalBits(segs, version);
if (dataUsedBits <= dataCapacityBits)
break; // This version number is found to be suitable
if (version >= maxVersion) // All versions in the range could not fit the given data
throw "Data too long";
}
// Increase the error correction level while the data still fits in the current version number
[this.Ecc.MEDIUM, this.Ecc.QUARTILE, this.Ecc.HIGH].forEach(function(newEcl) { // From low to high
if (boostEcl && dataUsedBits <= QrCode.getNumDataCodewords(version, newEcl) * 8)
ecl = newEcl;
});
// Concatenate all segments to create the data bit string
var bb = new BitBuffer();
segs.forEach(function(seg) {
bb.appendBits(seg.mode.modeBits, 4);
bb.appendBits(seg.numChars, seg.mode.numCharCountBits(version));
seg.getBits().forEach(function(bit) {
bb.push(bit);
});
});
if (bb.length != dataUsedBits)
throw "Assertion error";
// Add terminator and pad up to a byte if applicable
var dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8;
if (bb.length > dataCapacityBits)
throw "Assertion error";
bb.appendBits(0, Math.min(4, dataCapacityBits - bb.length));
bb.appendBits(0, (8 - bb.length % 8) % 8);
if (bb.length % 8 != 0)
throw "Assertion error";
// Pad with alternating bytes until data capacity is reached
for (var padByte = 0xEC; bb.length < dataCapacityBits; padByte ^= 0xEC ^ 0x11)
bb.appendBits(padByte, 8);
// Create the QR Code symbol
return new this(bb.getBytes(), mask, version, ecl);
};
/*---- Public constants for QrCode ----*/
var MIN_VERSION = 1;
var MAX_VERSION = 40;
Object.defineProperty(this.QrCode, "MIN_VERSION", {value:MIN_VERSION});
Object.defineProperty(this.QrCode, "MAX_VERSION", {value:MAX_VERSION});
/*---- Private static helper functions for QrCode ----*/
var QrCode = {}; // Private object to assign properties to. Not the same object as 'this.QrCode'.
// Returns the number of data bits that can be stored in a QR Code of the given version number, after
// all function modules are excluded. This includes remainder bits, so it might not be a multiple of 8.
// The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table.
QrCode.getNumRawDataModules = function(ver) {
if (ver < MIN_VERSION || ver > MAX_VERSION)
throw "Version number out of range";
var result = (16 * ver + 128) * ver + 64;
if (ver >= 2) {
var numAlign = Math.floor(ver / 7) + 2;
result -= (25 * numAlign - 10) * numAlign - 55;
if (ver >= 7)
result -= 36;
}
return result;
};
// Returns the number of 8-bit data (i.e. not error correction) codewords contained in any
// QR Code of the given version number and error correction level, with remainder bits discarded.
// This stateless pure function could be implemented as a (40*4)-cell lookup table.
QrCode.getNumDataCodewords = function(ver, ecl) {
return Math.floor(QrCode.getNumRawDataModules(ver) / 8) -
QrCode.ECC_CODEWORDS_PER_BLOCK [ecl.ordinal][ver] *
QrCode.NUM_ERROR_CORRECTION_BLOCKS[ecl.ordinal][ver];
};
/*---- Private tables of constants for QrCode ----*/
// For use in getPenaltyScore(), when evaluating which mask is best.
QrCode.PENALTY_N1 = 3;
QrCode.PENALTY_N2 = 3;
QrCode.PENALTY_N3 = 40;
QrCode.PENALTY_N4 = 10;
QrCode.ECC_CODEWORDS_PER_BLOCK = [
// Version: (note that index 0 is for padding, and is set to an illegal value)
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
[null, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Low
[null, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28], // Medium
[null, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // Quartile
[null, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30], // High
];
QrCode.NUM_ERROR_CORRECTION_BLOCKS = [
// Version: (note that index 0 is for padding, and is set to an illegal value)
// 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 Error correction level
[null, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25], // Low
[null, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49], // Medium
[null, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68], // Quartile
[null, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81], // High
];
/*---- Public helper enumeration ----*/
/*
* Represents the error correction level used in a QR Code symbol.
*/
this.QrCode.Ecc = {
// Constants declared in ascending order of error protection
LOW : new Ecc(0, 1),
MEDIUM : new Ecc(1, 0),
QUARTILE: new Ecc(2, 3),
HIGH : new Ecc(3, 2),
};
// Private constructor.
function Ecc(ord, fb) {
// (Public) In the range 0 to 3 (unsigned 2-bit integer)
Object.defineProperty(this, "ordinal", {value:ord});
// (Package-private) In the range 0 to 3 (unsigned 2-bit integer)
Object.defineProperty(this, "formatBits", {value:fb});
}
/*---- Data segment class ----*/
/*
* Represents a segment of character data, binary data, or control data
* to be put into a QR Code symbol. Instances of this class are immutable.
* This segment class imposes no length restrictions, but QR Codes have restrictions.
* Even in the most favorable conditions, a QR Code can only hold 7089 characters of data.
* Any segment longer than this is meaningless for the purpose of generating QR Codes.
*/
this.QrSegment = function(mode, numChars, bitData) {
if (numChars < 0 || !(mode instanceof Mode))
throw "Invalid argument";
bitData = bitData.slice(); // Make defensive copy
// The mode indicator for this segment.
Object.defineProperty(this, "mode", {value:mode});
// The length of this segment's unencoded data, measured in characters. Always zero or positive.
Object.defineProperty(this, "numChars", {value:numChars});
// Returns a copy of all bits, which is an array of 0s and 1s.
this.getBits = function() {
return bitData.slice(); // Make defensive copy
};
};
/*---- Public static factory functions for QrSegment ----*/
/*
* Returns a segment representing the given binary data encoded in byte mode.
*/
this.QrSegment.makeBytes = function(data) {
var bb = new BitBuffer();
data.forEach(function(b) {
bb.appendBits(b, 8);
});
return new this(this.Mode.BYTE, data.length, bb);
};
/*
* Returns a segment representing the given string of decimal digits encoded in numeric mode.
*/
this.QrSegment.makeNumeric = function(digits) {
if (!this.NUMERIC_REGEX.test(digits))
throw "String contains non-numeric characters";
var bb = new BitBuffer();
for (var i = 0; i < digits.length; ) { // Consume up to 3 digits per iteration
var n = Math.min(digits.length - i, 3);
bb.appendBits(parseInt(digits.substr(i, n), 10), n * 3 + 1);
i += n;
}
return new this(this.Mode.NUMERIC, digits.length, bb);
};
/*
* Returns a segment representing the given text string encoded in alphanumeric mode.
* The characters allowed are: 0 to 9, A to Z (uppercase only), space,
* dollar, percent, asterisk, plus, hyphen, period, slash, colon.
*/
this.QrSegment.makeAlphanumeric = function(text) {
if (!this.ALPHANUMERIC_REGEX.test(text))
throw "String contains unencodable characters in alphanumeric mode";
var bb = new BitBuffer();
var i;
for (i = 0; i + 2 <= text.length; i += 2) { // Process groups of 2
var temp = QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)) * 45;
temp += QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i + 1));
bb.appendBits(temp, 11);
}
if (i < text.length) // 1 character remaining
bb.appendBits(QrSegment.ALPHANUMERIC_CHARSET.indexOf(text.charAt(i)), 6);
return new this(this.Mode.ALPHANUMERIC, text.length, bb);
};
/*
* Returns a new mutable list of zero or more segments to represent the given Unicode text string.
* The result may use various segment modes and switch modes to optimize the length of the bit stream.
*/
this.QrSegment.makeSegments = function(text) {
// Select the most efficient segment encoding automatically
if (text == "")
return [];
else if (this.NUMERIC_REGEX.test(text))
return [this.makeNumeric(text)];
else if (this.ALPHANUMERIC_REGEX.test(text))
return [this.makeAlphanumeric(text)];
else
return [this.makeBytes(toUtf8ByteArray(text))];
};
/*
* Returns a segment representing an Extended Channel Interpretation
* (ECI) designator with the given assignment value.
*/
this.QrSegment.makeEci = function(assignVal) {
var bb = new BitBuffer();
if (0 <= assignVal && assignVal < (1 << 7))
bb.appendBits(assignVal, 8);
else if ((1 << 7) <= assignVal && assignVal < (1 << 14)) {
bb.appendBits(2, 2);
bb.appendBits(assignVal, 14);
} else if ((1 << 14) <= assignVal && assignVal < 1000000) {
bb.appendBits(6, 3);
bb.appendBits(assignVal, 21);
} else
throw "ECI assignment value out of range";
return new this(this.Mode.ECI, 0, bb);
};
// (Package-private) Calculates and returns the number of bits needed to encode the given segments at the
// given version. The result is infinity if a segment has too many characters to fit its length field.
this.QrSegment.getTotalBits = function(segs, version) {
var result = 0;
for (var i = 0; i < segs.length; i++) {
var seg = segs[i];
var ccbits = seg.mode.numCharCountBits(version);
if (seg.numChars >= (1 << ccbits))
return Infinity; // The segment's length doesn't fit the field's bit width
result += 4 + ccbits + seg.getBits().length;
}
return result;
};
/*---- Constants for QrSegment ----*/
var QrSegment = {}; // Private object to assign properties to. Not the same object as 'this.QrSegment'.
// (Public) Can test whether a string is encodable in numeric mode (such as by using QrSegment.makeNumeric()).
this.QrSegment.NUMERIC_REGEX = /^[0-9]*$/;
// (Public) Can test whether a string is encodable in alphanumeric mode (such as by using QrSegment.makeAlphanumeric()).
this.QrSegment.ALPHANUMERIC_REGEX = /^[A-Z0-9 $%*+.\/:-]*$/;
// (Private) The set of all legal characters in alphanumeric mode, where each character value maps to the index in the string.
QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";
/*---- Public helper enumeration ----*/
/*
* Represents the mode field of a segment. Immutable.
*/
this.QrSegment.Mode = { // Constants
NUMERIC : new Mode(0x1, [10, 12, 14]),
ALPHANUMERIC: new Mode(0x2, [ 9, 11, 13]),
BYTE : new Mode(0x4, [ 8, 16, 16]),
KANJI : new Mode(0x8, [ 8, 10, 12]),
ECI : new Mode(0x7, [ 0, 0, 0]),
};
// Private constructor.
function Mode(mode, ccbits) {
// (Package-private) The mode indicator bits, which is a uint4 value (range 0 to 15).
Object.defineProperty(this, "modeBits", {value:mode});
// (Package-private) Returns the bit width of the segment character count field for this mode object at the given version number.
this.numCharCountBits = function(ver) {
return ccbits[Math.floor((ver + 7) / 17)];
};
}
/*---- Private helper functions and classes ----*/
// Returns a new array of bytes representing the given string encoded in UTF-8.
function toUtf8ByteArray(str) {
str = encodeURI(str);
var result = [];
for (var i = 0; i < str.length; i++) {
if (str.charAt(i) != "%")
result.push(str.charCodeAt(i));
else {
result.push(parseInt(str.substr(i + 1, 2), 16));
i += 2;
}
}
return result;
}
/*
* A private helper class that computes the Reed-Solomon error correction codewords for a sequence of
* data codewords at a given degree. Objects are immutable, and the state only depends on the degree.
* This class exists because each data block in a QR Code shares the same the divisor polynomial.
* This constructor creates a Reed-Solomon ECC generator for the given degree. This could be implemented
* as a lookup table over all possible parameter values, instead of as an algorithm.
*/
function ReedSolomonGenerator(degree) {
if (degree < 1 || degree > 255)
throw "Degree out of range";
// Coefficients of the divisor polynomial, stored from highest to lowest power, excluding the leading term which
// is always 1. For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array {255, 8, 93}.
var coefficients = [];
// Start with the monomial x^0
for (var i = 0; i < degree - 1; i++)
coefficients.push(0);
coefficients.push(1);
// Compute the product polynomial (x - r^0) * (x - r^1) * (x - r^2) * ... * (x - r^{degree-1}),
// drop the highest term, and store the rest of the coefficients in order of descending powers.
// Note that r = 0x02, which is a generator element of this field GF(2^8/0x11D).
var root = 1;
for (var i = 0; i < degree; i++) {
// Multiply the current product by (x - r^i)
for (var j = 0; j < coefficients.length; j++) {
coefficients[j] = ReedSolomonGenerator.multiply(coefficients[j], root);
if (j + 1 < coefficients.length)
coefficients[j] ^= coefficients[j + 1];
}
root = ReedSolomonGenerator.multiply(root, 0x02);
}
// Computes and returns the Reed-Solomon error correction codewords for the given
// sequence of data codewords. The returned object is always a new byte array.
// This method does not alter this object's state (because it is immutable).
this.getRemainder = function(data) {
// Compute the remainder by performing polynomial division
var result = coefficients.map(function() { return 0; });
data.forEach(function(b) {
var factor = b ^ result.shift();
result.push(0);
for (var i = 0; i < result.length; i++)
result[i] ^= ReedSolomonGenerator.multiply(coefficients[i], factor);
});
return result;
};
}
// This static function returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and
// result are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8.
ReedSolomonGenerator.multiply = function(x, y) {
if (x >>> 8 != 0 || y >>> 8 != 0)
throw "Byte out of range";
// Russian peasant multiplication
var z = 0;
for (var i = 7; i >= 0; i--) {
z = (z << 1) ^ ((z >>> 7) * 0x11D);
z ^= ((y >>> i) & 1) * x;
}
if (z >>> 8 != 0)
throw "Assertion error";
return z;
};
/*
* A private helper class that represents an appendable sequence of bits.
* This constructor creates an empty bit buffer (length 0).
*/
function BitBuffer() {
// Packs this buffer's bits into bytes in big endian,
// padding with '0' bit values, and returns the new array.
this.getBytes = function() {
var result = [];
while (result.length * 8 < this.length)
result.push(0);
this.forEach(function(bit, i) {
result[i >>> 3] |= bit << (7 - (i & 7));
});
return result;
};
// Appends the given number of low bits of the given value
// to this sequence. Requires 0 <= val < 2^len.
this.appendBits = function(val, len) {
if (len < 0 || len > 31 || val >>> len != 0)
throw "Value out of range";
for (var i = len - 1; i >= 0; i--) // Append bit by bit
this.push((val >>> i) & 1);
};
}
BitBuffer.prototype = Object.create(Array.prototype);
};

1
web/lightning/qrcodegen.min.js vendored Normal file

File diff suppressed because one or more lines are too long

95
web/lightning/style.css Normal file
View File

@ -0,0 +1,95 @@
body {
font-family: "Helvetica", "Arial", sans-serif;
font-size: 13px;
}
/* Style the tab */
.tab {
max-width: 524px;
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
/* Style the buttons that are used to open the tab content */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
max-width: 500px;
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
.lncontainer {
position: relative;
width: 100%;
text-align: center;
}
.lnqrcode {
display: inline;
}
.lntext {
width: 100%;
border: none;
text-overflow: ellipsis;
}
.lnwait {
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.lnsettled {
display: none;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: green;
font-size: 300%;
font-family: Arial, sans-serif;
font-weight: bold;
}
.footnotebox {
position: relative;
vertical-align: baseline;
}
.footnote {
position: absolute;
min-width: 20em;
left: 0px;
top: 25px;
font-size: .7em;
border: 1px solid;
padding: 5px;
background-color: #fff;
z-index: 9999;
}

77
web/lnd/check-invoice.py Normal file
View File

@ -0,0 +1,77 @@
import re
import os
import sys
import codecs
import time
import grpc
import rpc_pb2 as ln
import rpc_pb2_grpc as lnrpc
def connect():
# Due to updated ECDSA generated tls.cert we need to let gprc know that
# we need to use that cipher suite otherwise there will be a handshake
# error when we communicate with the lnd rpc server.
os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA'
with open('/home/lnd/.lnd/tls.cert', 'rb') as f:
cert = f.read()
with open('/home/lnd/.lnd/data/chain/bitcoin/mainnet/invoice.macaroon', 'rb') as f:
macaroon_bytes = f.read()
macaroon = codecs.encode(macaroon_bytes, 'hex')
def metadata_callback(_context, callback):
# for more info see grpc docs
callback([('macaroon', macaroon)], None)
# build ssl credentials using the cert the same as before
cert_creds = grpc.ssl_channel_credentials(cert)
# now build meta data credentials
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# combine the cert credentials and the macaroon auth credentials
# such that every call is properly encrypted and authenticated
combined_creds = grpc.composite_channel_credentials(cert_creds, auth_creds)
# finally pass in the combined credentials when creating a channel
channel = grpc.secure_channel('localhost:10009', combined_creds)
stub = lnrpc.LightningStub(channel)
return stub
def main():
stub = connect()
uri = os.environ.get("REQUEST_URI")
match = re.search("[?&]r_hash=([0-9a-f]+)(&.*)?$", uri)
if not match:
raise ValueError("No Index")
rhash = match.group(1)
settled = False
timeout = time.time() + 60 # 1 minute timeout
while not settled and time.time() < timeout:
invoice = stub.LookupInvoice(ln.PaymentHash(r_hash_str=rhash))
if invoice.settled:
settled = True
break
time.sleep(1)
print("Content-Type: application/json; charset=UTF-8")
print("")
print('{"settled":%s}' % ("true" if settled else "false"))
debug = False
#debug = True
if debug:
sys.stderr = sys.stdout
try:
main()
except Exception:
import traceback
print("Status: 500 Internal Error")
print("Content-Type: text/html; charset=UTF-8")
print("")
print("<h1>500 Internal Server Error</h1>")
if debug:
print("<pre>")
traceback.print_exc()
print("</pre>")
else:
traceback.print_exc()

60
web/lnd/invoice-mp.py Normal file
View File

@ -0,0 +1,60 @@
import rpc_pb2 as ln
import rpc_pb2_grpc as lnrpc
import grpc
import re
import os
import sys
import codecs
import binascii
def main():
# Due to updated ECDSA generated tls.cert we need to let gprc know that
# we need to use that cipher suite otherwise there will be a handshake
# error when we communicate with the lnd rpc server.
os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA'
with open('/home/lnd/.lnd/tls.cert', 'rb') as f:
cert = f.read()
with open('/home/lnd/.lnd/data/chain/bitcoin/mainnet/invoice.macaroon', 'rb') as f:
macaroon_bytes = f.read()
macaroon = codecs.encode(macaroon_bytes, 'hex')
def metadata_callback(context, callback):
# for more info see grpc docs
callback([('macaroon', macaroon)], None)
# build ssl credentials using the cert the same as before
cert_creds = grpc.ssl_channel_credentials(cert)
# now build meta data credentials
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# combine the cert credentials and the macaroon auth credentials
# such that every call is properly encrypted and authenticated
combined_creds = grpc.composite_channel_credentials(cert_creds, auth_creds)
# finally pass in the combined credentials when creating a channel
channel = grpc.secure_channel('localhost:10009', combined_creds)
stub = lnrpc.LightningStub(channel)
invoice = stub.AddInvoice(ln.Invoice(memo="Donation for Johoe's Mempool"))
print("Content-Type: application/json; charset=UTF-8")
print("")
print('{"r_hash":"%s","payment_request":"%s","add_index":%d}' % (binascii.hexlify(invoice.r_hash),invoice.payment_request,invoice.add_index))
debug = False
#debug = True
if debug:
sys.stderr = sys.stdout
try:
main()
except:
import traceback
print("Status: 500 Internal Error")
print("Content-Type: text/html; charset=UTF-8")
print("")
print("<h1>500 Internal Server Error</h1>")
if debug:
print("<pre>")
traceback.print_exc()
print("</pre>")

73
web/lnd/invoice.py Normal file
View File

@ -0,0 +1,73 @@
#!/usr/bin/python3
import cgi
import os
import sys
import codecs
import binascii
import grpc
import rpc_pb2 as ln
import rpc_pb2_grpc as lnrpc
def connect():
# Due to updated ECDSA generated tls.cert we need to let gprc know that
# we need to use that cipher suite otherwise there will be a handshake
# error when we communicate with the lnd rpc server.
os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA'
with open('/home/lnd/.lnd/tls.cert', 'rb') as f:
cert = f.read()
with open('/home/lnd/.lnd/data/chain/bitcoin/mainnet/invoice.macaroon', 'rb') as f:
macaroon_bytes = f.read()
macaroon = codecs.encode(macaroon_bytes, 'hex')
def metadata_callback(_context, callback):
# for more info see grpc docs
callback([('macaroon', macaroon)], None)
# build ssl credentials using the cert the same as before
cert_creds = grpc.ssl_channel_credentials(cert)
# now build meta data credentials
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# combine the cert credentials and the macaroon auth credentials
# such that every call is properly encrypted and authenticated
combined_creds = grpc.composite_channel_credentials(cert_creds, auth_creds)
# finally pass in the combined credentials when creating a channel
channel = grpc.secure_channel('localhost:10009', combined_creds)
stub = lnrpc.LightningStub(channel)
return stub
def main():
stub = connect()
form = cgi.FieldStorage()
value = int(form["value"].value) if "value" in form.keys() else 0
memo = form["memo"].value if "memo" in form.keys() else ""
invoice = stub.AddInvoice(ln.Invoice(memo=memo, value=value))
print("Content-Type: application/json; charset=UTF-8")
print("")
print('{"r_hash":"%s","payment_request":"%s","add_index":%d}'
% (binascii.hexlify(invoice.r_hash),
invoice.payment_request, invoice.add_index))
debug = False
#debug = True
if debug:
sys.stderr = sys.stdout
try:
main()
except Exception:
import traceback
print("Status: 500 Internal Error")
print("Content-Type: text/html; charset=UTF-8")
print("")
print("<h1>500 Internal Server Error</h1>")
if debug:
print("<pre>")
traceback.print_exc()
print("</pre>")
else:
traceback.print_exc()

BIN
web/queue/dash-32px.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

View File

@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$dbtype = "mysql";
$dbtype = "mysql";
$dbdatabase = "dbname=btc_mempool;host=localhost";
$dbdsn = "$dbtype:$dbdatabase";
$dbuser = "www";
@ -45,20 +45,20 @@ try {
$query = $db->prepare("SELECT * FROM mempool WHERE time >= :start AND time < :end and (time DIV 60) MOD :increment = 0 ORDER BY time");
$query->execute(array(':start' => $start, ':end' => $end, ':increment' => $increment));
header("Content-Type: application/json; charset=UTF-8");
header("Content-Type: application/javascript; charset=UTF-8");
echo 'call([';
$comma="";
while ($row = $query->fetch(PDO::FETCH_NUM)) {
for ($i = 0; $i < 3*$feelevels+1; $i++) {
if (!isset($row[$i])) {
for ($i = 0; $i < 3*$feelevels+1; $i++) {
if (!isset($row[$i])) {
$row[$i] = 0;
}
}
echo $comma.'['.$row[0].',['.
join(',', array_slice($row, 1, $feelevels)).'],['.
join(',', array_slice($row, 1 + $feelevels, $feelevels)).'],['.
join(',', array_slice($row, 1 + 2*$feelevels, $feelevels)).']]';
$comma = ",\n";
}
echo $comma.'['.$row[0].',['.
join(',', array_slice($row, 1, $feelevels)).'],['.
join(',', array_slice($row, 1 + $feelevels, $feelevels)).'],['.
join(',', array_slice($row, 1 + 2*$feelevels, $feelevels)).']]';
$comma = ",\n";
}
echo "]);\n";
exit;

View File

@ -9,13 +9,14 @@
<script src="../flot/jquery.flot.resize.min.js"></script>
<script src="../flot/jquery.flot.selection.min.js"></script>
<script src="../flot/jquery.flot.navigate.min.js"></script>
<script src="mempool.js?v=2.0"></script>
<script src="mempool.js?v=2.0.13"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="Content-Language" content="en"/>
<meta name="author" content="Jochen Hoenicke"/>
<meta name="keywords" content="Jochen Hoenicke, Bitcoin, Mempool, Statistics"/>
<meta name="description" content="Johoe's Bitcoin Mempool Size Statistics"/>
<meta property="og:image" content="https://jochen-hoenicke.de/queue/mempool-20180219.png"/>
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
@ -33,28 +34,42 @@
</script>
<div>
<p>
This page displays the number and size of the unconfirmed bitcoin transactions, also known as the transactions in the <b>mempool</b>. It gives a real-time view and shows how the mempool evolves over the time. The transactions are colored by the amount of fee they pay per byte. The data is generated from my full node and is updated every minute. Note that in bitcoin there is no global mempool; every node keeps its own set of unconfirmed transactions that it has seen. The mempool is also cleared when I reboot my node.
This page displays the number and size of the unconfirmed bitcoin transactions, also known as the transactions in the <b>mempool</b>. It gives a real-time view and shows how the mempool evolves over the time. The transactions are colored by the amount of fee they pay per (virtual) byte. The data is generated from my full node and is updated every minute. Note that in bitcoin there is no global mempool; every node keeps its own set of unconfirmed transactions that it has seen. The mempool is also cleared when I reboot my node.
The idea is based on the retired service bitcoinqueue.com.
</p>
<p>The data is separated into different fee levels given in satoshi per bytes. The lowest colored stripe is for transactions that pay the lowest fee. Higher fee transactions are stacked on top of it. Since miners prefer high fee transactions, a new block usually only removes the top 1 MB from the queue. If a colored stripe persists over several hours without getting smaller, this means that transactions paying this amount of fee are not confirmed during this time, because there are higher paying transactions that take precedence. If a stripe on the bottom chart is much bigger than on the top chart, the transactions are larger than the average.</p>
<p>You can click on some fee level in the legend to hide all fee levels below that level. This way you can better see how many transactions are competing with that fee level.</p>
<p>Note that sizes include the segwit discount. So for the core chain, a block will always take at most 1 MB from the mempool, even if it is bigger than 1&nbsp;MB, because the lower diagram already shows the size minus three quarter of the witness size. The segwit discount is also included when computing the fee level for a transaction. In case a transaction pays exactly the fee that defines the boundary between stripes, it is included in the higher stripe. Free transactions are not included, even if they make it into the mempool.</p>
<p>Note that sizes include the segwit discount, i.e., the graphs show virtual byte (weight divided by four). For segwit transactions, the real size of the transaction is a bit larger than the virtual size. So for the BTC and LTC chains, a block will always take at most 1 MB from the mempool, even if it is bigger than 1&nbsp;MB, because the lower diagram already shows the size in vbyte (with the segwit discount included). The segwit discount is also included when computing the fee level for a transaction. In case a transaction pays exactly the fee that defines the boundary between stripes, it is included in the higher stripe. Free transactions are not included, even if they make it into the mempool.</p>
</div>
<h2>Donation Addresses</h2>
<div class="centered">
<a href="bitcoin:3LrXizKejCGYyGUxYzGweyuxFVtfs3odEe"><div class="qrcontainer"><span class="cover pixelated qrcode" style="width:148px; height:148px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACUAAAAlAQMAAAD/ULJAAAAABlBMVEX///8AAABVwtN+AAAA1ElEQVQI12NABvZ9c84/YFCYX8qhwKC3YKH3Aga9nnurgeT+/NMLGBRWfNVQYLBftWr9AwYG5soFDAxCG122NTAoiTg4MDAIXzC64sCgYVMZ4MDAfOr1ewcG7jRTFwcGi69TTh9g0KuJz1FgEPtYOesBg25mLesCBoujv7wdGIwz9FkYGPhW2Pc5MJiKfos9wMDRtdnpAAOnYbSVAoPFPfX9QKPVZJIaGOwnKmsdYFDo+rvIgUFvl9k+oAubJLWBJjcuWtTAoLDz8ASg+7vffVNA9hAAKhdEcnLvcTYAAAAASUVORK5CYII=);"></span><img class="qrlogo" src="bc-logo-32x32.png" alt=""/></div></a>
<a href="bitcoincash:qqc0a3s49uzj329rju4v27erlc6kx5paqs6t5l70n6"><div class="qrcontainer"><span class="cover pixelated qrcode" style="width:148px; height:148px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACUAAAAlAQMAAAD/ULJAAAAABlBMVEX///8AAABVwtN+AAAA00lEQVQI12NABvYTMvsfMChsuHZCgUGv6/7qBQx6+xSygeSe00BSodsKKG6/atX6BwwMKt8cGBjEF/NJOzAwemu0MTCwPIzNd2Aw95l0ZgED6zbpiQ8YFEOPuiswcJ06qOzAYM+d+3cBA9Mds5MLGHiNT9YqMOj8EytKYOBg2xm1gEH7y/T6BgYTg0k3GBhU9xf6LWDQYRTkfsBgtivU7gADg57QogUM9tOfr3JgUFi/SgkosDS9PoFBb/cinQMMejN3PwG6ea2jJtCWvpftB5A9BAB0VkYyusTI4gAAAABJRU5ErkJggg==);"></span><img class="qrlogo" src="bch-logo-30.png" alt=""/></div></a>
<a href="litecoin:MK7jfGG48RTsETCXTAz1wP27uVoFhBUV5o"><div class="qrcontainer"><span class="cover pixelated qrcode" style="width:148px; height:148px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACUAAAAlAQMAAAD/ULJAAAAABlBMVEX///8AAABVwtN+AAAA00lEQVQI12NABvb7a/sfMCjsy16hwKA3pTV7AYNejzaInKvMvYBBYbpqhwKD/apV6x8wMMgcc2BgEPir/iGBQYDl6rEEBraHExkPMIjbWzk3MGjMvF7lwGAlJRG7gEFludWuAwyceTnuCxiMWv3bHjAIWXfVHmCQvbTs5gIGdT6Z/AcMvHM6DzEw2HjfEWtg0H2k1HmAQS1sU+cDBrM5Mf+A1qifWtzAYL9l5uoDDAqNTMlA90x8vs+BQW/al09Ad7bul05gUNjyLQyoppOr1gHZQwBzTUeVN9V6gwAAAABJRU5ErkJggg==);"></span><img class="qrlogo" src="ltc-32px.png" alt=""/></div></a>
<p>Donation
bitcoin:<a href="bitcoin:3LrXizKejCGYyGUxYzGweyuxFVtfs3odEe">3LrXizKejCGYyGUxYzGweyuxFVtfs3odEe</a> (Segwit)<br/>
<a href="bitcoincash:qqc0a3s49uzj329rju4v27erlc6kx5paqs6t5l70n6">bitcoincash:qqc0a3s49uzj329rju4v27erlc6kx5paqs6t5l70n6</a><br/>
litecoin:<a href="litecoin:MK7jfGG48RTsETCXTAz1wP27uVoFhBUV5o">MK7jfGG48RTsETCXTAz1wP27uVoFhBUV5o</a><br/>
ethereum: <span class="cover pixelated" style="width: 20px;height:20px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAgMAAAC5YVYYAAAACVBMVEWV5Xgyfg0qispl6+N0AAAAH0lEQVQI12NwYGRwdGQIDWVQkWBwEWSYwMagNgMoAgAqGwPVVzuqWQAAAABJRU5ErkJggg==); border-radius: 50%; display: inline-block;"></span>&nbsp;mempool.hoenicke.eth</p>
<div class="donation">
<a href="bitcoin:bc1qm9hxngjd6hj44yn73p26f5k854u98krsm0fn5n"><div class="qrcontainer"><img class="cover pixelated qrcode" width="148" height="148" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACUAAAAlAQMAAAD/ULJAAAAABlBMVEX///8AAABVwtN+AAAA0ElEQVQI12NABvaTf71/wKDQ/7FDgUFvu3z3Aga9HY+ygeSKCCBbYVk2hwKD/apV6x8wMKh4Agn9xuT1DQyiUb0yCQwctzLFGxhEghYbL2AwvuXZ6MCgofpJcgGDzrW5ugcYLKTXZwLFZ+yd1sBgFyjc2MBgdDug4wCDeb6t+QIGzqalTQ4MFiEnZBQYNJY9ZHRgUA7yzwDqXXP3P9BZSo+SHjDYN716zQB0g7sy0D17O+wYGPR2J11LYNBb07SggUGhYbVWA4P9goWPHZA9BABn6UepgMPvWQAAAABJRU5ErkJggg==" alt=""/><img class="qrlogo" src="bc-logo-32x32.png" alt=""/></div></a><a href="#" onClick="window.open('../lightning/','ln','resizeable,height=600,width=500'); return false;"><img class="bolt" src="../lightning/lightning-bolt.png" alt="lightning" /></a><br />
bitcoin:<a href="bitcoin:bc1qm9hxngjd6hj44yn73p26f5k854u98krsm0fn5n">bc1qm9hxngjd6hj44yn73p26f5k854u98krsm0fn5n</a><br/>
(old bitcoin:<a href="bitcoin:3KwNxt5tX2U6riFjGNBa3ZXshzYyAUeGJ7">3KwNxt5tX2U6riFjGNBa3ZXshzYyAUeGJ7</a>)
</div>
<div class="donation">
<a href="bitcoincash:qzpg8k2j84pwdtuf7ll4kuszw6d5g3p9xcgk704qzg"><div class="qrcontainer"><img class="cover pixelated qrcode" width="148" height="148" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJQAAACUAQMAAABP8pKXAAAABlBMVEX///8AAABVwtN+AAABAElEQVRIx83V0Q2DQAwDUG/g/bf0Bq5j1C5gPhpO1+QhkVSHBP4+bAuyRLDFaEKEuQArxWzJ2FbJVZ7tQHjNkvJ2vmK3iNYtNuux/CLFajiXyW81Worn4WVzNUPpQTQorAbRUTJOO7pZ8qwUUH7g2Z6hnUgWGk3BGEjiJtZohIJUyrtpjAaTyPqKVuuY/fu8fLTkPO8reRtWA7OMp4Go0Ujf1fcyZoyWXSSNGHpvsxAcSoPniEaLBCBF23A1kd2SJryarUi/Ak5ObNa4ilCHXi2lojDYbqsdyORVyjWbFVPQTL93DExmMvyGJZehZ/bVjp9ReaNjtJ5Rn93ck/19fADSM8pBJzawzQAAAABJRU5ErkJggg==" alt=""/><img class="qrlogo" src="bch-logo-30.png" alt=""/></div></a><br/>
<a href="bitcoincash:qzpg8k2j84pwdtuf7ll4kuszw6d5g3p9xcgk704qzg">bitcoincash:qzpg8k2j84pwdtuf7ll4kuszw6d5g3p9xcgk704qzg</a><br/>
(old bitcoincash:<a href="bitcoincash:1Cu6nxjUgACKweizhfRAdrAqJH4ugSW9JP">1Cu6nxjUgACKweizhfRAdrAqJH4ugSW9JP</a>)
</div>
<div class="donation">
<a href="litecoin:ltc1qp2qsuh73rrj8gxpvw65ck554qfnv8s5pke3qzm"><div class="qrcontainer"><img class="cover pixelated qrcode" width="148" height="148" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACUAAAAlAQMAAAD/ULJAAAAABlBMVEX///8AAABVwtN+AAAA1ElEQVQI12NABvZTW9Y/YFDojj2hwKA3vWv1Aga9Za9OA8nJ+14vYFDY9LlDgcF+1SqgGgY1DwcGBom2u7oMDLLxCVkPGASe2O9OYBDOWnNTgcH22v32BwxmjtKvHjCIvZiV94BBqVB8IQOD9J0bmxkYFIVL9Q8wyK2LE0xgEKlbH/aAgeu0pOMCBkbWB4wJDGY/dGoeMDAnGgYpMJjfELU/wMBg8OnxAaDbQlc1MChM+LcI6La50f8aGPQaTy08wKC3taof6ObFYl1At034mJuA7CEA8yNLCukmy7UAAAAASUVORK5CYII=" alt=""/><img class="qrlogo" src="ltc-32px.png" alt=""/></div></a><br />
litecoin:<a href="litecoin:ltc1qp2qsuh73rrj8gxpvw65ck554qfnv8s5pke3qzm">ltc1qp2qsuh73rrj8gxpvw65ck554qfnv8s5pke3qzm</a><br/>
(old litecoin:<a href="litecoin:MK7jfGG48RTsETCXTAz1wP27uVoFhBUV5o">MK7jfGG48RTsETCXTAz1wP27uVoFhBUV5o</a>)
</div>
<div class="donation">
<a href="dash:XhvBxZ5WiTK7K8js4uphXCP5QjFQMogAMk"><div class="qrcontainer"><img class="cover pixelated qrcode" width="148" height="148" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACUAAAAlAQMAAAD/ULJAAAAABlBMVEX///8AAABVwtN+AAAA0UlEQVQI12NABvZr1c4/YFBYap6hwKC3bJn3Aga9raKngeRKxu4FDAp9N4Hi9qtWrX/AwKBavICBQepcCPcDBmXFUy8ZGERPbWJ+wGCfq/jPgYF1paolA4NYylXDBwzq/RPkgOIBsjYODPzPZ0U8YBA3KRJMYNBZUb07gUE2t3eeA4Pw3WP/FBjYOb4pJjBod17vT2CQ5yn+ocCg+bH3P9Au4wWLFzDY72vUArptBocyA4Pemhr7BAa9GaqOQHKtoxjQbWu2XndgsJ+yqDIB2UMAFahFDpSQnIQAAAAASUVORK5CYII=" alt=""/><img class="qrlogo" src="dash-32px.png" alt=""/></div></a><br />
dash:<a href="dash:XhvBxZ5WiTK7K8js4uphXCP5QjFQMogAMk">XhvBxZ5WiTK7K8js4uphXCP5QjFQMogAMk</a><br/>&nbsp;
</div>
<p>
ethereum: <span class="cover pixelated" style="width: 20px;height:20px; background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAgMAAAC5YVYYAAAACVBMVEWV5Xgyfg0qispl6+N0AAAAH0lEQVQI12NwYGRwdGQIDWVQkWBwEWSYwMagNgMoAgAqGwPVVzuqWQAAAABJRU5ErkJggg==); border-radius: 50%; display: inline-block;"></span>&nbsp;mempool.hoenicke.eth</p>
</div>
<div class="centered" style="font-size: 13px; margin: 20px;">
Source code on github: <a href="https://github.com/jhoenicke/mempool">https://github.com/jhoenicke/mempool</a><br/>
© 2016-2018 <a href="https://jochen-hoenicke.de/">Jochen Hoenicke</a>
Source code on github: <a href="https://github.com/jhoenicke/mempool">https://github.com/jhoenicke/mempool</a><br/>
© 2016-2019 <a href="https://jochen-hoenicke.de/">Jochen Hoenicke</a>
</div>
</html>

View File

@ -19,26 +19,31 @@
var charts;
var config = [
{"name":"BTC",
"url":"https://dedi.jochen-hoenicke.de/queue/",
"title":"Bitcoin Core 0.18.1. Huge mempool limit and no timeout, to prevent any transactions to be dropped.",
/*
"url":"https://jochen-hoenicke.de/queue/",
"symbol":"BTC",
"satPerUnit": 100000000.0,
"ranges": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 17, 20, 25, 30, 40, 50, 60, 70, 80, 100, 120, 140, 170, 200, 250, 300, 400, 500, 600, 700, 800, 1000, 1200, 1400, 1700, 2000, 2500, 3000, 4000, 5000, 6000, 7000, 8000, 10000 ],
"show": [ 0, 1, 2, 5, 9, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37 ],
"colors": [ "#535154", "#001080", "#349dac", "#a21010", "#7e5e82",
"#84b200", "#a0d0cd", "#c7b52e", "#6cbbea", "#514f4c",
"#4e7fbb", "#9f63a0", "#f69445", "#349dac", "#c7b52e",
"#c14540", "#7e2e82", "#514f4c", "#54b200", "#1e7fbb",
"#f67405", "#60e0cd", "#e12000", "#123456", "#fe3dba",
"#349d00", "#bd00ed", "#001080"],
"inc": true},
{"name":"BTC (more stripes)",
"url":"https://dedi.jochen-hoenicke.de/queue/",
"feelevel": 1,
"ranges": [ 0,1,2,5,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,220,240,260,280,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000,1400,2000,3000,5000,7000,10000 ],
"show": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 17, 18, 20, 23, 25, 27, 29, 31 ],
"colors": [
"#535154", "#0000ac", "#0000ff", "#8080ff",
"#00c000", "#00e000", "#90e090",
"#808000", "#989800", "#b0b000", "#c8c800", "#e0e000", "#e0e030", "#e0e060",
"#800000", "#a00000", "#c00000", "#e00000", "#e02020", "#e04040", "#e06060",
"#800080", "#000000",
],
"inc": false},
*/
"url":"https://johoe.jochen-hoenicke.de/queue/",
"symbol":"BTC",
"satPerUnit": 100000000.0,
"feelevel": 1,
"ranges": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 17, 20, 25, 30, 40, 50, 60, 70, 80, 100, 120, 140, 170, 200, 250, 300, 400, 500, 600, 700, 800, 1000, 1200, 1400, 1700, 2000, 2500, 3000, 4000, 5000, 6000, 7000, 8000, 10000 ],
"show": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37 ],
"colors": [
"#000080", "#0000ac", "#0000c2", "#0000d8", "#0000ec", "#0000ff", "#2c2cff", "#5858ff", "#8080ff",
"#535154", "#0000ac", "#0000c2", "#0000d8", "#0000ec", "#0000ff", "#2c2cff", "#5858ff", "#8080ff",
"#008000", "#00a000", "#00c000", "#00e000", "#30e030", "#60e060", "#90e090",
"#808000", "#989800", "#b0b000", "#c8c800", "#e0e000", "#e0e030", "#e0e060",
"#800000", "#a00000", "#c00000", "#e00000", "#e02020", "#e04040", "#e06060",
@ -47,45 +52,110 @@ var config = [
],
"inc": true},
{"name":"BTC (default mempool)",
"title":"Bitcoin Core with default mempool settings (300 MB + 14 days timeout).",
"url":"https://core.jochen-hoenicke.de/queue/",
"symbol":"BTC",
"satPerUnit": 100000000.0,
"ranges": [ 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000 ],
"show": [ 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31, 35 ],
"colors": [ "#349dac", "#a21010", "#7e5e82", "#84b200", "#a0d0cd",
"#c7b52e", "#6cbbea", "#514f4c", "#4e7fbb", "#9f63a0",
"#f69445", "#349dac", "#c7b52e", "#514f4c", "#c14540",
"#7e2e82", "#54b200", "#1e7fbb", "#f67405", "#60e0cd",
"#e12000", "#123456", "#fe3dba", "#349d00", "#bd00ed",
"#001080", "#ffff00", "#20c020", "#0000c0" ],
"inc": false},
"feelevel": 0,
"ranges": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 17, 20, 25, 30, 40, 50, 60, 70, 80, 100, 120, 140, 170, 200, 250, 300, 400, 500, 600, 700, 800, 1000, 1200, 1400, 1700, 2000, 2500, 3000, 4000, 5000, 6000, 7000, 8000, 10000 ],
"show": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37 ],
"colors": [
"#535154", "#0000ac", "#0000c2", "#0000d8", "#0000ec", "#0000ff", "#2c2cff", "#5858ff", "#8080ff",
"#008000", "#00a000", "#00c000", "#00e000", "#30e030", "#60e060", "#90e090",
"#808000", "#989800", "#b0b000", "#c8c800", "#e0e000", "#e0e030", "#e0e060",
"#800000", "#a00000", "#c00000", "#e00000", "#e02020", "#e04040", "#e06060",
"#800080", "#ac00ac", "#d800d8", "#ff00ff", "#ff2cff", "#ff58ff", "#ff80ff",
"#000000"
],
"inc": true},
{"name":"BCH",
"url":"https://jochen-hoenicke.de/queue/cash/",
"title":"Bitcoin Cash - BCHN 0.21.0.",
"url":"https://johoe.jochen-hoenicke.de/queue/cash/",
"symbol":"BCH",
"satPerUnit": 100000000.0,
"ranges": [ 0, 5, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 120, 140, 160, 180, 200, 220, 240, 260, 280, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000 ],
"show": [ 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,22,23,24, 25, 26,27 ],
"colors": [ "#349dac", "#a21010", "#7e5e82", "#84b200", "#a0d0cd",
"#c7b52e", "#6cbbea", "#514f4c", "#4e7fbb", "#9f63a0",
"#f69445", "#349dac", "#c7b52e", "#514f4c", "#c14540",
"#7e2e82", "#54b200", "#1e7fbb", "#f67405", "#60e0cd",
"#e12000", "#123456", "#fe3dba", "#349d00", "#bd00ed",
"#001080"],
"inc": false},
"feelevel": 1,
"ranges": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 17, 20, 25, 30, 40, 50, 60, 70, 80, 100, 120, 140, 170, 200, 250, 300, 400, 500, 600, 700, 800, 1000, 1200, 1400, 1700, 2000, 2500, 3000, 4000, 5000, 6000, 7000, 8000, 10000 ],
"show": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21,22,23,24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 ],
"colors": [
"#535154", "#400080", "#5600ac", "#6100c2", "#6c00d8", "#7600ec", "#7f00ff", "#9020ff",
"#c040ff", "#0000ac", "#0000c2", "#0000d8", "#0000ec", "#0000ff", "#2c2cff", "#5858ff", "#8080ff",
"#008000", "#00a000", "#00c000", "#00e000", "#30e030", "#60e060", "#90e090",
"#808000", "#989800", "#b0b000", "#c8c800", "#e0e000", "#e0e030", "#e0e060",
// "#800000", "#a00000", "#c00000", "#e00000", "#e02020", //"#e04040", "#e06060",
// "#800080", "#ac00ac", "#d800d8", "#ff00ff", "#ff2cff", "#ff58ff", "#ff80ff",
"#000000" ],
"inc": true},
{"name":"BSV",
"title":"Bitcoin SV 1.0.3",
"url":"https://sv.jochen-hoenicke.de/queuesv/",
"symbol":"BSV",
"satPerUnit": 100000000.0,
"feelevel": 0,
"ranges": [ 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1, 1.2, 1.4, 1.7, 2, 2.5, 3, 4, 5, 6, 7, 8, 10, 12, 14, 17, 20, 25, 30, 40, 50, 60, 70, 80, 100, 120, 140, 170, 200, 250, 300, 400, 500, 600, 700, 800, 1000 ],
"show": [ 0, 1, 2, 3, 4, 5, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,22,23,24, 25, 27, 29, 31, 33, 35, 37 ],
"colors": [
"#535154", "#0000ac", "#0000c2", "#0000d8", "#0000ec", "#0000ff", "#2c2cff", "#5858ff", "#8080ff",
"#008000", "#00a000", "#00c000", "#00e000", "#30e030", "#60e060", "#90e090",
"#808000", "#989800", "#b0b000", "#c8c800", "#e0e000", "#e0e030", "#e0e060",
"#800000", "#a00000", "#c00000", "#e00000", "#e02020", "#e04040", //"#e06060",
//"#800080", "#ac00ac", "#d800d8", "#ff00ff", "#ff2cff", "#ff58ff", "#ff80ff",
"#000000"
],
"inc": true},
{"name":"LTC",
"url":"https://dedi.jochen-hoenicke.de/queue/litecoin/",
"title":"Litecoin Core with higher memory limit.",
"url":"https://johoe.jochen-hoenicke.de/queue/litecoin/",
"symbol":"LTC",
"satPerUnit": 100000000.0,
"feelevel": 1,
"ranges": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 17, 20, 25, 30,40, 50, 60, 70, 80,100, 120, 140, 170, 200, 250, 300, 400, 500, 600, 700, 800, 1000, 1200, 1400, 2000, 3000, 5000, 7000, 10000 ],
"show": [ 0, 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40],
"colors": [ "#535154", "#001080", /*"#349d00",*/ "#349dac",
/*"#bd00ed",*/ "#a21010", "#7e5e82", /*"#fe3dba",*/
"#84b200", "#a0d0cd",
"#c7b52e", "#6cbbea", "#514f4c", "#4e7fbb", "#9f63a0",
"#f69445", "#349dac", "#c7b52e", "#c14540",
"#7e2e82", "#54b200", "#1e7fbb", "#f67405", "#514f4c", "#60e0cd",
"#e12000", "#123456", "#fe3dba", "#349d00", "#bd00ed",
"#001080"],
"show": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 ],
"colors": [
"#535154", "#400080", "#5600ac", "#6100c2", "#6c00d8", "#7600ec", "#7f00ff", "#9020ff",
"#c040ff", "#0000ac", "#0000c2", "#0000d8", "#0000ec", "#0000ff", "#2c2cff", "#5858ff", "#8080ff",
"#008000", "#00a000", "#00c000", "#00e000", "#30e030", "#60e060", "#90e090",
"#808000", "#989800", "#b0b000", "#c8c800", "#e0e000", "#e0e030", "#e0e060",
"#800000", "#a00000", "#c00000", "#e00000", "#e02020", //"#e04040", "#e06060",
// "#800080", "#ac00ac", "#d800d8", "#ff00ff", "#ff2cff", "#ff58ff", "#ff80ff",
"#000000"
],
"inc": true},
/*
{"name":"LTC",
"title":"Litecoin Core",
"url":"https://jochen-hoenicke.de/queue/litecoin/",
"symbol":"LTC",
"satPerUnit": 100000000.0,
"feelevel": 0,
"ranges": [ 0, 5,10,20,30,40,50,60,70,80,90,100,120,140,160,180,200,220,240,260,280,300,350,400,450,500,550,600,650,700,750,800,850,900,950,1000 ],
"show": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 ],
"colors": [
"#535154", "#400080", "#5600ac", "#6100c2", "#6c00d8", "#7600ec", "#7f00ff", "#9020ff",
"#c040ff", "#0000ac", "#0000c2", "#0000d8", "#0000ec", "#0000ff", "#2c2cff", "#5858ff", "#8080ff",
"#008000", "#00a000", "#00c000", "#00e000", "#30e030", "#60e060", "#90e090",
"#808000", "#989800", "#b0b000", "#c8c800", "#e0e000", "#e0e030", "#e0e060",
//"#800000", "#a00000", "#c00000", "#e00000", "#e02020", //"#e04040", "#e06060",
// "#800080", "#ac00ac", "#d800d8", "#ff00ff", "#ff2cff", "#ff58ff", "#ff80ff",
"#000000"
],
"inc": false},
*/
{"name":"DASH",
"title":"Dash Core v0.15.0.0 with default memory limit",
"url":"https://johoe.jochen-hoenicke.de/queue/dash/",
"symbol":"DASH",
"satPerUnit": 100000000.0,
"feelevel": 1,
"ranges": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 17, 20, 25, 30, 40, 50, 60, 70, 80, 100, 120, 140, 170, 200, 250, 300, 400, 500, 600, 700, 800, 1000, 1200, 1400, 1700, 2000, 2500, 3000, 4000, 5000, 6000, 7000, 8000, 10000 ],
"show": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37 ],
"colors": [
"#535154", "#0000ac", "#0000c2", "#0000d8", "#0000ec", "#0000ff", "#2c2cff", "#5858ff", "#8080ff",
"#008000", "#00a000", "#00c000", "#00e000", "#30e030", "#60e060", "#90e090",
"#808000", "#989800", "#b0b000", "#c8c800", "#e0e000", "#e0e030", "#e0e060",
"#800000", "#a00000", "#c00000", "#e00000", "#e02020", "#e04040", "#e06060",
"#800080", "#ac00ac", "#d800d8", "#ff00ff", "#ff2cff", "#ff58ff", "#ff80ff",
"#000000"
],
"inc": true}
];
var periods = ["2h", "8h", "24h", "2d", "4d", "1w", "2w", "30d", "3m", "6m", "1y", "all"];
@ -268,7 +338,7 @@ function addData(raw, dataidx, unit) {
}
}
var amount = 0;
for (k = show[j]; k < (j == show.length ? ranges.length : show[j + 1]); k++) {
for (k = show[j]; k < (j == show.length - 1 ? config[currconfig].ranges.length : show[j + 1]); k++) {
amount = amount + get(raw[i][dataidx+1],k);
}
data[dataidx][j].push([raw[i][0]*1000, amount/unit]);
@ -391,10 +461,12 @@ function zoomData(rawdata) {
var oldconfig;
function loadData(rawdata) {
if (!charts) {
feelevel = config[currconfig].feelevel;
showMempool(rawdata);
oldconfig = currconfig;
} else {
if (currconfig != oldconfig) {
feelevel = config[currconfig].feelevel;
for (var i = 0; i < 3; i++) {
charts[i].setData(convertData(rawdata, i, scale(i)));
}
@ -474,7 +546,7 @@ function button(timespan) {
}
function main() {
var hashconfig = 1;
var hashconfig = 0;
var hashtimespan = "24h";
if (location.hash.length > 0) {
var args = location.hash.substring(1).split(",");
@ -488,16 +560,20 @@ function main() {
var divconfig = document.getElementById("configs");
for (var i = 0; i < config.length; i++) {
var name = config[i].name;
var title = config[i].title;
var btn = document.createElement("a");
btn.text = name;
btn.href = "#";
if (title) {
btn.title = title;
}
(function() {
var cfg = i;
btn.onclick = function(e) { setconfig(cfg); button(currtimespan); }
})();
btn.className = "lnk";
btn.id = "cfg"+i;
divconfig.append(btn);
divconfig.appendChild(document.createTextNode("\u200b"));
divconfig.appendChild(btn);
}
var div = document.getElementById("periods");
var onclickfun = function(e) { button(e.target.text); };
@ -505,11 +581,11 @@ function main() {
var name = periods[i];
var btn = document.createElement("a");
btn.text = name;
btn.href = "#";
btn.onclick = onclickfun;
btn.className = "lnk";
btn.id = "lk"+name;
div.append(btn);
div.appendChild(document.createTextNode("\u200b"));
div.appendChild(btn);
}
setconfig(hashconfig);
button(hashtimespan);

View File

@ -8,13 +8,14 @@ a {
}
.lnk {
margin: 1px;
text-size: 14px;
font-size: 14px;
text-decoration: none;
border: 1px solid #888;
padding-top: 1px;
padding-bottom: 1px;
padding-left: 3px;
padding-right: 3px;
cursor: pointer;
}
.selected {
color: #000;
@ -71,6 +72,11 @@ div.button {
background-size: cover;
background-repeat: no-repeat;
}
.donation {
display: inline-block;
position: relative;
margin: 1ex 1em;
}
.qrcontainer {
display: inline-block;
position: relative;
@ -85,3 +91,7 @@ div.button {
left: 50%;
transform: translate(-50%, -50%);
}
.bolt {
margin-bottom: 2ex;
}