Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcgary committed Sep 6, 2024
1 parent 8929594 commit 0766ac1
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 193 deletions.
143 changes: 0 additions & 143 deletions internal/storage/postgresql/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ func NewPostgresBlockStore(db *gorm.DB, cfg *config.Config, l *zap.Logger) (*Pos
return mds, nil
}

func (m *PostgresBlockStore) GetDb() *gorm.DB {
return m.Db
}

func (m *PostgresBlockStore) autoMigrate() {
if m.migrated {
return
Expand All @@ -61,36 +57,6 @@ func (m *PostgresBlockStore) CreateTxBlock(tx *gorm.DB) *gorm.DB {
return m.Db.Begin()
}

func (m *PostgresBlockStore) GetNextSequenceId() (uint64, error) {
return pg.WrapTxAndCommit[uint64](func(txn *gorm.DB) (uint64, error) {
query := `SELECT coalesce(max(id), -1) + 1 FROM block_sequences`

var nextId uint64
result := txn.Raw(query).Scan(&nextId)

if result.Error != nil {
return 0, xerrors.Errorf("Failed to get next sequence id: %w", result.Error)
}

return nextId, nil
}, nil, m.Db)
}

func (m *PostgresBlockStore) UpdateBlockPath(sequenceId uint64, blockNumber uint64, path string) (*storage.Block, error) {
return pg.WrapTxAndCommit[*storage.Block](func(txn *gorm.DB) (*storage.Block, error) {
sequence := &storage.Block{}
result := txn.Model(sequence).
Clauses(clause.Returning{}).
Where("id = ? and number = ?", sequenceId, blockNumber).
Update("blob_path", path)

if result.Error != nil {
return nil, xerrors.Errorf("Failed to update block path: %w", result.Error)
}
return sequence, nil
}, nil, m.Db)
}

func (m *PostgresBlockStore) InsertBlockAtHeight(
blockNumber uint64,
hash string,
Expand Down Expand Up @@ -147,38 +113,6 @@ func (m *PostgresBlockStore) InsertBlockTransaction(
}, nil, m.Db)
}

func (m *PostgresBlockStore) BatchInsertBlockTransactions(
sequenceId uint64,
blockNumber uint64,
transactions []storage.BatchTransaction,
) ([]*storage.Transaction, error) {
if len(transactions) == 0 {
return make([]*storage.Transaction, 0), nil
}
return pg.WrapTxAndCommit[[]*storage.Transaction](func(txn *gorm.DB) ([]*storage.Transaction, error) {
txs := make([]*storage.Transaction, 0, len(transactions))
for _, tx := range transactions {
txs = append(txs, &storage.Transaction{
BlockSequenceId: sequenceId,
BlockNumber: blockNumber,
TransactionHash: tx.TxHash,
TransactionIndex: tx.TxIndex,
FromAddress: tx.From,
ToAddress: tx.To,
ContractAddress: tx.ContractAddress,
BytecodeHash: tx.BytecodeHash,
})
}

result := m.Db.Model(&storage.Transaction{}).Clauses(clause.Returning{}).Create(&txs)

if result.Error != nil {
return nil, xerrors.Errorf("Failed to insert block transaction: %w", result.Error)
}
return txs, nil
}, nil, m.Db)
}

func (m *PostgresBlockStore) InsertTransactionLog(
txHash string,
transactionIndex uint64,
Expand Down Expand Up @@ -219,36 +153,6 @@ func (m *PostgresBlockStore) InsertTransactionLog(
}, nil, m.Db)
}

func (m *PostgresBlockStore) BatchInsertTransactionLogs(transactions []*storage.BatchInsertTransactionLogs) ([]*storage.TransactionLog, error) {
logs := make([]*storage.TransactionLog, 0)

for _, tx := range transactions {
for _, log := range tx.ParsedTransaction.Logs {
argsJson, err := json.Marshal(log.Arguments)
if err != nil {
m.Logger.Sugar().Errorw("Failed to marshal arguments", zap.Error(err))
}
logs = append(logs, &storage.TransactionLog{
TransactionHash: tx.Transaction.Hash.Value(),
TransactionIndex: tx.Transaction.Index.Value(),
BlockNumber: tx.Transaction.BlockNumber.Value(),
BlockSequenceId: 0,
Address: strings.ToLower(log.Address),
Arguments: string(argsJson),
EventName: log.EventName,
LogIndex: log.LogIndex,
})
}
}

result := m.Db.Model(&storage.TransactionLog{}).Clauses(clause.Returning{}).Create(&logs)

if result.Error != nil {
return nil, xerrors.Errorf("Failed to insert block transaction: %w", result.Error)
}
return logs, nil
}

