-
Notifications
You must be signed in to change notification settings - Fork 1
Small fixes and cleanup #79
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
9b020de
5ab545e
e21eaa9
950dcc1
e2f328a
efc12f8
3288000
e284c5a
16a08f2
768f08b
bd1d5d5
1f3bfe6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,9 +119,7 @@ def process_single_transaction( | |
| self.log_message = [] | ||
| try: | ||
| # compute raw token imbalances | ||
| token_imbalances = self.process_token_imbalances( | ||
| tx_hash, auction_id, block_number | ||
| ) | ||
| token_imbalances = self.process_token_imbalances(tx_hash) | ||
|
|
||
| # get transaction timestamp | ||
| transaction_timestamp = self.blockchain_data.get_transaction_timestamp( | ||
|
|
@@ -134,9 +132,8 @@ def process_single_transaction( | |
| # transaction_tokens = self.blockchain_data.get_transaction_tokens(tx_hash) | ||
| # store transaction tokens | ||
| transaction_tokens = [] | ||
| for token_address, imbalance in token_imbalances.items(): | ||
| if imbalance != 0: | ||
| transaction_tokens.append((tx_hash, token_address)) | ||
| for token_address in token_imbalances.keys(): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would reorganize code here. Instead of fetching
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it is still not clear where and how the raw imbalances will be used, i decided to keep it separate and not part of a get_transaction_tokens function.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One reason for separating functionality into functions is that it makes it possible to test things. Moving a function into the main body and removing tests is not ideal. I can handle moving the function into token imbalances if you do not have the capacity.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok i am attempting to do this now |
||
| transaction_tokens.append((tx_hash, token_address)) | ||
| self.db.write_transaction_tokens(transaction_tokens) | ||
|
|
||
| # update token decimals | ||
|
|
@@ -202,7 +199,8 @@ def process_single_transaction( | |
| return | ||
|
|
||
| def process_token_imbalances( | ||
| self, tx_hash: str, auction_id: int, block_number: int | ||
| self, | ||
| tx_hash: str, | ||
| ) -> dict[str, int]: | ||
| """Process token imbalances for a given transaction and return imbalances.""" | ||
| try: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,7 @@ def tests_write_prices(): | |
| f"postgresql+psycopg://postgres:postgres@localhost:5432/mainnet" | ||
| ) | ||
| db = Database(engine, "mainnet") | ||
| # list contains duplicate entry in order to test how this is handled | ||
|
||
| token_prices = [ | ||
| ( | ||
| "0xA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48", | ||
|
|
@@ -85,6 +86,12 @@ def tests_write_prices(): | |
| 0.000000050569218629, | ||
| "moralis", | ||
| ), | ||
| ( | ||
| "0x68BBED6A47194EFF1CF514B50EA91895597FC91E", | ||
| int(datetime.fromisoformat("2024-10-10 16:49:47.000000").timestamp()), | ||
| 0.000000050569218629, | ||
| "moralis", | ||
| ), | ||
| ] | ||
| # truncate table | ||
| with engine.connect() as conn: | ||
|
|
@@ -97,6 +104,8 @@ def tests_write_prices(): | |
| res = conn.execute( | ||
| text("SELECT token_address, time, price, source FROM prices") | ||
| ).all() | ||
| # cleaning up the duplicate entry | ||
| token_prices = token_prices[:2] | ||
| for i, (token_address, time, price, source) in enumerate(token_prices): | ||
| assert HexBytes(res[i][0]) == HexBytes(token_address) | ||
fhenneke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert res[i][1].timestamp() == time | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.