cmd: add --last
to block-headers-range
example: $ monero daemon get-block-headers-range --last=10 | grep Transactions Number of Transactions: 6 Number of Transactions: 79 Number of Transactions: 93 Number of Transactions: 15 Number of Transactions: 74 Number of Transactions: 73 Number of Transactions: 11 Number of Transactions: 2 Number of Transactions: 20 Number of Transactions: 124 Number of Transactions: 158 Signed-off-by: Ciro S. Costa <utxobr@protonmail.com>
This commit is contained in:
parent
17ffb4aea4
commit
2eb47cf90f
|
@ -13,6 +13,7 @@ import (
|
|||
type getBlockHeadersRangeCommand struct {
|
||||
Start uint64
|
||||
End uint64
|
||||
Last uint64
|
||||
|
||||
JSON bool
|
||||
}
|
||||
|
@ -31,6 +32,8 @@ func (c *getBlockHeadersRangeCommand) Cmd() *cobra.Command {
|
|||
0, "height of the first block in the range")
|
||||
cmd.Flags().Uint64Var(&c.End, "end",
|
||||
0, "height the last block in the range")
|
||||
cmd.Flags().Uint64Var(&c.Last, "last",
|
||||
0, "get the last `n` block headers")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
@ -44,7 +47,18 @@ func (c *getBlockHeadersRangeCommand) RunE(_ *cobra.Command, _ []string) error {
|
|||
return fmt.Errorf("client: %w", err)
|
||||
}
|
||||
|
||||
resp, err := client.GetBlockHeadersRange(ctx, c.Start, c.End)
|
||||
start, end := c.Start, c.End
|
||||
if c.Last != 0 {
|
||||
heightResp, err := client.GetHeight(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get height: %w", err)
|
||||
}
|
||||
|
||||
end = heightResp.Height - 1
|
||||
start = end - c.Last
|
||||
}
|
||||
|
||||
resp, err := client.GetBlockHeadersRange(ctx, start, end)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get block header by height: %w", err)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package daemon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
|
@ -10,6 +11,8 @@ import (
|
|||
)
|
||||
|
||||
func prettyBlockHeader(table *uitable.Table, header daemon.BlockHeader) {
|
||||
timestamp := time.Unix(header.Timestamp, 0)
|
||||
|
||||
table.AddRow("Block Size:", humanize.Bytes(header.BlockSize))
|
||||
table.AddRow("Block Weight:", humanize.Bytes(header.BlockWeight))
|
||||
table.AddRow("Cumulative Difficulty:", header.CumulativeDifficulty)
|
||||
|
@ -29,7 +32,7 @@ func prettyBlockHeader(table *uitable.Table, header daemon.BlockHeader) {
|
|||
table.AddRow("Proof-of-Work Hash:", header.PowHash)
|
||||
table.AddRow("Previous Hash:", header.PrevHash)
|
||||
table.AddRow("Reward:", header.Reward)
|
||||
table.AddRow("Timestamp:", time.Unix(header.Timestamp, 0))
|
||||
table.AddRow("Timestamp:", fmt.Sprintf("%s (%s)", timestamp, humanize.Time(timestamp)))
|
||||
table.AddRow("Wide Cumulative Difficulty:", header.WideCumulativeDifficulty)
|
||||
table.AddRow("Wide Difficulty:", header.WideDifficulty)
|
||||
}
|
||||
|
|
Reference in a new issue