@ -28,7 +28,9 @@ public class BlockBody implements org.hyperledger.besu.plugin.data.BlockBody {
new BlockBody ( Collections . emptyList ( ) , Collections . emptyList ( ) ) ;
/ * *
* Adding a new field with a corresponding root hash in the block header will require a change in
* { @link org . hyperledger . besu . ethereum . eth . manager . task . GetBodiesFromPeerTask . BodyIdentifier }
* { @link org . hyperledger . besu . ethereum . eth . manager . task . GetBodiesFromPeerTask . BodyIdentifier }
* Also requires adding the new field to the constructor used in the { @link
* org . hyperledger . besu . ethereum . util . RawBlockIterator }
* /
private final List < Transaction > transactions ;
@ -99,23 +101,35 @@ public class BlockBody implements org.hyperledger.besu.plugin.data.BlockBody {
*
* @param output Output to write to
* /
public void writeTo ( final RLPOutput output ) {
public void writeWrappedBody To ( final RLPOutput output ) {
output . startList ( ) ;
writeTo ( output ) ;
output . endList ( ) ;
}
public void writeTo ( final RLPOutput output ) {
output . writeList ( getTransactions ( ) , Transaction : : writeTo ) ;
output . writeList ( getOmmers ( ) , BlockHeader : : writeTo ) ;
withdrawals . ifPresent ( withdrawals - > output . writeList ( withdrawals , Withdrawal : : writeTo ) ) ;
deposits . ifPresent ( deposits - > output . writeList ( deposits , Deposit : : writeTo ) ) ;
output . endList ( ) ;
}
public static BlockBody readFrom (
public static BlockBody readWrappedBody From (
final RLPInput input , final BlockHeaderFunctions blockHeaderFunctions ) {
return readFrom ( input , blockHeaderFunctions , false ) ;
return readWrappedBody From ( input , blockHeaderFunctions , false ) ;
}
public static BlockBody readFrom (
/ * *
* Read all fields from the block body expecting a list wrapping them An example of valid body
* structure that this method would be able to read is : [ [ txs ] , [ ommers ] , [ withdrawals ] ] This is
* used for decoding list of bodies
*
* @param input The RLP - encoded input
* @param blockHeaderFunctions The block header functions used for parsing block headers
* @param allowEmptyBody A flag indicating whether an empty body is allowed
* @return the decoded BlockBody from the RLP
* /
public static BlockBody readWrappedBodyFrom (
final RLPInput input ,
final BlockHeaderFunctions blockHeaderFunctions ,
final boolean allowEmptyBody ) {
@ -125,21 +139,33 @@ public class BlockBody implements org.hyperledger.besu.plugin.data.BlockBody {
input . leaveList ( ) ;
return empty ( ) ;
}
// TODO: Support multiple hard fork transaction formats.
final BlockBody body =
new BlockBody (
input . readList ( Transaction : : readFrom ) ,
input . readList ( rlp - > BlockHeader . readFrom ( rlp , blockHeaderFunctions ) ) ,
input . isEndOfCurrentList ( )
? Optional . empty ( )
: Optional . of ( input . readList ( Withdrawal : : readFrom ) ) ,
input . isEndOfCurrentList ( )
? Optional . empty ( )
: Optional . of ( input . readList ( Deposit : : readFrom ) ) ) ;
final BlockBody body = readFrom ( input , blockHeaderFunctions ) ;
input . leaveList ( ) ;
return body ;
}
/ * *
* Read all fields from the block body expecting no list wrapping them . An example of a valid body
* would be : [ txs ] , [ ommers ] , [ withdrawals ] , [ deposits ] this method is called directly when importing
* a single block
*
* @param input The RLP - encoded input
* @param blockHeaderFunctions The block header functions used for parsing block headers
* @return the BlockBody decoded from the RLP
* /
public static BlockBody readFrom (
final RLPInput input , final BlockHeaderFunctions blockHeaderFunctions ) {
return new BlockBody (
input . readList ( Transaction : : readFrom ) ,
input . readList ( rlp - > BlockHeader . readFrom ( rlp , blockHeaderFunctions ) ) ,
input . isEndOfCurrentList ( )
? Optional . empty ( )
: Optional . of ( input . readList ( Withdrawal : : readFrom ) ) ,
input . isEndOfCurrentList ( )
? Optional . empty ( )
: Optional . of ( input . readList ( Deposit : : readFrom ) ) ) ;
}
@Override
public boolean equals ( final Object o ) {
if ( this = = o ) return true ;