type latestBlockNumber struct {
BlockNumber uint64
}
Expand Down Expand Up @@ -278,53 +182,6 @@ func (m *PostgresBlockStore) GetBlockByNumber(blockNumber uint64) (*storage.Bloc
return block, nil
}

func (m *PostgresBlockStore) DeleteTransactionLogsForBlock(blockNumber uint64) error {
result := m.Db.Where("block_number = ?", blockNumber).Delete(&storage.TransactionLog{})
if result.Error != nil {
return xerrors.Errorf("Failed to delete transaction logs: %w", result.Error)
}
return nil
}

func (m *PostgresBlockStore) GetTransactionByHash(txHash string) (*storage.Transaction, error) {
tx := &storage.Transaction{}

result := m.Db.Model(&tx).Where("transaction_hash = ?", strings.ToLower(txHash)).First(&tx)
if result.Error != nil {
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
return nil, nil
}
return nil, result.Error
}
return tx, nil
}

func (m *PostgresBlockStore) ListTransactionsForContractAddress(contractAddress string) ([]*storage.Transaction, error) {
contractAddress = strings.ToLower(contractAddress)
var txs []*storage.Transaction

result := m.Db.Model(&storage.Transaction{}).
Where("contract_address = ? or to_address = ?", contractAddress, contractAddress).
Find(&txs)
if result.Error != nil {
return nil, xerrors.Errorf("Failed to list transactions for contract address: %w", result.Error)
}
return txs, nil
}

func (m *PostgresBlockStore) ListTransactionLogsForContractAddress(contractAddress string) ([]*storage.TransactionLog, error) {
contractAddress = strings.ToLower(contractAddress)
var txLogs []*storage.TransactionLog

result := m.Db.Model(&storage.TransactionLog{}).
Where("address = ?", contractAddress).
Find(&txLogs)
if result.Error != nil {
return nil, xerrors.Errorf("Failed to list transaction logs for contract address: %w", result.Error)
}
return txLogs, nil
}

