Skip to content

Commit

Permalink
add transaction method to store
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Jan 9, 2024
1 parent 7acd3b2 commit ab66e8d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions explorer/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Store interface {
Tip() (types.ChainIndex, error)
BlockByID(id types.BlockID) (types.Block, error)
BlockByHeight(height uint64) (types.Block, error)
Transaction(id types.TransactionID) (types.Transaction, error)
}

// Explorer implements a Sia explorer.
Expand All @@ -39,3 +40,8 @@ func (e *Explorer) BlockByID(id types.BlockID) (types.Block, error) {
func (e *Explorer) BlockByHeight(height uint64) (types.Block, error) {
return e.s.BlockByHeight(height)
}

// Transaction returns the transaction with the specified ID.
func (e *Explorer) Transaction(id types.TransactionID) (types.Transaction, error) {
return e.s.Transaction(id)
}
11 changes: 11 additions & 0 deletions persist/sqlite/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,14 @@ func (s *Store) BlockByHeight(height uint64) (result types.Block, err error) {
result, err = s.BlockByID(bid)
return
}

// Transaction implements explorer.Store.
func (s *Store) Transaction(id types.TransactionID) (result types.Transaction, err error) {
var txnID int64
if err = s.queryRow("SELECT id FROM transactions WHERE transaction_id = ?", encode(id)).Scan(&txnID); err != nil {
return
}

result, err = s.transactionByID(txnID)
return
}
1 change: 1 addition & 0 deletions persist/sqlite/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func (s *Store) addTransactions(tx txn, bid types.BlockID, txns []types.Transact
if err != nil {
return err
}

if _, err := tx.Exec("INSERT INTO block_transactions(block_id, transaction_id, block_order) VALUES (?, ?, ?)", encode(bid), txnID, i); err != nil {
return err
} else if err := s.addArbitraryData(tx, txnID, txn); err != nil {
Expand Down

0 comments on commit ab66e8d

Please sign in to comment.