Skip to content

Commit

Permalink
fix(v1): only sort deposits by timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbitfly committed Jan 16, 2025
1 parent 95a741a commit 97681c8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 61 deletions.
28 changes: 4 additions & 24 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,25 +196,15 @@ func ApplyEmbeddedDbSchema(version int64) error {
return nil
}

func GetEth1DepositsJoinEth2Deposits(query string, length, start uint64, orderBy, orderDir string, latestEpoch, validatorOnlineThresholdSlot uint64) ([]*types.EthOneDepositsData, uint64, error) {
func GetEth1DepositsJoinEth2Deposits(query string, length, start uint64, orderDir string, latestEpoch, validatorOnlineThresholdSlot uint64) ([]*types.EthOneDepositsData, uint64, error) {
// Initialize the return values
deposits := []*types.EthOneDepositsData{}
totalCount := uint64(0)

if orderDir != "desc" && orderDir != "asc" {
orderDir = "desc"
}
columns := []string{"tx_hash", "tx_input", "tx_index", "block_number", "block_ts", "from_address", "publickey", "withdrawal_credentials", "amount", "signature", "merkletree_index", "state", "valid_signature"}
hasColumn := false
for _, column := range columns {
if orderBy == column {
hasColumn = true
break
}
}
if !hasColumn {
orderBy = "block_ts"
}
orderBy := "block_ts"

var param interface{}
var searchQuery string
Expand Down Expand Up @@ -378,25 +368,15 @@ func GetEth1DepositsLeaderboard(query string, length, start uint64, orderBy, ord
return deposits, totalCount, nil
}

func GetEth2Deposits(query string, length, start uint64, orderBy, orderDir string) ([]*types.EthTwoDepositData, uint64, error) {
func GetEth2Deposits(query string, length, start uint64, orderDir string) ([]*types.EthTwoDepositData, uint64, error) {
// Initialize the return values
deposits := []*types.EthTwoDepositData{}
totalCount := uint64(0)

if orderDir != "desc" && orderDir != "asc" {
orderDir = "desc"
}
columns := []string{"block_slot", "publickey", "amount", "withdrawalcredentials", "signature"}
hasColumn := false
for _, column := range columns {
if orderBy == column {
hasColumn = true
break
}
}
if !hasColumn {
orderBy = "block_slot"
}
orderBy := "block_slot"

var param interface{}
var searchQuery string
Expand Down
20 changes: 1 addition & 19 deletions handlers/eth1Deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,12 @@ func Eth1DepositsData(w http.ResponseWriter, r *http.Request) {
if length > 100 {
length = 100
}

orderColumn := q.Get("order[0][column]")
orderByMap := map[string]string{
"0": "from_address",
"1": "publickey",
"2": "withdrawal_credential",
"3": "amount",
"4": "tx_hash",
"5": "block_ts",
"6": "block_number",
"7": "state",
"8": "valid_signature",
}
orderBy, exists := orderByMap[orderColumn]
if !exists {
orderBy = "block_ts"
}

orderDir := q.Get("order[0][dir]")

latestEpoch := services.LatestEpoch()
validatorOnlineThresholdSlot := GetValidatorOnlineThresholdSlot()

deposits, depositCount, err := db.GetEth1DepositsJoinEth2Deposits(search, length, start, orderBy, orderDir, latestEpoch, validatorOnlineThresholdSlot)
deposits, depositCount, err := db.GetEth1DepositsJoinEth2Deposits(search, length, start, orderDir, latestEpoch, validatorOnlineThresholdSlot)
if err != nil {
logger.Errorf("GetEth1Deposits error retrieving eth1_deposit data: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
Expand Down
17 changes: 1 addition & 16 deletions handlers/eth2Deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,9 @@ func Eth2DepositsData(w http.ResponseWriter, r *http.Request) {
if length > 100 {
length = 100
}

orderColumn := q.Get("order[0][column]")
orderByMap := map[string]string{
"0": "block_slot",
// "1": "validatorindex",
"1": "publickey",
"2": "amount",
"3": "withdrawalcredentials",
"4": "signature",
}
orderBy, exists := orderByMap[orderColumn]
if !exists {
orderBy = "block_ts"
}

orderDir := q.Get("order[0][dir]")

deposits, depositCount, err := db.GetEth2Deposits(search, length, start, orderBy, orderDir)
deposits, depositCount, err := db.GetEth2Deposits(search, length, start, orderDir)
if err != nil {
logger.Errorf("error retrieving eth2_deposit data or count: %v", err)
http.Error(w, "Internal server error", http.StatusInternalServerError)
Expand Down
20 changes: 18 additions & 2 deletions templates/deposits.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
stateLoadCallback: function (settings) {
return JSON.parse(localStorage.getItem("DataTables_" + settings.sInstance))
},
order: [[6, 'desc']],
order: [[5, 'desc']],
searching: true,
ajax: dataTableLoader('/validators/initiated-deposits/data'),
pagingType: 'input',
Expand All @@ -43,7 +43,18 @@
previous: '<i class="fas fa-chevron-left"></i>',
next: '<i class="fas fa-chevron-right"></i>'
}
}
},
columnDefs: [
{ orderable: false, targets: 0 },
{ orderable: false, targets: 1 },
{ orderable: false, targets: 2 },
{ orderable: false, targets: 3 },
{ orderable: false, targets: 4 },
{ orderable: true, targets: 5 },
{ orderable: false, targets: 6 },
{ orderable: false, targets: 7 },
{ orderable: false, targets: 8 }
],
})
{{end}}
var tblIncluded = $("#included-deposits").DataTable({
Expand Down Expand Up @@ -75,8 +86,12 @@
$('[data-toggle="tooltip"]').tooltip()
},
columnDefs: [
{ orderable: true, targets: 0 },
{ orderable: false, targets: 1 },
{ orderable: false, targets: 2 },
{
targets: 3,
orderable: false,
data: "3",
render: function (data, type, row, meta) {
// make the span we get from the backend into a DOM element and extract the text value from it (because clipboard text takes only string, not HTML elements)
Expand All @@ -89,6 +104,7 @@
},
{
targets: 4,
orderable: false,
data: "4",
render: function (data, type, row, meta) {
const clipboardtext = $(row[6]).text()
Expand Down

0 comments on commit 97681c8

Please sign in to comment.