Skip to content

Commit 528223b

Browse files
authored
feat: include original block/TX object in chainsync events (#196)
This allows access to all underlying block/TX attributes when embedding snek as a library
1 parent 6c18d3b commit 528223b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

input/chainsync/block.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type BlockContext struct {
2525
}
2626

2727
type BlockEvent struct {
28+
Block ledger.Block `json:"-"`
2829
BlockBodySize uint64 `json:"blockBodySize"`
2930
IssuerVkey string `json:"issuerVkey"`
3031
BlockHash string `json:"blockHash"`
@@ -51,6 +52,7 @@ func NewBlockHeaderContext(block ledger.BlockHeader) BlockContext {
5152

5253
func NewBlockEvent(block ledger.Block, includeCbor bool) BlockEvent {
5354
evt := BlockEvent{
55+
Block: block,
5456
BlockBodySize: block.BlockBodySize(),
5557
BlockHash: block.Hash(),
5658
IssuerVkey: block.IssuerVkey().Hash().String(),

input/chainsync/tx.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type TransactionContext struct {
2828
}
2929

3030
type TransactionEvent struct {
31+
Transaction ledger.Transaction `json:"-"`
3132
BlockHash string `json:"blockHash"`
3233
TransactionCbor byteSliceJsonHex `json:"transactionCbor,omitempty"`
3334
Inputs []ledger.TransactionInput `json:"inputs"`
@@ -59,11 +60,12 @@ func NewTransactionEvent(
5960
includeCbor bool,
6061
) TransactionEvent {
6162
evt := TransactionEvent{
62-
BlockHash: block.Hash(),
63-
Inputs: tx.Inputs(),
64-
Outputs: tx.Outputs(),
65-
Fee: tx.Fee(),
66-
TTL: tx.TTL(),
63+
Transaction: tx,
64+
BlockHash: block.Hash(),
65+
Inputs: tx.Inputs(),
66+
Outputs: tx.Outputs(),
67+
Fee: tx.Fee(),
68+
TTL: tx.TTL(),
6769
}
6870
if includeCbor {
6971
evt.TransactionCbor = tx.Cbor()

0 commit comments

Comments
 (0)