Skip to content

Conversation

@Andrei-Dolgolev
Copy link
Contributor

@Andrei-Dolgolev Andrei-Dolgolev commented Nov 13, 2024

Added raw transactions table for store raw transactions with values for each transaction which was parent of indexed tx_call or event.

table structure

                                           Table "public.ethereum_transactions"
          Column          |           Type           | Collation | Nullable |                   Default
--------------------------+--------------------------+-----------+----------+----------------------------------------------
 hash                     | character varying(256)   |           | not null |
 block_number             | bigint                   |           | not null |
 block_timestamp          | bigint                   |           | not null |
 block_hash               | character varying(256)   |           | not null |
 from_address             | bytea                    |           |          |
 to_address               | bytea                    |           |          |
 gas                      | numeric(78,0)            |           |          |
 gas_price                | numeric(78,0)            |           |          |
 max_fee_per_gas          | numeric(78,0)            |           |          |
 max_priority_fee_per_gas | numeric(78,0)            |           |          |
 input                    | text                     |           |          |
 nonce                    | character varying(256)   |           |          |
 transaction_index        | bigint                   |           |          |
 transaction_type         | integer                  |           |          |
 value                    | numeric(78,0)            |           |          |
 indexed_at               | timestamp with time zone |           | not null | timezone('utc'::text, statement_timestamp())
Indexes:
    "pk_ethereum_transactions" PRIMARY KEY, btree (hash)
    "ix_ethereum_transactions_block_hash" btree (block_hash)
    "ix_ethereum_transactions_block_number" btree (block_number)
    "ix_ethereum_transactions_block_timestamp" btree (block_timestamp)
    "ix_ethereum_transactions_from_address" btree (from_address)
    "ix_ethereum_transactions_gas" btree (gas)
    "ix_ethereum_transactions_gas_price" btree (gas_price)
    "ix_ethereum_transactions_hash" UNIQUE, btree (hash)
    "ix_ethereum_transactions_to_address" btree (to_address)
    "ix_ethereum_transactions_value" btree (value)

l2 tables contain l1_block_number.

Running Locally

1) Clone the repository

git clone [email protected]:moonstream-to/api.git

Then navigate to the directory:

cd api/moonstreamdb-v3

2) Create and activate a virtual environment

python3 -m venv .moonstreamdb
source .moonstreamdb/bin/activate

3) Install dependencies

pip install -e .

4) Set up Alembic configuration

Copy the sample configuration file to your dev config:

cp alembic.sample.ini alembic.dev.ini

Edit the “sqlalchemy.url” in alembic.dev.ini to match your local database connection string.

If your database operates in the “public” schema, set:

export MOONSTREAM_DB_V3_SCHEMA_NAME="public"

5) Run Alembic migrations

Run the migrations with:

./alembic.sh -c alembic.dev.ini upgrade head

This will initialize or update your local database schema to the latest version.


hash = Column(
VARCHAR(256), primary_key=True, unique=True, nullable=False, index=True
)
block_number = Column(
Copy link
Contributor

Choose a reason for hiding this comment

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

Not ForeignKey?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That will mean nullable ForeignKey in labels so i suggest make normalization later if we need.

Copy link
Contributor

@kompotkot kompotkot left a comment

Choose a reason for hiding this comment

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

lg

@Andrei-Dolgolev Andrei-Dolgolev merged commit 49bf3b7 into main Mar 4, 2025
1 check failed
@Andrei-Dolgolev Andrei-Dolgolev deleted the add-raw-transactions branch March 4, 2025 14:28
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.

3 participants