func (m *PostgresBlockStore) InsertOperatorRestakedStrategies(avsDirectorAddress string, blockNumber uint64, blockTime time.Time, operator string, avs string, strategy string) (*storage.OperatorRestakedStrategies, error) {
return pg.WrapTxAndCommit[*storage.OperatorRestakedStrategies](func(txn *gorm.DB) (*storage.OperatorRestakedStrategies, error) {
ors := &storage.OperatorRestakedStrategies{
Expand Down
24 changes: 0 additions & 24 deletions internal/storage/sqlite/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,20 @@ func NewSqliteBlockStore(db *gorm.DB, l *zap.Logger, cfg *config.Config) *Sqlite
}

/*
func (s *SqliteBlockStore) GetNextSequenceId() (uint64, error) {
}
func (s *SqliteBlockStore) InsertBlockAtHeight(blockNumber uint64, hash string, blockTime uint64) (*storage.Block, error) {
}
func (s *SqliteBlockStore) UpdateBlockPath(sequenceId uint64, blockNumber uint64, path string) (*storage.Block, error) {
}
func (s *SqliteBlockStore) InsertBlockTransaction(sequenceId uint64, blockNumber uint64, txHash string, txIndex uint64, from string, to string, contractAddress string, bytecodeHash string) (*storage.Transaction, error) {
}
func (s *SqliteBlockStore) InsertTransactionLog(txHash string, transactionIndex uint64, blockNumber uint64, blockSequenceId uint64, log *parser.DecodedLog, outputData map[string]interface{}) (*storage.Transaction, error) {
}
func (s *SqliteBlockStore) BatchInsertBlockTransactions(sequenceId uint64, blockNumber uint64, transactions []storage.BatchTransaction) ([]*storage.Transaction, error) {
}
func (s *SqliteBlockStore) BatchInsertTransactionLogs(transactions []*BatchInsertTransactionLogs) ([]*TransactionLog, error) {
}
func (s *SqliteBlockStore) GetLatestBlock() (int64, error) {
}
func (s *SqliteBlockStore) GetBlockByNumber(blockNumber uint64) (*Block, error) {
}
func (s *SqliteBlockStore) DeleteTransactionLogsForBlock(blockNumber uint64) error {
}
func (s *SqliteBlockStore) GetTransactionByHash(txHash string) (*Transaction, error) {
}
func (s *SqliteBlockStore) ListTransactionsForContractAddress(contractAddress string) ([]*Transaction, error) {
}
func (s *SqliteBlockStore) ListTransactionLogsForContractAddress(contractAddress string) ([]*TransactionLog, error) {
}
func (s *SqliteBlockStore) InsertOperatorRestakedStrategies(avsDirectorAddress string, blockNumber uint64, blockTime time.Time, operator string, avs string, strategy string) (*OperatorRestakedStrategies, error) {
Expand Down
26 changes: 0 additions & 26 deletions internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,19 @@ package storage
import (
"github.com/Layr-Labs/sidecar/internal/clients/ethereum"
"github.com/Layr-Labs/sidecar/internal/parser"
"gorm.io/gorm"
"time"
)

type BlockStore interface {
GetNextSequenceId() (uint64, error)
InsertBlockAtHeight(blockNumber uint64, hash string, blockTime uint64) (*Block, error)
UpdateBlockPath(sequenceId uint64, blockNumber uint64, path string) (*Block, error)
InsertBlockTransaction(sequenceId uint64, blockNumber uint64, txHash string, txIndex uint64, from string, to string, contractAddress string, bytecodeHash string) (*Transaction, error)
InsertTransactionLog(txHash string, transactionIndex uint64, blockNumber uint64, blockSequenceId uint64, log *parser.DecodedLog, outputData map[string]interface{}) (*TransactionLog, error)
BatchInsertBlockTransactions(sequenceId uint64, blockNumber uint64, transactions []BatchTransaction) ([]*Transaction, error)
BatchInsertTransactionLogs(transactions []*BatchInsertTransactionLogs) ([]*TransactionLog, error)
GetLatestBlock() (int64, error)
GetBlockByNumber(blockNumber uint64) (*Block, error)
DeleteTransactionLogsForBlock(blockNumber uint64) error
GetTransactionByHash(txHash string) (*Transaction, error)
ListTransactionsForContractAddress(contractAddress string) ([]*Transaction, error)
ListTransactionLogsForContractAddress(contractAddress string) ([]*TransactionLog, error)
InsertOperatorRestakedStrategies(avsDirectorAddress string, blockNumber uint64, blockTime time.Time, operator string, avs string, strategy string) (*OperatorRestakedStrategies, error)

GetDb() *gorm.DB

// Less generic functions
GetLatestActiveAvsOperators(blockNumber uint64, avsDirectoryAddress string) ([]*ActiveAvsOperator, error)

// State change functions
// InsertIntoAvsOperatorChangesForBlock(blockNumber uint64) error
// InsertIntoOperatorShareChangesForBlock(blockNumber uint64) error
// InsertIntoStakerShareChangesForBlock(blockNumber uint64) error
// InsertIntoStakerDelegationChangesForBlock(blockNumber uint64) error
// InsertIntoActiveRewardSubmissionsForBlock(blockNumber uint64) error
//
// // Aggregate table functions
// CloneRegisteredAvsOperatorsForNewBlock(newBlockNumber uint64) error
// CloneOperatorSharesForNewBlock(newBlockNumber uint64) error
// CloneStakerSharesForNewBlock(newBlockNumber uint64) error
// CloneDelegatedStakersForNewBlock(newBlockNumber uint64) error
// SetActiveRewardsForNewBlock(newBlockNumber uint64) error
// SetActiveRewardForAllForNewBlock(newBlockNumber uint64) error
}

// Tables
Expand Down

0 comments on commit 0766ac1

Please sign in to comment.