Skip to content

Commit

Permalink
rpcv03 pending block support
Browse files Browse the repository at this point in the history
  • Loading branch information
rianhughes committed Aug 22, 2023
1 parent e409e6e commit 30e7fa1
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func WithBlockTag(tag string) BlockID {
}

// BlockWithTxHashes gets block information given the block id.
// TODO: add support for PendingBlock
func (provider *Provider) BlockWithTxHashes(ctx context.Context, blockID BlockID) (interface{}, error) {
var result Block
if err := do(ctx, provider.c, "starknet_getBlockWithTxHashes", &result, blockID); err != nil {
Expand All @@ -59,6 +58,17 @@ func (provider *Provider) BlockWithTxHashes(ctx context.Context, blockID BlockID
}
return nil, err
}

// if header.Hash == nil it's a pending block
if result.BlockHeader.BlockHash == nil {
return PendingBlock{
ParentHash: result.ParentHash,
Timestamp: result.Timestamp,
SequencerAddress: result.SequencerAddress,
Transactions: result.Transactions,
}, nil
}

return &result, nil
}

Expand Down Expand Up @@ -95,5 +105,14 @@ func (provider *Provider) BlockWithTxs(ctx context.Context, blockID BlockID) (in
}
return nil, err
}
// if header.Hash == nil it's a pending block
if result.BlockHeader.BlockHash == nil {
return PendingBlock{
ParentHash: result.ParentHash,
Timestamp: result.Timestamp,
SequencerAddress: result.SequencerAddress,
Transactions: result.Transactions,
}, nil
}
return &result, nil
}

0 comments on commit 30e7fa1

Please sign in to comment.