Skip to content

Commit

Permalink
improved spam log
Browse files Browse the repository at this point in the history
  • Loading branch information
vuapo-eth committed Nov 9, 2017
1 parent e8b4902 commit 5306bcd
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
1 change: 0 additions & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ header #header_text p {
#content #log span.important {
color: #00FF88;
font-weight: bold;
text-decoration: underline;
}

#content .statbox {
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ <h1>Your Login Data</h1>
<hr/>

<h3>Spamming Log:</h3>
<div id="log" spellcheck="false" readonly></div>
<div id="log"></div>

<!--
<hr/>
Expand Down
15 changes: 12 additions & 3 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var txmsg;
const significantFigures = 3
var startMilliseconds = Date.now();

var state = "", log = "";

function millisecondsToHHMMSSms(milliseconds) {
var sec_num = parseInt(`${milliseconds / 1000}`, 10); // don't forget the second param
var hours = Math.floor(sec_num / 3600);
Expand All @@ -31,9 +33,16 @@ $(function(){
message: txmsg
})

eventEmitter.on('state', function(state) {
//console.log(`${new Date().toISOString()} New state: ${state}`)
$('#log').html(formatDate(new Date()) + ": " + state + "<br/>" + $('#log').html());
eventEmitter.on('state', function(msg) {
state = formatDate(new Date()) + ": " + msg;
$('#log').html("Current state: " + state + "<br/><br/>" + log);
})

eventEmitter.on('log', function(msg) {
var entry = formatDate(new Date()) + ": " + msg + "<br/>";
console.log(entry);
log = entry + log;
$('#log').html("Current state: " + state + "<br/><br/>" + log);
})

eventEmitter.on('transactionCountChanged', function(transactionCount) {
Expand Down
16 changes: 9 additions & 7 deletions js/spammer.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ var iotaTransactionSpammer = (function(){
eventEmitter.emitEvent('state', [`Creating transaction`])
iota.api.sendTransfer(spamSeed, generateDepth(), weight, transfers, function(error, success){
if (error) {
eventEmitter.emitEvent('state', ['<span class="warning">Error occurred while sending transactions</span>']);
eventEmitter.emitEvent('log', ['<span class="warning">Error occurred while sending transactions</span>']);
setTimeout(changeProviderAndSync, 1000);
return;
}
Expand All @@ -203,7 +203,7 @@ var iotaTransactionSpammer = (function(){
confirmationCount += localConfirmationCount
averageConfirmationDuration = (oldTotalConfirmationDuration + transactionDuration) / confirmationCount

eventEmitter.emitEvent('state', ['<span class="important">Transaction created:</span> '+success[0].hash]);
eventEmitter.emitEvent('log', ['<span class="important">Transaction created:</span> '+success[0].hash]);
eventEmitter.emitEvent('transactionCountChanged', [transactionCount]);

eventEmitter.emitEvent('transactionCompleted', [success]);
Expand All @@ -230,7 +230,7 @@ var iotaTransactionSpammer = (function(){

iota.api.getNodeInfo(function(error, success){
if(error) {
eventEmitter.emitEvent('state', ['<span class="warning">Error occurred while checking if node is synced</span>']);
eventEmitter.emitEvent('log', ['<span class="warning">Error occurred while checking if node is synced</span>']);
setTimeout(changeProviderAndSync, 1000);
return;
}
Expand All @@ -247,7 +247,7 @@ var iotaTransactionSpammer = (function(){
sendMessages()
} else {
const secondsBeforeChecking = 3
eventEmitter.emitEvent('state', [`<span class="warning">Node is not synced. Wait ${secondsBeforeChecking}s.</span>`])
eventEmitter.emitEvent('log', [`<span class="warning">Node is not synced. Wait ${secondsBeforeChecking}s.</span>`])
setTimeout(function(){
changeProviderAndSync() // Sometimes the node stays unsynced for a long time, so change provider
}, secondsBeforeChecking * 1000)
Expand All @@ -260,8 +260,10 @@ var iotaTransactionSpammer = (function(){
validProviders = getValidProviders();
currentProvider = getRandomProvider();

eventEmitter.emitEvent('log', [`<span class="important">New node:</span> ${currentProvider}</span>`])

if(currentProvider == null) {
eventEmitter.emitEvent('state', [`<span class="warning">Node list emptry. Check again in 5s.</span>`])
eventEmitter.emitEvent('log', [`<span class="warning">Node list emptry. Check again in 5s.</span>`])
return setTimeout(restartSpamming, 5000);
} else {
initializeIOTA()
Expand Down Expand Up @@ -295,13 +297,13 @@ var iotaTransactionSpammer = (function(){
if(started) { return }
started = true;
transactionCount = 0;
eventEmitter.emitEvent('state', ['<span class="important">Start transaction spamming</span><br/>']);
eventEmitter.emitEvent('log', ['<span class="important">Start spamming</span><br/>']);
restartSpamming();
},
stopSpamming: function() {
started = false;
stopSpammer = true;
eventEmitter.emitEvent('state', ['<span class="important">Stop transaction spamming</span>']);
eventEmitter.emitEvent('log', ['<span class="important">Stop spamming</span>']);
},
eventEmitter: eventEmitter,
getTransactionCount: () => transactionCount,
Expand Down

0 comments on commit 5306bcd

Please sign in to comment.