Skip to content

Commit

Permalink
fix: handle when there are no transactions in a block (#24)
Browse files Browse the repository at this point in the history
* fix: handle when there are no transactions in a block
  • Loading branch information
neilcampbell authored Mar 18, 2024
1 parent 0491b32 commit 67f48c9
Show file tree
Hide file tree
Showing 4 changed files with 502 additions and 370 deletions.
2 changes: 1 addition & 1 deletion docs/code/interfaces/types_block.Block.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ ___

### txns

**txns**: [`BlockTransaction`](types_block.BlockTransaction.md)[]
`Optional` **txns**: [`BlockTransaction`](types_block.BlockTransaction.md)[]

The transactions within the block.

Expand Down
2 changes: 1 addition & 1 deletion src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function getBlockTransactions(block: Block): TransactionInBlock[] {
let offset = 0
const getOffset = () => offset++

return block.txns.flatMap((blockTransaction, roundIndex) => {
return (block.txns ?? []).flatMap((blockTransaction, roundIndex) => {
let parentOffset = 0
const getParentOffset = () => parentOffset++
const parentData = extractTransactionFromBlockTransaction(blockTransaction, block)
Expand Down
2 changes: 1 addition & 1 deletion src/types/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface Block {
*/
txn256: string
/** The transactions within the block. */
txns: BlockTransaction[]
txns?: BlockTransaction[]
}

/** Data that is returned in a raw Algorand block for a single transaction
Expand Down
Loading

0 comments on commit 67f48c9

Please sign in to comment.