3939
4040public class BlockResultFactory {
4141
42+ // region BlockResult
43+
4244 public BlockResult transactionComplete (
4345 final BlockWithMetadata <TransactionWithMetadata , Hash > blockWithMetadata ) {
4446 return transactionComplete (blockWithMetadata , false );
@@ -103,21 +105,44 @@ public BlockResult transactionComplete(final Block block) {
103105 block .getBody ().getBlockAccessList ());
104106 }
105107
108+ public BlockResult transactionHash (final BlockWithMetadata <Hash , Hash > blockWithMetadata ) {
109+ return transactionHash (blockWithMetadata , false );
110+ }
111+
112+ public BlockResult transactionHash (
113+ final BlockWithMetadata <Hash , Hash > blockWithMetadata , final boolean includeCoinbase ) {
114+ final List <TransactionResult > txs =
115+ blockWithMetadata .getTransactions ().stream ()
116+ .map (Hash ::toString )
117+ .map (TransactionHashResult ::new )
118+ .collect (Collectors .toList ());
119+ final List <JsonNode > ommers =
120+ blockWithMetadata .getOmmers ().stream ()
121+ .map (Hash ::toString )
122+ .map (TextNode ::new )
123+ .collect (Collectors .toList ());
124+ // TODO: Pass BAL once part of the block interface
125+ return new BlockResult (
126+ blockWithMetadata .getHeader (),
127+ txs ,
128+ ommers ,
129+ blockWithMetadata .getTotalDifficulty (),
130+ blockWithMetadata .getSize (),
131+ includeCoinbase ,
132+ blockWithMetadata .getWithdrawals (),
133+ Optional .empty ());
134+ }
135+
136+ // endregion BlockResult
137+
138+ // region EngineGetPayloadResult
139+
106140 public EngineGetPayloadResultV1 payloadTransactionCompleteV1 (final Block block ) {
107141 final List <String > txs = txsAsHex (block );
108142
109143 return new EngineGetPayloadResultV1 (block .getHeader (), txs );
110144 }
111145
112- private static List <String > txsAsHex (final Block block ) {
113- return block .getBody ().getTransactions ().stream ()
114- .map (
115- transaction ->
116- TransactionEncoder .encodeOpaqueBytes (transaction , EncodingContext .BLOCK_BODY ))
117- .map (b -> HexUtils .toFastHex (b , true ))
118- .collect (Collectors .toList ());
119- }
120-
121146 public EngineGetPayloadResultV2 payloadTransactionCompleteV2 (final PayloadWrapper payload ) {
122147 final var blockWithReceipts = payload .blockWithReceipts ();
123148 final Block block = blockWithReceipts .getBlock ();
@@ -130,15 +155,6 @@ public EngineGetPayloadResultV2 payloadTransactionCompleteV2(final PayloadWrappe
130155 Quantity .create (payload .blockValue ()));
131156 }
132157
133- public EngineGetPayloadBodiesResultV1 payloadBodiesCompleteV1 (
134- final List <Optional <BlockBody >> blockBodies ) {
135- final List <PayloadBody > payloadBodies =
136- blockBodies .stream ()
137- .map (maybeBody -> maybeBody .map (PayloadBody ::new ).orElse (null ))
138- .collect (Collectors .toList ());
139- return new EngineGetPayloadBodiesResultV1 (payloadBodies );
140- }
141-
142158 public EngineGetPayloadResultV3 payloadTransactionCompleteV3 (final PayloadWrapper payload ) {
143159 final var blockWithReceipts = payload .blockWithReceipts ();
144160 final List <String > txs = txsAsHex (blockWithReceipts .getBlock ());
@@ -169,19 +185,6 @@ public EngineGetPayloadResultV4 payloadTransactionCompleteV4(final PayloadWrappe
169185 blobsBundleV1 );
170186 }
171187
172- private static Optional <List <String >> requestsAsHex (final PayloadWrapper payload ) {
173- return payload
174- .requests ()
175- .map (
176- rqs ->
177- rqs .stream ()
178- .sorted (Comparator .comparing (Request ::getType ))
179- .filter (r -> !r .getData ().isEmpty ())
180- .map (Request ::getEncodedRequest )
181- .map (b -> HexUtils .toFastHex (b , true ))
182- .toList ());
183- }
184-
185188 public EngineGetPayloadResultV5 payloadTransactionCompleteV5 (final PayloadWrapper payload ) {
186189 final var blockWithReceipts = payload .blockWithReceipts ();
187190 final List <String > txs = txsAsHex (blockWithReceipts .getBlock ());
@@ -229,31 +232,40 @@ public EngineGetPayloadResultV6 payloadTransactionCompleteV6(final PayloadWrappe
229232 blockAccessList );
230233 }
231234
232- public BlockResult transactionHash (final BlockWithMetadata <Hash , Hash > blockWithMetadata ) {
233- return transactionHash (blockWithMetadata , false );
235+ private static List <String > txsAsHex (final Block block ) {
236+ return block .getBody ().getTransactions ().stream ()
237+ .map (
238+ transaction ->
239+ TransactionEncoder .encodeOpaqueBytes (transaction , EncodingContext .BLOCK_BODY ))
240+ .map (b -> HexUtils .toFastHex (b , true ))
241+ .collect (Collectors .toList ());
234242 }
235243
236- public BlockResult transactionHash (
237- final BlockWithMetadata <Hash , Hash > blockWithMetadata , final boolean includeCoinbase ) {
238- final List <TransactionResult > txs =
239- blockWithMetadata .getTransactions ().stream ()
240- .map (Hash ::toString )
241- .map (TransactionHashResult ::new )
242- .collect (Collectors .toList ());
243- final List <JsonNode > ommers =
244- blockWithMetadata .getOmmers ().stream ()
245- .map (Hash ::toString )
246- .map (TextNode ::new )
244+ private static Optional <List <String >> requestsAsHex (final PayloadWrapper payload ) {
245+ return payload
246+ .requests ()
247+ .map (
248+ rqs ->
249+ rqs .stream ()
250+ .sorted (Comparator .comparing (Request ::getType ))
251+ .filter (r -> !r .getData ().isEmpty ())
252+ .map (Request ::getEncodedRequest )
253+ .map (b -> HexUtils .toFastHex (b , true ))
254+ .toList ());
255+ }
256+
257+ // endregion EngineGetPayloadResult
258+
259+ // region EngineGetPayloadBodiesResult
260+
261+ public EngineGetPayloadBodiesResultV1 payloadBodiesCompleteV1 (
262+ final List <Optional <BlockBody >> blockBodies ) {
263+ final List <PayloadBody > payloadBodies =
264+ blockBodies .stream ()
265+ .map (maybeBody -> maybeBody .map (PayloadBody ::new ).orElse (null ))
247266 .collect (Collectors .toList ());
248- // TODO: Pass BAL once part of the block interface
249- return new BlockResult (
250- blockWithMetadata .getHeader (),
251- txs ,
252- ommers ,
253- blockWithMetadata .getTotalDifficulty (),
254- blockWithMetadata .getSize (),
255- includeCoinbase ,
256- blockWithMetadata .getWithdrawals (),
257- Optional .empty ());
267+ return new EngineGetPayloadBodiesResultV1 (payloadBodies );
258268 }
269+
270+ // endregion EngineGetPayloadBodiesResult
259271}
0 commit comments