SteemRadar.js - New Features Account Mentions, Account Counter, New Structure Update 0.2.0

in utopian-io •  5 years ago  (edited)

Repository

https://github.com/gigatoride/steemradar.js

SteemRadar

logo.png
Logo design by @gigatoride only licensed for contributions related to this project

New Features

I would like to introduce version 0.2.0 a minor release which has so many improvements and reliable stream algorithm
also, it has some new features and has faster process algorithms and better catch for each target for all methods as well as some breaking changes.

line1.png

Account Mentions

commit
If someone mentioned an account in a comment or a post it will be detected directly thanks to this new method, it also comes with multiple accounts support instead of creating an instance for each account

Also, a simple regex is being used to filter the comment/post body then it being matched with the user input mentions accounts.

The following code is the core operation for this method.

const transactions = await blockchain.getTransactions();
for (const trx of transactions) {
  const [txType, txData] = trx.operations[0];
  if (txType === 'comment') {
    const mentionAccounts = txData.body.match(/\B@[a-z0-9-.]+/gm);
    const mentionTargets = accounts
      ? accounts.map(name => {
        return `@${name}`;
      })
      : [];
    const setMentions = accounts ? mentionAccounts.some(name => mentionTargets.includes(name)) : true;
    if (mentionAccounts && setMentions && trx.transaction_id !== latestCatch) {
      latestCatch = trx.transaction_id;
      yield trx;
    }
  }
}

Account Counter

commit
This method is supposed to stream each count when someone signs up
by a simple algorithm

let latestCatch;
const count = await api.getAccountCount();
if (count && latestCatch !== count) {
  latestCatch = count;
  yield count;
}

Now when any new account register will be streamed directly by using the iterator stream algorithm.

line2.png

Funds Tracker

commit
I've made some improvements for this method to be reliable and faster, I also have prepared this method for multi-tracking by using an options parameter as an object. it will handle the multi variable as a boolean
Also, I've implemented the async iterator stream algorithm.

The multi-tracking for future I've been working on it but I didn't publish it yet it will be ready in next versions.

Support multiple accounts

Now all single account params methods now accepting multiple accounts.
This gonna be an array which contains an account name instead of just a single account string as a parameter.

Then this code for multiple accounts validation

accounts.every(account => validateAccountName(account) === null)

line1.png

New Structure & Iterator streams

commit
map.png

In the old version, I've been using a blockchain as a helper file for each method, all in one file.
But now I've separated all methods for easier maintenance and development.

Also, the module has been moved from dsteem as a dependency to steem-js as dsteem no longer updated since 6 months ago.
and also because some utilities not available in dsteem also I can see that steem-js is currently stable and reliable for SteemRadar.js.

The folder structure has been changed now blockchain is a prototype for the scan class beside utopian.

line2.png

Breaking changes

The following methods have been renamed.

//old
scan.blockchain.accounts()
//new
scan.blockchain.accountActivity()

//old
scan.blockchain.security()
//new
scan.blockchain.accountSecurity()

I've made some improvements to existing methods to be an alternative for others.
The following methods have been removed from SteemRadar as there are other alternatives.

Utopian vote stream

// Removed
scan.utopian.vote()
// Alternative
scan.blockchain.votes()

Memo stream

// Removed
scan.blockchain.memo()
// Alternative
scan.blockchain.transfers()

line1.png

Implementation

if you already have the older version you can update this package by the following command

$ npm update

or you can install the package by the following command

$ npm install steemradar

Create new instance

const steemradar = require('steemradar');

const scan = new steemradar.Scan();

I'm going to explain how to implement the new features only for other features please read the documentation

Stream or detect any account mentions from blockchain comments/posts

  const accounts = ['utopian-io'] || null;

  const stream = scan.blockchain.accountMentions(accounts);
  stream.on('data', trx => {
    stream.pause(); // Pause this operation use resume() to resume
    stream.destroy(); // Destory this operation
  });

Stream account counting from blockchain

  const stream = scan.blockchain.accountCounter();
  stream.on('data', trx => {
   console.log(trx);
    stream.pause();
    stream.destroy();
  });

line2.png

Testing

For testing all methods please use the following command

npm test

SharedScreenshot.jpg

line1.png

What's next?

A new major release:

  • Some breaking changes
  • Rename all scan aliases to start with get
  • Complete funds tracking algorithm for multi-tracking
  • A new method for comments
  • A new method for posts
  • Full streaming methods for utopian.rocks
  • Improve library code readability & documentation
  • Reduce the dependencies (by built-in alternatives)
  • Sperate command-line utility in a different repository to reduce the dependencies and library size.

line2.png

Github Account

https://github.com/gigatoride

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  • Good article with images, code samples and explanation of coding choices
  • Good commit messages, but few inline code comments.
  • Watch out for doucmentation, it should be documentation

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Chat with us on Discord.

[utopian-moderator]

Thanks for the review, fixed the typo :)

I'm trying to improve the code readability without inline comments in next major version some if/else statements gonna be described with variables.

I only use inline comments for necessary or complicated things.

Thank you for your review, @helo! Keep up the good work!

Hi @gigatoride!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hey, @gigatoride!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!