-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
evm_transactions_controller.go
49 lines (41 loc) · 1.43 KB
/
evm_transactions_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package web
import (
"database/sql"
"net/http"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/web/presenters"
"github.com/ethereum/go-ethereum/common"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
)
// TransactionsController displays Ethereum transactions requests.
type TransactionsController struct {
App chainlink.Application
}
// Index returns paginated transactions
func (tc *TransactionsController) Index(c *gin.Context, size, page, offset int) {
txs, count, err := tc.App.TxmStorageService().TransactionsWithAttempts(offset, size)
ptxs := make([]presenters.EthTxResource, len(txs))
for i, tx := range txs {
tx.TxAttempts[0].Tx = tx
ptxs[i] = presenters.NewEthTxResourceFromAttempt(tx.TxAttempts[0])
}
paginatedResponse(c, "transactions", size, page, ptxs, count, err)
}
// Show returns the details of a Ethereum Transaction details.
// Example:
//
// "<application>/transactions/:TxHash"
func (tc *TransactionsController) Show(c *gin.Context) {
hash := common.HexToHash(c.Param("TxHash"))
ethTxAttempt, err := tc.App.TxmStorageService().FindTxAttempt(hash)
if errors.Is(err, sql.ErrNoRows) {
jsonAPIError(c, http.StatusNotFound, errors.New("Transaction not found"))
return
}
if err != nil {
jsonAPIError(c, http.StatusInternalServerError, err)
return
}
jsonAPIResponse(c, presenters.NewEthTxResourceFromAttempt(*ethTxAttempt), "transaction")
}