-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: status, participation and state interfaces
- Loading branch information
Showing
21 changed files
with
393 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package algod | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"github.com/algorandfoundation/algorun-tui/api" | ||
"time" | ||
) | ||
|
||
type BlockMetrics struct { | ||
AvgTime time.Duration | ||
TPS float64 | ||
} | ||
|
||
func GetBlockMetrics(ctx context.Context, client api.ClientWithResponsesInterface, round uint64, window int) (BlockMetrics, api.ResponseInterface, error) { | ||
var avgs = BlockMetrics{ | ||
AvgTime: 0, | ||
TPS: 0, | ||
} | ||
var format api.GetBlockParamsFormat = "json" | ||
|
||
// Current Block | ||
currentBlockResponse, err := client.GetBlockWithResponse(ctx, int(round), &api.GetBlockParams{ | ||
Format: &format, | ||
}) | ||
if err != nil { | ||
return avgs, currentBlockResponse, err | ||
} | ||
if currentBlockResponse.StatusCode() != 200 { | ||
return avgs, currentBlockResponse, errors.New(currentBlockResponse.Status()) | ||
} | ||
|
||
// Previous Block Response | ||
previousBlockResponse, err := client.GetBlockWithResponse(ctx, int(round)-window, &api.GetBlockParams{ | ||
Format: &format, | ||
}) | ||
if err != nil { | ||
return avgs, previousBlockResponse, err | ||
} | ||
if previousBlockResponse.StatusCode() != 200 { | ||
return avgs, previousBlockResponse, errors.New(previousBlockResponse.Status()) | ||
} | ||
|
||
// Push to the transactions count list | ||
aTimestampRes := currentBlockResponse.JSON200.Block["ts"] | ||
bTimestampRes := previousBlockResponse.JSON200.Block["ts"] | ||
if aTimestampRes == nil || bTimestampRes == nil { | ||
return avgs, previousBlockResponse, nil | ||
} | ||
aTimestamp := time.Duration(aTimestampRes.(float64)) * time.Second | ||
bTimestamp := time.Duration(bTimestampRes.(float64)) * time.Second | ||
|
||
// Transaction Counter | ||
aTransactions := currentBlockResponse.JSON200.Block["tc"] | ||
bTransactions := previousBlockResponse.JSON200.Block["tc"] | ||
|
||
avgs.AvgTime = time.Duration((int(aTimestamp - bTimestamp)) / window) | ||
if aTransactions != nil && bTransactions != nil { | ||
avgs.TPS = (aTransactions.(float64) - bTransactions.(float64)) / (float64(window) * avgs.AvgTime.Seconds()) | ||
} | ||
|
||
return avgs, currentBlockResponse, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package internal | ||
package algod | ||
|
||
import ( | ||
"context" | ||
|
Oops, something went wrong.