# Functions
AddNewSubscriptionPlan - Adding new subcription plan to database after those being read from .plans.json
Taking into consideration the factor, whether it has been already persisted or not, or any changes made to `.plans.json` file.
AddSubscriptionPlanForAddress - Persisting subscription plan for one ethereum address, when this address is first time creating one `ette` application.
CheckSubscriptionPlanByAddress - Given user's ethereum address, checking if user has already subscribed to any plan or not.
CheckSubscriptionPlanDetailsByAddress - Given address of subscriber, returns full plan details to which they're subscribed.
ComputeAPIKeyForAddress - Computing new API key for user address, by taking `nonce` of that account & current unix time stamp ( with nanosecond level precision ) under consideration
Here `nonce` is nothing but count of applications created in `ette` by account
`Time` field is being added when computing next API key for making it more unpredictable
Previous implementation had very predicatable pattern.
Connect - Connecting to postgresql database.
CreateSubscriptionPlan - Creates new entry for subscription plan.
DeleteBlock - Delete block entry, identified by block number, while cascading all dependent entries ( i.e.
DeliveryCountByPlanName - Given subscription plan name, returns subscription plan's delivery count.
DoesItMatch - Given one event emitted by some contract & topic signature against which we're attempting to match the event it'll return boolean depending upon whether it's satisfying all conditions or not.
DropOldDeliveryHistories - Attempts to delete older than 24 hours delivery history from data store, because that piece of data is not being used any where, so no need to keep it
Before delivering any piece of data to client, rate limit to be checked for last 24 hours not older than that
@note This function can be invoked every 24 hours to clean up historical entries.
EventTopicsAsString - Given event topic signatures as map, returns these topics as string, seperated by `,` i.e.
ExtractOutOnlyMatchingEvents - Extract out only those events which are having full match with specified event topic signatures.
GetAllBlockNumbersInRange - Returns all block numbers in given range, both inclusive.
GetAllowedDeliveryCountByAddress - Returns how many deliveries can be made to user in 24 hours, as per plan they're subscribed to.
GetAllSubscriptionPlans - Returns a list of all available susbcription plans from this `ette` instance.
GetAppsByUserAddress - Given user address, returns list of all apps created by user, along with their API key & respective creation timestamp.
GetBlock - Fetch block by number, from database.
GetBlockByHash - Given blockhash finds out block related information
If not found, returns nil.
GetBlockByNumber - Fetch block using block number
If not found, returns nil.
GetBlockCount - Returns how many blocks currently present in database
Caution : As we're dealing with very large tables ( with row count ~ 10M & increasing 1 row every 2 seconds ) this function needs to be least frequently, otherwise due to full table scan it'll cost us a lot
Currently only using during application start up
All other block count calculation requirements can be fulfilled by using in-memory program state holder.
GetBlocksByNumberRange - Given block numbers as range, it'll extract out those blocks by number, while returning them in ascendically sorted form in terms of block numbers
Note : Can return at max 10 blocks in a single query
If more blocks are requested, simply to be rejected In that case, consider splitting them such that they satisfy criteria.
GetBlocksByTimeRange - Given time range ( of 60 sec span at max ), returns blocks mined in that time span
If asked to find out blocks in time span larger than 60 sec, simply drops query request.
GetContractCreationTransactionsFromAccountByBlockNumberRange - Fetch all contract creation tx(s) from given account with in specific block number range.
GetContractCreationTransactionsFromAccountByBlockTimeRange - Fetch all contract creation tx(s) from given account with in specific block time span range.
GetCurrentBlockNumber - Returns highest block number, which got processed by `ette`.
GetCurrentOldestBlockNumber - Fetches what's lowest block number present in database, which denotes if it's not 0, from here we can start syncing again, until we reach 0.
GetDefaultSubscriptionPlanID - Finding out that subscription plan id, which has lowest daily deliveryCount promise, which is going to be always default plan, when a new ethereum address joins `ette`.
GetEventByBlockHashAndLogIndex - Given block hash and log index in block return respective event log, if any exists.
GetEventByBlockNumberAndLogIndex - Given block number and log index in block return respective event log, if any exists.
GetEventsByBlockHash - Given block hash retrieves all events from all tx present in that block.
GetEventsByTransactionHash - Given tx hash, returns all events emitted during contract interaction ( i.e.
GetEventsFromContractByBlockNumberRange - Given block number range & contract address, extracts out all events emitted by this contract during block span.
GetEventsFromContractByBlockTimeRange - Given block time range & contract address, extracts out all events emitted by this contract during time span.
GetEventsFromContractWithTopicsByBlockNumberRange - Given block number range, contract address & topics of event log, extracts out all events emitted by this contract during block span with topic signatures matching.
GetEventsFromContractWithTopicsByBlockTimeRange - Given time range, contract address & topics of event log, extracts out all events emitted by this contract during block span with topic signatures matching.
GetLastXEventsFromContract - Finds out last `x` events emitted by contract.
GetTransactionByHash - Given tx hash, extracts out transaction related data.
GetTransactionCountBetweenAccountsByBlockNumberRange - Given from & to account addresses & block number range, returns #-of transactions where `from` & `to` fields are matching.
GetTransactionCountBetweenAccountsByBlockTimeRange - Given from & to account addresses & block mining time range, returns #-of transactions where `from` & `to` fields are matching.
GetTransactionCountByBlockHash - Given block hash, finds out how many transactions are packed in that block.
GetTransactionCountByBlockNumber - Given block number, finds out how many transactions are packed in that block.
GetTransactionCountFromAccountByBlockNumberRange - Given account address & block number range, it can find out how many tx(s) were sent from this account in specified block range.
GetTransactionCountFromAccountByBlockTimeRange - Given account address & block mining time stamp range, it can find out count of all tx(s) performed by this address, with in that time span.
GetTransactionCountToAccountByBlockNumberRange - Given account address & block number range, returns #-of transactions where `account` was in `to` field.
GetTransactionCountToAccountByBlockTimeRange - Given account address which is present in `to` field of tx(s) held in blocks mined with in given time range, returns those tx count.
GetTransactionFromAccountWithNonce - Given tx sender address & account nonce, finds out tx, satisfying condition.
GetTransactionsBetweenAccountsByBlockNumberRange - Given from & to account addresses & block number range, returns transactions where `from` & `to` fields are matching.
GetTransactionsBetweenAccountsByBlockTimeRange - Given from & to account addresses & block mining time range, returns transactions where `from` & `to` fields are matching.
GetTransactionsByBlockHash - Given block hash, returns all transactions present in that block.
GetTransactionsByBlockNumber - Given block number, returns all transactions present in that block.
GetTransactionsFromAccountByBlockNumberRange - Given account address & block number range, it can find out all transactions which are performed from this account.
GetTransactionsFromAccountByBlockTimeRange - Given account address & block mining time stamp range, it can find out all tx(s) performed from this account, with in that time span.
GetTransactionsToAccountByBlockNumberRange - Given account address & block number range, returns transactions where `account` was in `to` field.
GetTransactionsToAccountByBlockTimeRange - Given account address which is present in `to` field of tx(s) held in blocks mined with in given time range.
GetUserFromAPIKey - Given API Key, tries to find out if there's any user registered who signed for creating this API Key.
IsUnderRateLimit - Checks whether number of times data delivered to client application on this day ( identified using signer address i.e.
IsValidSubscriptionPlan - Given subscription plan id, checking against database whether it's a valid one or not.
PersistAllSubscriptionPlans - Given path to user created subscription plan holder ``.plans.json` file, it'll read that content into memory & then parse JSON content of its, which will be persisted into database, into `subscription_plans` table.
PutBlock - Persisting fetched block.
PutDataDeliveryInfo - Persisting data delivery info, before it's sent to client application
dataLength is length of data in bytes, sent to client application.
RegisterNewApp - Registering new application for given address.
RemoveEventsByBlockHash - All events emitted by tx(s) packed in block, to be removed from DB.
RemoveTransactionsByBlockHash - Remove all tx(s) packed in this block from DB.
StoreBlock - Persisting block data in database, if data already not stored
Also checks equality with existing data, if mismatch found, updated with latest data
Tries to wrap db modifications inside database transaction to guarantee consistency, other read only operations being performed without protection of db transaction
👆 gives us performance improvement, also taste of atomic db operation i.e.
ToggleAPIKeyState - Given valid API key, toggles its enabled state.
UpdateBlock - Updating already existing block.
UpdateSubscriptionPlan - Tries to update existing subscription plan, where it's assumed plan name is unchanged & allowed delivery count in 24 hours has got updated.
UpsertEvent - It may be the case previously this block was processed and event log also got persisted into database, which has been updated on chain, due to chain reorganization
Now we want to persist latest entry into database, using upsert operation i.e.
UpsertTransaction - It may be the case previously this block was processed and transaction also got persisted into database, which has been updated on chain, due to chain reorganization
Now we want to persist latest entry into database, using upsert operation i.e.
ValidateAPIKey - Given an API Key, checks whether this API Key is present or not, if yes, request from client can be taken up.
# Structs
Blocks - Mined block info holder table model.
DeliveryHistory - For each request coming from client application we're keeping track of how much data gets sent back in response of their query
This is to be used for controlling client application's access to resources they're requesting.
Events - Events emitted from smart contracts to be held in this table.
PackedBlock - Whole block data to be persisted in a single database transaction to ensure data consistency, if something goes wrong in mid, whole persisting operation will get reverted.
PackedTransaction - All data that is stored in a tx, to be passed from tx data fetcher to whole block data persist handler function.
SubscriptionDetails - Keeps track of which ethereum address has subscription to which plan where, `subscriptionplan` refers to `id` in subscription_plans table and `address` refers to address in users table.
SubscriptionPlans - Allowed subscription plans, to be auto populated from .plans.json, at application start up.
Transactions - Blockchain transaction holder table model.
Users - User address & created api key related info, holder table.
# Interfaces
Tabler - ...