Skip to content

Commit

Permalink
Removing use of tx-confirmation websockets
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthieu Riou committed Jun 7, 2018
1 parent cb2fa86 commit 3698979
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 132 deletions.
66 changes: 0 additions & 66 deletions templates/address_overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,72 +317,6 @@ <h2>Wallet Addresses</h2>

$("time.timeago").timeago();

var total_ws_received = 0;
var MAX_WS_TO_RECEIVE = 1000;

{% if not is_wallet_page and not before_bh and num_unconfirmed_txns < 10 %}

function create_ws() {
console.log('Creating new websocket...');
ws = new WebSocket('{{ coin_symbol|coin_symbol_to_wss }}');
}

create_ws();

function send_ping() {
// Send pings at regular interval:
if (total_ws_received < MAX_WS_TO_RECEIVE) {
console.log('Sending websocket ping...');
ws.send(JSON.stringify({event: "ping"}));
// Trigger self recursively
setTimeout(send_ping, 20000);
} else {
console.log('Not sending ping because MAX_WS_TO_RECEIVE reached');
}
}

ws.onmessage = function(evt) {

var data = JSON.parse(evt.data);
console.log('Websocket Received: ' + evt.data);

// Weak protection against too much activity
total_ws_received += 1;
if (total_ws_received > MAX_WS_TO_RECEIVE) {
ws.close();
}

if ( data.hasOwnProperty('hash') ) {
if (data['confirmations'] <= 6 ) {
// Update data in the view
location.reload();
}
}
}

ws.onopen = function() {
console.log('Connection established.');
ws.send(JSON.stringify(
{
'address': "{% if is_wallet_page %}{{ bc_wallet_name }}{% else %}{{address }}{% endif %}",
'event': 'tx-confirmation',
'token': '{{ BLOCKCYPHER_PUBLIC_KEY }}',
}
));
send_ping();
};

ws.onclose = function() {
console.log('Connection closed');
if (total_ws_received < MAX_WS_TO_RECEIVE) {
console.log('Creating new websocket to replace old one...');
create_ws();
}

};

{% endif %}

if (window.location.hash == '#advanced-details') {
$('#advanced-details').collapse('show');
}
Expand Down
66 changes: 0 additions & 66 deletions templates/transaction_overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -365,72 +365,6 @@ <h3>Details</h3>

$("time.timeago").timeago();

var total_ws_received = 0;
var MAX_WS_TO_RECEIVE = 1000;

function create_ws() {
console.log('Creating new websocket...');
ws = new WebSocket('{{ coin_symbol|coin_symbol_to_wss }}');
}

create_ws();

function send_ping() {
// Send pings at regular interval:
if (total_ws_received < MAX_WS_TO_RECEIVE) {
console.log('Sending websocket ping...');
ws.send(JSON.stringify({event: "ping"}));
// Trigger self recursively
setTimeout(send_ping, 20000);
} else {
console.log('Not sending ping because MAX_WS_TO_RECEIVE reached');
}
}

ws.onmessage = function(evt) {

var data = JSON.parse(evt.data);
console.log('Websocket Received: ' + evt.data);

// Weak protection against too much activity
total_ws_received += 1;
if (total_ws_received > MAX_WS_TO_RECEIVE) {
ws.close();
}

if ( data.hasOwnProperty('hash') ) {

{# TODO: duplicate all logic in JS #}
location.reload();


}

}

ws.onopen = function() {
console.log('Connection established.');
ws.send(JSON.stringify(
{
'hash': "{{ tx_hash }}",
'event': 'tx-confirmation',
{# UGLY HACK #}
'address': "{{ outputs.0.addresses.0 }}",
'token': '{{ BLOCKCYPHER_PUBLIC_KEY }}',
}
));
send_ping();
};

ws.onclose = function() {
console.log('Connection closed');
if (total_ws_received < MAX_WS_TO_RECEIVE) {
console.log('Creating new websocket to replace old one...');
create_ws();
}

};

{% if transaction.confirmations == 0 and transaction.double_spend == False %}
poll_confidence()
{% endif %}
Expand Down

0 comments on commit 3698979

Please sign in to comment.