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

Add chains crawler for seer. #9

Merged
merged 28 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,194 @@ go.work
# Seer ignores
seer
.vscode/


### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace

# Local History for Visual Studio Code
.history/

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode

# Envionments
.seer/
.venv/
.env/

# Environment variables
dev.env
test.env
prod.env
moonstreamdb.env
docker.env
docker.dev.env
docker.test.dev
docker.prod.env
docker.moonstreamdb.env

.secrets/

# Alembic migrations
alembic.test.ini
alembic.dev.ini
alembic.prod.ini
alembic.moonstreamdb.ini
alembic.docker.ini

# Schematic
srv/
.schematic.env

# Custom
scratch/
137 changes: 137 additions & 0 deletions blockchain/common/decoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package common

import (
"encoding/json"
"fmt"
"log"
"os"
// "time"
)

type BlockJson struct {
Difficulty int64 `json:"difficulty"`
ExtraData string `json:"extraData"`
GasLimit int64 `json:"gasLimit"`
GasUsed int64 `json:"gasUsed"`
Hash string `json:"hash"`
LogsBloom string `json:"logsBloom"`
Miner string `json:"miner"`
MixHash string `json:"mixHash"`
Nonce string `json:"nonce"`
BlockNumber int64 `json:"number"`
ParentHash string `json:"parentHash"`
ReceiptRoot string `json:"receiptRoot"`
Sha3Uncles string `json:"sha3Uncles"`
StateRoot string `json:"stateRoot"`
Timestamp int64 `json:"timestamp"`
TotalDifficulty string `json:"totalDifficulty"`
TransactionsRoot string `json:"transactionsRoot"`
Uncles string `json:"uncles"`
Size int32 `json:"size"`
BaseFeePerGas string `json:"baseFeePerGas"`
IndexedAt int64 `json:"indexed_at"`
}

type SingleTransactionJson struct {
AccessList []AccessList `json:"accessList"`
BlockHash string `json:"blockHash"`
BlockNumber int64 `json:"blockNumber"`
ChainId string `json:"chainId"`
FromAddress string `json:"from"`
Gas string `json:"gas"`
GasPrice string `json:"gasPrice"`
Hash string `json:"hash"`
Input string `json:"input"`
MaxFeePerGas string `json:"maxFeePerGas"`
MaxPriorityFeePerGas string `json:"maxPriorityFeePerGas"`
Nonce string `json:"nonce"`
R string `json:"r"`
S string `json:"s"`
ToAddress string `json:"to"`
TransactionIndex int64 `json:"transactionIndex"`
TransactionType int32 `json:"type"`
Value string `json:"value"`
YParity string `json:"yParity"`
IndexedAt int64 `json:"indexed_at"`
BlockTimestamp int64 `json:"block_timestamp"`
}

type AccessList struct {
Address string `json:"address"`
StorageKeys []string `json:"storageKeys"`
}

// SingleEvent represents a single event within a transaction
type SingleEventJson struct {
Address string `json:"address"`
Topics []string `json:"topics"`
Data string `json:"data"`
BlockNumber int64 `json:"blockNumber"`
TransactionHash string `json:"transactionHash"`
BlockHash string `json:"blockHash"`
Removed bool `json:"removed"`
LogIndex int64 `json:"logIndex"`
TransactionIndex int64 `json:"transactionIndex"`
}

// ReadJsonBlocks reads blocks from a JSON file
func ReadJsonBlocks() []*BlockJson {
file, err := os.Open("data/blocks_go.json")
if err != nil {
log.Fatal(err)
}
defer file.Close()

var blocks []*BlockJson
decoder := json.NewDecoder(file)
err = decoder.Decode(&blocks)
if err != nil {
fmt.Println("error:", err)
}

return blocks
}

// ReadJsonTransactions reads transactions from a JSON file
func ReadJsonTransactions() []*SingleTransactionJson {

file, err := os.Open("data/transactions_go.json")
if err != nil {
log.Fatal(err)
}
defer file.Close()

var transactions []*SingleTransactionJson
decoder := json.NewDecoder(file)
err = decoder.Decode(&transactions)
if err != nil {
fmt.Println("error:", err)
}

return transactions
}

// ReadJsonEventLogs reads event logs from a JSON file
func ReadJsonEventLogs() []*SingleEventJson {

file, err := os.Open("data/event_logs_go.json")
if err != nil {
log.Fatal(err)
}
defer file.Close()

var eventLogs []*SingleEventJson

decoder := json.NewDecoder(file)

fmt.Println("decoder:", decoder)

err = decoder.Decode(&eventLogs)
if err != nil {
fmt.Println("error:", err)
}

fmt.Println("eventLogs:", eventLogs[0])

return eventLogs
}
17 changes: 17 additions & 0 deletions blockchain/common/ecoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package common

import "math/big"

// BlockchainHandler defines the interface for handling blockchain data fetching.
type BlockchainHandler interface {
FetchData(blockNumber *big.Int) ([]EventData, error)
}

// EventData outlines the structure for blockchain event data.
type EventData struct {
// Common fields...
BlockNumber uint64
Data []byte
ChainID string
Extra interface{} // Use for blockchain-specific additional data
}
Loading
Loading