Best Way to Go About Building Deposit Monitoring Scripts for STEEM?

in #life7 years ago (edited)

While many of you know me for my "political" or "artistic" work on the site my true passion is developing and programming all sorts of things. STEEM stuff is challenging and fun to build!

Currently I've got a number of projects on the go in regards to our STEEM network. It's actually very exciting for me to be spearheading and developing the tools and services I am. However recently I've run into a bit of a snag in my development work and have decided to reach out to the community for help solving the issues I'm currently facing in development.

Put in the simplest way: I need a hand with building a system to monitor the STEEM blockchain for deposits to various services. I've begun work on my own accord to get this necesarry system built but unfortunately haven't had much luck in getting it to fire.

I Believe I Understand the Concept of STEEM Deposits

The way to monitor for deposits seems simple enough.. STEEM blocks aren't encrypted an if you're able to parse the transfers in the blocks and check them for your projects name and the memo attached matches certain variables set by your deposit rules then X amount of STEEM or SBD would be credited to the account in question.

What I'd started building my deposit scripts off of is linked below!

Written in Node.js and sourced from:
https://steem.io/documentation/how-monitor-account-deposits/

var rpc = require('node-json-rpc');

// Block to check from
  var last_block = 160900;
// Account to monitor for
  var watch_account = "world";
// Connection settings
  var options = {
      port: 8092,
      host: '127.0.0.1',
      path: '/rpc',
      strict: false
  };

// Outgoing RPC Call code
  var callrpc = function(name, params, cb) {
      client.call(
          {"jsonrpc": "2.0",
           "method": name,
           "params": params,
           "id": 0},
          function(err, res) {
             if (err) { cb(err, null) }
             else { cb(null, res["result"]) }
          }
      );
  }

// Block parsing bits?
  var process_transfer = function(op, block, blockid) {
      console.log(block);
      if (op["to"] == watch_account) {
          console.log(blockid + " | " + 
                      block["timestamp"] + " | "+
                      op["from"] + " -> " +
                      op["to"] + ": " +
                      op["amount"] + " -- " +
                      op["memo"]
              );
      }
  }


// More block parsing for transfers?
  var process_block = function(block, blockid) {
      console.log(blockid);
      console.log(block["transactions"]);
      for (var tx in block["transactions"]) {
          for (var opObj in tx["operations"]) {
              var opType = opObj[0];
              var op = opObj[1];

              console.log(op);

              if (opType == "transfer") {
                  process_transfer(op, block, blockid);
              }
          }
      }
  }

// Loop and check next block if not caught up
  var start_loop = function() {
      callrpc("get_dynamic_global_properties", [], function(err, props) {
          var block_number = props["last_irreversible_block_num"];
          while ((block_number - last_block) > 0) {
              last_block += 1
              callrpc("get_block", [last_block], function(err, block) {
                  process_block(block, last_block);
              });
          }
      });
  }


  var client = new rpc.Client(options);

  var block_interval;
// See what the block times are like
  callrpc("get_config", [],
          function (err, config) {
              if (err) { console.log(err); }
              else {
                  block_interval = config["STEEMIT_BLOCK_INTERVAL"]
                  start_loop();
              }
          }
         )



I've had limited success with the code above. I was seemingly able to get it started on checking all of the blocks for my test deposits but seemingly haven't been able to get it to run as I would like. Two things I'm still very much trying to figure out:

  1. Is their a way to make the script above less resource intensive? It currently eats resources like a bastard.

  2. I realize that block times are 3 seconds... But how does one know when the last reversible block is passed from the deposit in order to allow withdrawal or credit to account?

I know a number of folks have been using Piston based scripts or tools to monitor the blockchain for deposits. While I'm not against using Piston or Python3 I'd like to get a working Node.js deposit script going in order to minimize the amount of dependencies needed to deploy deposit systems into my projects. Has anyone got a Node.js STEEM deposit script with examples beyond what I've shown above that they are using and willing to share with me to help with my projects?

Looking for Piston Bot Code Too!

Also, Side note (Piston Related) does anyone have the sourcecode available for the bot functionality to call a bot or script it in comments sections? I remember seeing a post that had all code needed to build a listening / replying bot based off of piston but cannot for the life of me remember the author nor post name to search it.

Basically the functionality I am looking for is a user would use an @name call followed by a command. The code to simply have the calls register on my side should be enough to get me tinkering on a side project that STEEM desperately needs but hasn't got yet.

Thank you for taking the time to read this. All the Developer brains get at me please!

Sort:  

Also, Side note (Piston Related) does anyone have the sourcecode available for the bot functionality to call a bot or script it in comments sections?

https://steemit.com/steemit/@contentjunkie/how-to-get-started-making-a-python-based-steemit-bot-on-centos-7-using-piston

He also had one about a dickbutt bot that would comment dickbutt pics any time someone said dickbutt.
https://steemit.com/funny/@contentjunkie/the-complete-source-code-for-a-simple-steemit-dickbutt-reply-bot-written-in-python-using-steem-piston

also, i think you can do something similar with transactions, no? that is to say steem.stream_transactions

Also, you could check the account history every X seconds too, i think.... that is to say, of getting a whole block every three seconds, parsing it, and searching through it for your transactions, you can get_account_history every three seconds, and just look for new transactions... then again, i know shit about programming so maybe im talking out of my ass.

You are thinking the right way though. Thank you for the resources!

I am experimenting with piston based stuff at the moment. Python isn't my strongest programming language but it's nice to challenge yourself to learn new things.

Thanks sir

This post has been ranked within the top 25 most undervalued posts in the second half of Jan 09. We estimate that this post is undervalued by $10.99 as compared to a scenario in which every voter had an equal say.

See the full rankings and details in The Daily Tribune: Jan 09 - Part II. You can also read about some of our methodology, data analysis and technical details in our initial post.

If you are the author and would prefer not to receive these comments, simply reply "Stop" to this comment.

I have no idea about any of this stuff but Good Luck to you ! steem on !👍😉🇨🇦

No worries Karen! Neither did I when I started programming years back.

While I may not be the smartest stick what I lack in intelligence I make up for in perseverance!

I decided to come to your blog and see what was going on and say hi and IDK any of this stuff but I was on Steem Global a day or so ago and clicked to get my daily dose of free steem.

Since I am trying things and learning little things here and there, this post reminded me I made a note to tell you I tried clicking more than once a day to see if the deposits would work and (I think anyways) -- it seemed to allow it but I am not 100% sure

So you may want to check that. I meant to message you on this before.

Sweetheart, I love you and only swinging by to give upvote and comment love. LOL I know nothing about code. Good luck with that.

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.034
BTC 64058.80
ETH 3150.15
USDT 1.00
SBD 3.99