Skip to content

Commit

Permalink
API: Hotfix block endpoint (#1397)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Warehime authored Jan 3, 2023
1 parent 8c49730 commit 9379435
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 0 additions & 5 deletions api/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1359,11 +1359,6 @@ func (si *ServerImplementation) fetchBlock(ctx context.Context, round uint64, op

results := make([]generated.Transaction, 0)
for _, txrow := range transactions {
// Do not include inner transactions.
if txrow.RootTxn != nil {
continue
}

tx, err := txnRowToTransaction(txrow)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions idb/idb.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ type TransactionFilter struct {
// instead of the root txn.
ReturnInnerTxnOnly bool

// If this flag is set to true, then the query returns only root txns
// and no inner txns
ReturnRootTxnsOnly bool

// If this flag is set to true, then the query returns the block excluding
// the transactions
HeaderOnly bool
Expand Down
9 changes: 6 additions & 3 deletions idb/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func (db *IndexerDb) GetBlock(ctx context.Context, round uint64, options idb.Get

if options.Transactions {
out := make(chan idb.TxnRow, 1)
query, whereArgs, err := buildTransactionQuery(idb.TransactionFilter{Round: &round, Limit: options.MaxTransactionsLimit + 1})
query, whereArgs, err := buildTransactionQuery(idb.TransactionFilter{Round: &round, Limit: options.MaxTransactionsLimit + 1, ReturnRootTxnsOnly: true})
if err != nil {
err = fmt.Errorf("txn query err %v", err)
out <- idb.TxnRow{Error: err}
Expand Down Expand Up @@ -658,9 +658,12 @@ func buildTransactionQuery(tf idb.TransactionFilter) (query string, whereArgs []
if tf.RekeyTo != nil && (*tf.RekeyTo) {
whereParts = append(whereParts, "(t.txn -> 'txn' -> 'rekey') IS NOT NULL")
}
if tf.ReturnRootTxnsOnly {
whereParts = append(whereParts, "t.txid IS NOT NULL")
}

// If returnInnerTxnOnly flag is false, then return the root transaction
if !tf.ReturnInnerTxnOnly {
if !(tf.ReturnInnerTxnOnly || tf.ReturnRootTxnsOnly) {
query = "SELECT t.round, t.intra, t.txn, root.txn, t.extra, t.asset, h.realtime FROM txn t JOIN block_header h ON t.round = h.round"
} else {
query = "SELECT t.round, t.intra, t.txn, NULL, t.extra, t.asset, h.realtime FROM txn t JOIN block_header h ON t.round = h.round"
Expand All @@ -671,7 +674,7 @@ func buildTransactionQuery(tf idb.TransactionFilter) (query string, whereArgs []
}

// join in the root transaction if the returnInnerTxnOnly flag is false
if !tf.ReturnInnerTxnOnly {
if !(tf.ReturnInnerTxnOnly || tf.ReturnRootTxnsOnly) {
query += " LEFT OUTER JOIN txn root ON t.round = root.round AND (t.extra->>'root-intra')::int = root.intra"
}

Expand Down

0 comments on commit 9379435

Please sign in to comment.