Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aarontravass/block-transactions-index
https://github.com/aarontravass/block-transactions-index
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/aarontravass/block-transactions-index
- Owner: aarontravass
- Created: 2024-04-22T21:56:55.000Z (7 months ago)
- Default Branch: master
- Last Pushed: 2024-04-23T05:23:26.000Z (7 months ago)
- Last Synced: 2024-10-08T02:42:37.235Z (about 1 month ago)
- Language: Python
- Size: 19.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Relayer Coding Challenge
### Part 1 Solution
For part 1, install all packages in requirements.txt and run the following in the current directory
```commandline
python .\index.py 18908800-18909050
```Replace `` and `` with the values given in the email. (Hidden from public view due to spam)
The Python program uses the following packages
1. requests
2. sqlalchemy`requests` is used for making HTTP calls and `sqlalchemy` is the ORM.
We first save all blocks to memory and then persist them in the DB.
### Part 2 Solution
The following SQL statement will fetch the block with max volume:
```sql
SELECT SUM(('x'|| LPAD(SUBSTRING(VALUE, 3, LENGTH(VALUE)), 16, '0')):: BIT(64):: BIGINT) AS volume,
('x'|| LPAD(SUBSTRING("Transaction"."blockNumber", 3, LENGTH("Transaction"."blockNumber")), 16, '0')):: BIT(64):: BIGINT AS "intBlockNumber"
FROM "Transaction"
INNER JOIN "Block" ON "Block"."blockNumber" = "Transaction"."blockNumber"
WHERE
"timestamp" >= EXTRACT(EPOCH FROM TIMESTAMP '2024-01-01 00:00:00')*1000 AND
"timestamp" <= EXTRACT(EPOCH FROM TIMESTAMP '2024-01-01 00:30:00')*1000
GROUP BY "intBlockNumber"
ORDER BY "volume" DESC
LIMIT 1
```The sql first converts all value to bigint and then uses `sum` as an aggregate function, thus allowing us to perform group by clause on the `blockNumber` column.
We order by the `volume` and then take the first row.The solution is
Volume | Block Number
----------------------|--------------
53883433384695265018 | 18908973## Tests
Pytest is used for unit testing. Run `python tests/index.py` to run the test suite.