#3 - Indexer: accounts.py

in #steemlast year (edited)

Hivemind Deep Dive (new).png

What I am learning about Hivemind's design

This module handles account related operations in Hivemind. Accounts are a fundamental aspect of the Steem blockchain and they relate operations to owners, which becomes a foundation for attributing actions, token balances, etc to accounts and their owners.

Python script on GitHub: accounts.py in Hivemind [214-core branch] contains the latest code as of this writing.

Account creation

Accounts are added to the Hivemind database according to account creation operations. There are four operations (triggered from blocks.py) that create an account entry: account_create, account_create_with_delegation, create_claimed_account_operation, pow, pow2. This brings compatibility back to the first block to capture accounts created by any of these various methods, some of which are now defunct and some recently introduced.

An entry is inserted into the database after a number of validity checks, like checking if the account does not already exist. It also passes info to the Community class to check for new community registrations and handle them according, since they are also posted to the blockchain as new account operations.

Updating accounts

Account metadata updates are triggered from blocks.py and this marks accounts as "dirty," which sets them up for updates. When an account_update_operation operartion is detected in a block, Accounts.dirty() is called with the account mentioned in the operation as a parameter.

There are methods that validate entries and update the account info accordingly, such as _sql(). In short, validity checks are made to ensure real accounts are being modified, and certain constraints around data types are checked and enforced as well.

Validation for other modules

In the accounts module, there is also a def exists() function that serves to verify if an account exists, for events triggered by many other modules in Hivemind. For example, when a follow account operation is detected by blocks.py, the function above is called to verify that the account actually exists on the blockchain before adding any of its operations to the database. This maintains the integrity of the entire database.

What have I learned?

From studying this module, I learned how new accounts are added to the database and how community creation is handled. I now know how to utilize the validation method def exists() to check if an account exists, for code I intend to add to Hivemind when working on Native Ads.

Posts in this series

#1 - Overview and opportunities
#2 - Indexer: blocks.py
#3 - Indexer: accounts.py




I am currently working on a new feature called Native Ads, that may be added to Hivemind Communities in a future update.

For an overview of the Native Ads feature and how it will work, read this doc.

If you would like to take a look at the code, check out my fork of Hivemind on GitHub.