diff --git a/api/client.go b/api/client.go index 5cc43985..bd3e30a9 100644 --- a/api/client.go +++ b/api/client.go @@ -124,7 +124,9 @@ func (c *Client) Transactions(ids []types.TransactionID) (resp []explorer.Transa return } -func (c *Client) TransactionIndices(id types.TransactionID, offset, limit uint64) (resp []types.ChainIndex, err error) { +// TransactionChainIndices returns chain indices a transaction was +// included in. +func (c *Client) TransactionChainIndices(id types.TransactionID, offset, limit uint64) (resp []types.ChainIndex, err error) { err = c.c.GET(fmt.Sprintf("/transactions/%s/indices?offset=%d&limit=%d", id, offset, limit), &resp) return } diff --git a/api/server.go b/api/server.go index 6a058b73..1092513c 100644 --- a/api/server.go +++ b/api/server.go @@ -53,7 +53,7 @@ type ( Metrics(id types.BlockID) (explorer.Metrics, error) HostMetrics() (explorer.HostMetrics, error) Transactions(ids []types.TransactionID) ([]explorer.Transaction, error) - TransactionIndices(id types.TransactionID, offset, limit uint64) ([]types.ChainIndex, error) + TransactionChainIndices(id types.TransactionID, offset, limit uint64) ([]types.ChainIndex, error) Balance(address types.Address) (sc types.Currency, immatureSC types.Currency, sf uint64, err error) SiacoinElements(ids []types.SiacoinOutputID) (result []explorer.SiacoinOutput, err error) SiafundElements(ids []types.SiafundOutputID) (result []explorer.SiafundOutput, err error) @@ -279,7 +279,7 @@ func (s *server) transactionsIDIndicesHandler(jc jape.Context) { limit = 500 } - indices, err := s.e.TransactionIndices(id, offset, limit) + indices, err := s.e.TransactionChainIndices(id, offset, limit) if jc.Check("failed to get transaction indices", err) != nil { return } diff --git a/explorer/explorer.go b/explorer/explorer.go index d48bfb4a..c26299e2 100644 --- a/explorer/explorer.go +++ b/explorer/explorer.go @@ -45,7 +45,7 @@ type Store interface { Metrics(id types.BlockID) (Metrics, error) HostMetrics() (HostMetrics, error) Transactions(ids []types.TransactionID) ([]Transaction, error) - TransactionIndices(txid types.TransactionID, offset, limit uint64) ([]types.ChainIndex, error) + TransactionChainIndices(txid types.TransactionID, offset, limit uint64) ([]types.ChainIndex, error) UnspentSiacoinOutputs(address types.Address, offset, limit uint64) ([]SiacoinOutput, error) UnspentSiafundOutputs(address types.Address, offset, limit uint64) ([]SiafundOutput, error) AddressEvents(address types.Address, offset, limit uint64) (events []Event, err error) @@ -197,8 +197,11 @@ func (e *Explorer) Transactions(ids []types.TransactionID) ([]Transaction, error return e.s.Transactions(ids) } -func (e *Explorer) TransactionIndices(id types.TransactionID, offset, limit uint64) ([]types.ChainIndex, error) { - return e.s.TransactionIndices(id, offset, limit) +// TransactionChainIndices returns the chain indices of the blocks the transaction +// was included in. If the transaction has not been included in any blocks, the +// result will be nil,nil. +func (e *Explorer) TransactionChainIndices(id types.TransactionID, offset, limit uint64) ([]types.ChainIndex, error) { + return e.s.TransactionChainIndices(id, offset, limit) } // UnspentSiacoinOutputs returns the unspent siacoin outputs owned by the diff --git a/persist/sqlite/consensus_test.go b/persist/sqlite/consensus_test.go index a3772dd0..34292fb0 100644 --- a/persist/sqlite/consensus_test.go +++ b/persist/sqlite/consensus_test.go @@ -413,7 +413,7 @@ func TestSendTransactions(t *testing.T) { } checkChainIndices := func(t *testing.T, txnID types.TransactionID, expected []types.ChainIndex) { - indices, err := db.TransactionIndices(txnID, 0, 100) + indices, err := db.TransactionChainIndices(txnID, 0, 100) switch { case err != nil: t.Fatal(err) @@ -1639,7 +1639,7 @@ func TestRevertSendTransactions(t *testing.T) { } checkChainIndices := func(t *testing.T, txnID types.TransactionID, expected []types.ChainIndex) { - indices, err := db.TransactionIndices(txnID, 0, 100) + indices, err := db.TransactionChainIndices(txnID, 0, 100) switch { case err != nil: t.Fatal(err) diff --git a/persist/sqlite/transactions.go b/persist/sqlite/transactions.go index 28d7d3a2..801d7d16 100644 --- a/persist/sqlite/transactions.go +++ b/persist/sqlite/transactions.go @@ -7,10 +7,10 @@ import ( "go.sia.tech/explored/explorer" ) -// transactionChainIndices returns the chain indices of the blocks the transaction +// TransactionChainIndices returns the chain indices of the blocks the transaction // was included in. If the transaction has not been included in any blocks, the // result will be nil,nil. -func (s *Store) TransactionIndices(txnID types.TransactionID, offset, limit uint64) (indices []types.ChainIndex, err error) { +func (s *Store) TransactionChainIndices(txnID types.TransactionID, offset, limit uint64) (indices []types.ChainIndex, err error) { err = s.transaction(func(tx *txn) error { rows, err := tx.Query(`SELECT DISTINCT b.id, b.height FROM blocks b INNER JOIN block_transactions bt ON (bt.block_id = b.id)