Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/ethereum refactor accounts table #983

Merged
merged 18 commits into from
Apr 19, 2021

Conversation

redroy44
Copy link
Contributor

@redroy44 redroy44 commented Apr 7, 2021

To be merged to master after #981

This PR brings a number of ethereum improvements:

  • add (block_hash, block_number, timestamp) wherever necessary
  • add log_index to token_transfers table for ordering
  • refactor accounts table to contain account, contract and token data
  • add accounts_history table for temporal queries along with accounts_history endpoint
  • add contracts and tokens as views of accounts table
  • use tokenStandard instead of isERC20 and isERC721 fields
  • add bytecode_hash to accounts table. This is a SHA-1 hash of contract's bytecode
  • metadata updates

@redroy44 redroy44 force-pushed the feature/ethereum-refactor-accounts-table branch from 30b7a4d to 1923764 Compare April 7, 2021 13:12
@redroy44 redroy44 marked this pull request as ready for review April 8, 2021 08:01
@redroy44 redroy44 changed the base branch from bugfix/ethereum-indexer-bug to master April 13, 2021 07:28
implicit ec: ExecutionContext
): DBIOAction[List[Unit], NoStream, Effect.Read with Effect.Write with Effect.Transactional] = {
import tech.cryptonomic.conseil.common.sql.CustomProfileExtension.api._
DBIO.sequence(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I don't understand something, but why didn't you use something like this: Tables.Accounts.insertOrUpdateAll(accounts.map(_.convertTo[Tables.AccountsRow]))?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically I want to update Account with the latest data (blockHash, blockNumber, timestamp, balance) without overwriting contract/token data (bytecode, bytecode_hash, token_standard, name, symbol, decimals, total_supply)

That's why I take the existing row, update a subset of fields and write the updated row to DB

*/
def createTokens(tokens: List[Token]) =
def createAccountBalances(accounts: List[Account]): DBIOAction[Unit, NoStream, Effect.Write] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this also works - a bit cleaner:

def createAccountBalances(accounts: List[Account]): DBIO[Option[Int]] =
    Tables.AccountsHistory ++= accounts.map(_.convertTo[Tables.AccountsHistoryRow])

*/
def createContracts(contracts: List[Contract]) =
def createContractAccounts(contractAccounts: List[Account]): DBIOAction[Unit, NoStream, Effect.Write] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you refactor this like in example for createAccountBalances ?

Copy link
Contributor

@piotrkosecki piotrkosecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added few comments regarding simplification in ETH persistence, but besides that it looks ok

@sonarcloud
Copy link

sonarcloud bot commented Apr 19, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

No Coverage information No Coverage information
12.1% 12.1% Duplication

@vishakh vishakh merged commit 94da329 into master Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants