Skip to content

Commit

Permalink
fix #23 get import tx weight from output tx (#24)
Browse files Browse the repository at this point in the history
* fix #23 get import tx weight from output tx

* fix pointer deref causing 404 on Validator Data
  • Loading branch information
dqnk authored Apr 3, 2024
1 parent 3026510 commit de2044d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 7 additions & 1 deletion services/api/pchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,16 @@ func newApiPChainBlockTxs(txs []database.PChainTxInOutAmountsData) []ApiPChainBl
if tx.TxID == nil {
continue
}

txWeight := tx.Weight
if tx.Type == database.PChainImportTx || tx.Type == database.PChainExportTx {

switch tx.Type {
case database.PChainImportTx:
txWeight = tx.OutputAmount
case database.PChainExportTx:
txWeight = tx.ExportAmount
}

result = append(result, ApiPChainBlockTx{
TxID: *tx.TxID,
Type: tx.Type,
Expand Down
16 changes: 14 additions & 2 deletions services/routes/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ func (rh *stakerRouteHandlers) listValidators() utils.RouteHandler {
return nil, utils.InternalServerErrorHandler(err)
}

// if node is not found in node_uptimes, this could be null
uptime := 1.0
if status.StakingStart != nil {
uptime = float64(status.Uptime) / float64(now.Sub(*status.StakingStart))
}

validators[i] = Validator{
TxID: *tx.TxID,
NodeID: tx.NodeID,
Expand All @@ -193,7 +199,7 @@ func (rh *stakerRouteHandlers) listValidators() utils.RouteHandler {
Delegators: delegatorsPerNode[tx.NodeID],
Online: status.Online,
CurrentEpoch: status.Epoch,
Uptime: float64(status.Uptime) / float64(now.Sub(*status.StakingStart)),
Uptime: uptime,
}
}

Expand Down Expand Up @@ -262,12 +268,18 @@ func (rh *stakerRouteHandlers) getValidatorData() utils.RouteHandler {
return nil, utils.InternalServerErrorHandler(err)
}

// if node is not found in node_uptimes, this could be null
uptime := 1.0
if status.StakingStart != nil {
uptime = float64(status.Uptime) / float64(now.Sub(*status.StakingStart))
}

resp := Validator{
NodeID: node_id,
Delegators: delegatorsPerNode[node_id],
Delegations: delegations,
CurrentEpoch: status.Epoch,
Uptime: float64(status.Uptime) / float64(now.Sub(*status.StakingStart)),
Uptime: uptime,
Online: status.Online,
}

Expand Down

0 comments on commit de2044d

Please sign in to comment.