-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from harpagon210/resources-managment
adding replay from blocks.log file
- Loading branch information
Showing
5 changed files
with
210 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ examples | |
data | ||
test/data | ||
*.key | ||
*.cert | ||
*.cert | ||
blocks.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const fs = require('fs'); | ||
const readline = require('readline'); | ||
const stream = require('stream'); | ||
|
||
class Replay { | ||
constructor(type) { | ||
this.type = type; | ||
this.stop = false; | ||
} | ||
|
||
start(callback) { | ||
if (this.type === 'file') { | ||
Replay.replayFile(callback); | ||
} | ||
} | ||
|
||
stop() { | ||
this.stop = true; | ||
} | ||
|
||
static replayFile(callback) { | ||
let instream; | ||
let outstream; | ||
let rl; | ||
|
||
// make sure file exists | ||
const fileName = './blocks.log'; | ||
fs.stat(fileName, (err, stats) => { | ||
if (!err && stats.isFile()) { | ||
instream = fs.createReadStream(fileName); | ||
outstream = new stream(); // eslint-disable-line new-cap | ||
rl = readline.createInterface(instream, outstream); | ||
|
||
rl.on('line', (line) => { | ||
if (line !== '') { | ||
const block = JSON.parse(line); | ||
if (block.blockNumber !== 0) { | ||
callback({ | ||
blockNumber: block.blockNumber, | ||
// we timestamp the block with the Steem block timestamp | ||
timestamp: block.timestamp, | ||
transactions: block.transactions, | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
rl.on('close', () => { | ||
callback(null); | ||
}); | ||
} else { | ||
// file does not exist, so callback with null | ||
callback(null); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports.Replay = Replay; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters