Skip to content

Commit

Permalink
feat: include original block/TX object in chainsync events
Browse files Browse the repository at this point in the history
This allows access to all underlying block/TX attributes when embedding
snek as a library
  • Loading branch information
agaffney committed May 3, 2024
1 parent 6c18d3b commit 44046c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions input/chainsync/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type BlockContext struct {
}

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

func NewBlockEvent(block ledger.Block, includeCbor bool) BlockEvent {
evt := BlockEvent{
Block: block,
BlockBodySize: block.BlockBodySize(),
BlockHash: block.Hash(),
IssuerVkey: block.IssuerVkey().Hash().String(),
Expand Down
12 changes: 7 additions & 5 deletions input/chainsync/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type TransactionContext struct {
}

type TransactionEvent struct {
Transaction ledger.Transaction `json:"-"`
BlockHash string `json:"blockHash"`
TransactionCbor byteSliceJsonHex `json:"transactionCbor,omitempty"`
Inputs []ledger.TransactionInput `json:"inputs"`
Expand Down Expand Up @@ -59,11 +60,12 @@ func NewTransactionEvent(
includeCbor bool,
) TransactionEvent {
evt := TransactionEvent{
BlockHash: block.Hash(),
Inputs: tx.Inputs(),
Outputs: tx.Outputs(),
Fee: tx.Fee(),
TTL: tx.TTL(),
Transaction: tx,
BlockHash: block.Hash(),
Inputs: tx.Inputs(),
Outputs: tx.Outputs(),
Fee: tx.Fee(),
TTL: tx.TTL(),
}
if includeCbor {
evt.TransactionCbor = tx.Cbor()
Expand Down

0 comments on commit 44046c7

Please sign in to comment.