Simple Transaction Monitor

in #dev3 years ago

Pretty straight forward monitor

I'm back again with another simple python snippet of code to use in future projects. A lot of projects begin as needing something to monitor the chain and react accordingly. I thought about this and decided the best example to show how simple it is and a teaching tool to myself was to monitor the transaction ops and insert them into a database if they were to or from me.


This is the basis of listening for memos to react with a response of sorts. (In this case, put them into a simple sqlite3 DB) another popular option is to listen for the comments op and check if something is mentioned (that may be another project/lesson in the future)


This example requires both beem and dataset and will watch for whatever account you set as the watch variable.

#!/usr/bin/env python3

import dataset
from beem import Steem
from beem.blockchain import Blockchain

watch = "thecrazygm"

hive = Steem(node='')
db = dataset.connect('sqlite:///mydatabase.db')

# System Variables
blockchain = Blockchain(steem_instance=hive)
stream =['transfer'], raw_ops=False, threading=True, thread_num=4)
table = db[watch]

# parse json data to SQL insert
def update_db(post):
    except Exception as e:
        print(f'[Error: {e} moving on]')

def monitor():
    print("[Starting up...]")
    # Read the live stream and filter out only transfers
    for post in stream:
        if post["to"] == watch or post["from"] == watch:
            print(f"[Transaction Found from {post['from']} to {post['to']}]")

if __name__ == "__main__":

The code can be found always up to date at my GitHub gist area at this file:
If you like what I'm doing consider following me, either here or on GitHub or buy me a coffee.

Again, stay safe out there people,
Michael Garcia a.k.a. @TheCrazyGM