Last active
April 18, 2020 03:29
-
-
Save rraallvv/edc5e0ec5bcba8799f1aec3531568f85 to your computer and use it in GitHub Desktop.
Revisions
-
rraallvv revised this gist
Apr 18, 2020 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ // get data for each confirmed transaction $.client.addHeadChangedListener(async (hash, reason) => { const block = await $.client.getBlock(hash); const transactions = block.body.transactions; for (const transaction of transactions) { const data = { txid: transaction.hash().toPlain(), value: transaction.value, sender: transaction.recipient.toUserFriendlyAddress() }; console.log("!!!", data); } }); -
rraallvv revised this gist
Apr 17, 2020 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ const port = 8000, io = require("socket.io"), server = io.listen(port), dummy = { txid: "e3564341b77fe099b1d123bece39057e1cc4cf446376612dc6eaab6957b3f180", valueOut: 123.0, vout: [ {XhayrpwPfELBNjErrBmHe6qpsaiwFSWzyX: 12682308} ], isRBF: false, txlock: false @@ -16,7 +16,7 @@ const server.on("connection", (socket) => { console.info(`Client connected [id=${socket.id}]`); socket.on("disconnect", () => { console.info(`Client gone [id=${socket.id}]`); }); -
rraallvv created this gist
Apr 17, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ <html> <body> <script src="socket.io.js"></script> <script> eventToListenTo = 'tx' room = 'inv' packages = 0; var socket = io("http://localhost:8000/"); socket.on('connect', function() { console.log('connected!!!'); // Join the room. socket.emit('subscribe', room); }) socket.on(eventToListenTo, function(data) { console.log(data); if (packages > 10) { console.log('unsubscribed!!!'); socket.emit('unsubscribe', room); } else { packages++; } }) </script> </body> </html> This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ const port = 8000, io = require("socket.io"), server = io.listen(port), dummy = { txid: "e3564341b77fe099b1d123bece39057e1cc4cf446376612dc6eaab6957b3f180", valueOut: 123.0, vout: [ {XhayrpwPfELBNjErrBmHe6qpsaiwFSWzyX: 12682308} ], isRBF: false, txlock: false }; // event fired every time a new client connects: server.on("connection", (socket) => { console.info(`Client connected [id=${socket.id}]`); socket.on("disconnect", () => { console.info(`Client gone [id=${socket.id}]`); }); socket.on("subscribe", (data) => { if (data === "inv") { socket.join("inv", () => { console.info("Subscribed"); }); } }); socket.on("unsubscribe", (data) => { if (data === "inv") { socket.leave("inv", () => { console.info("Unsubscribed"); }); } }); }); // sends each client its current sequence number setInterval(() => { console.log('.'); server.to('inv').emit('tx', dummy); }, 5000); console.log(`App started on port ${port}`);