From de2044d7258bcb4f454fda8aa0160e53aed986ac Mon Sep 17 00:00:00 2001 From: dqnk <64268180+dqnk@users.noreply.github.com> Date: Wed, 3 Apr 2024 15:02:06 +0200 Subject: [PATCH] fix #23 get import tx weight from output tx (#24) * fix #23 get import tx weight from output tx * fix pointer deref causing 404 on Validator Data --- services/api/pchain.go | 8 +++++++- services/routes/staking.go | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/services/api/pchain.go b/services/api/pchain.go index 89ee963..67760f9 100644 --- a/services/api/pchain.go +++ b/services/api/pchain.go @@ -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, diff --git a/services/routes/staking.go b/services/routes/staking.go index cc91fc2..eb67275 100644 --- a/services/routes/staking.go +++ b/services/routes/staking.go @@ -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, @@ -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, } } @@ -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, }