From c0ebe4ea40f8bd49b5200d8227667c2019d3444d Mon Sep 17 00:00:00 2001 From: Ales Verbic Date: Sun, 29 Oct 2023 10:55:16 -0400 Subject: [PATCH] feat: add transaction count to chainsync Block event Signed-off-by: Ales Verbic --- input/chainsync/block.go | 16 +++++++++------- output/notify/notify.go | 3 ++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/input/chainsync/block.go b/input/chainsync/block.go index dd6c7da..9eddeb7 100644 --- a/input/chainsync/block.go +++ b/input/chainsync/block.go @@ -25,10 +25,11 @@ type BlockContext struct { } type BlockEvent struct { - BlockBodySize uint64 `json:"blockBodySize"` - IssuerVkey string `json:"issuerVkey"` - BlockHash string `json:"blockHash"` - BlockCbor byteSliceJsonHex `json:"blockCbor,omitempty"` + BlockBodySize uint64 `json:"blockBodySize"` + IssuerVkey string `json:"issuerVkey"` + BlockHash string `json:"blockHash"` + BlockCbor byteSliceJsonHex `json:"blockCbor,omitempty"` + TransactionCount uint64 `json:"transactionCount"` } func NewBlockContext(block ledger.Block, networkMagic uint32) BlockContext { @@ -50,9 +51,10 @@ func NewBlockHeaderContext(block ledger.BlockHeader) BlockContext { func NewBlockEvent(block ledger.Block, includeCbor bool) BlockEvent { evt := BlockEvent{ - BlockBodySize: block.BlockBodySize(), - BlockHash: block.Hash(), - IssuerVkey: block.IssuerVkey().Hash().String(), + BlockBodySize: block.BlockBodySize(), + BlockHash: block.Hash(), + IssuerVkey: block.IssuerVkey().Hash().String(), + TransactionCount: uint64(len(block.Transactions())), } if includeCbor { evt.BlockCbor = block.Cbor() diff --git a/output/notify/notify.go b/output/notify/notify.go index c3d61e8..e454df7 100644 --- a/output/notify/notify.go +++ b/output/notify/notify.go @@ -65,9 +65,10 @@ func (n *NotifyOutput) Start() error { err := beeep.Notify( n.title, fmt.Sprintf( - "New Block!\nBlockNumber: %d, SlotNumber: %d\nHash: %s", + "New Block!\nBlockNumber: %d, SlotNumber: %d, TransactionCount: %d\nHash: %s", bc.BlockNumber, bc.SlotNumber, + be.TransactionCount, be.BlockHash, ), "assets/snek-icon.png",