Skip to content

Commit

Permalink
Modified code as required by PR PegaSysEng#264
Browse files Browse the repository at this point in the history
  • Loading branch information
saltiniroberto committed Nov 21, 2018
1 parent 68200b6 commit 2830c5f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@

import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftSignedMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftUnsignedCommitMessageData;
import tech.pegasys.pantheon.ethereum.p2p.NetworkMemoryPool;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import io.netty.buffer.ByteBuf;

public class IbftCommitMessage extends AbstractIbftMessage {

private static final int MESSAGE_CODE = IbftV2.COMMIT;

private IbftCommitMessage(final ByteBuf data) {
private IbftCommitMessage(final BytesValue data) {
super(data);
}

public static IbftCommitMessage fromMessage(final MessageData message) {
if (message instanceof IbftCommitMessage) {
message.retain();
return (IbftCommitMessage) message;
}
final int code = message.getCode();
Expand All @@ -40,21 +36,18 @@ public static IbftCommitMessage fromMessage(final MessageData message) {
String.format("Message has code %d and thus is not a CommitMessage", code));
}

final ByteBuf data = NetworkMemoryPool.allocate(message.getSize());
message.writeTo(data);
return new IbftCommitMessage(data);
return new IbftCommitMessage(message.getData());
}

@Override
public IbftSignedMessageData<IbftUnsignedCommitMessageData> decode() {
return IbftSignedMessageData.readIbftSignedCommitMessageDataFrom(
RLP.input(BytesValue.wrapBuffer(data)));
return IbftSignedMessageData.readIbftSignedCommitMessageDataFrom(RLP.input(data));
}

public static IbftCommitMessage create(
final IbftSignedMessageData<IbftUnsignedCommitMessageData> ibftPrepareMessageDecoded) {

return new IbftCommitMessage(writeMessageToByteBuf(ibftPrepareMessageDecoded));
return new IbftCommitMessage(ibftPrepareMessageDecoded.encode());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,20 @@

import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftSignedMessageData;
import tech.pegasys.pantheon.consensus.ibft.ibftmessagedata.IbftUnsignedNewRoundMessageData;
import tech.pegasys.pantheon.ethereum.p2p.NetworkMemoryPool;
import tech.pegasys.pantheon.ethereum.p2p.api.MessageData;
import tech.pegasys.pantheon.ethereum.rlp.RLP;
import tech.pegasys.pantheon.util.bytes.BytesValue;

import io.netty.buffer.ByteBuf;

public class IbftNewRoundMessage extends AbstractIbftMessage {

private static final int MESSAGE_CODE = IbftV2.NEW_ROUND;

private IbftNewRoundMessage(final ByteBuf data) {
private IbftNewRoundMessage(final BytesValue data) {
super(data);
}

public static IbftNewRoundMessage fromMessage(final MessageData message) {
if (message instanceof IbftNewRoundMessage) {
message.retain();
return (IbftNewRoundMessage) message;
}
final int code = message.getCode();
Expand All @@ -40,21 +36,18 @@ public static IbftNewRoundMessage fromMessage(final MessageData message) {
String.format("Message has code %d and thus is not a NewRoundMessage", code));
}

final ByteBuf data = NetworkMemoryPool.allocate(message.getSize());
message.writeTo(data);
return new IbftNewRoundMessage(data);
return new IbftNewRoundMessage(message.getData());
}

@Override
public IbftSignedMessageData<IbftUnsignedNewRoundMessageData> decode() {
return IbftSignedMessageData.readIbftSignedNewRoundMessageDataFrom(
RLP.input(BytesValue.wrapBuffer(data)));
return IbftSignedMessageData.readIbftSignedNewRoundMessageDataFrom(RLP.input(data));
}

public static IbftNewRoundMessage create(
final IbftSignedMessageData<IbftUnsignedNewRoundMessageData> ibftPrepareMessageDecoded) {

return new IbftNewRoundMessage(writeMessageToByteBuf(ibftPrepareMessageDecoded));
return new IbftNewRoundMessage(ibftPrepareMessageDecoded.encode());
}

@Override
Expand Down

0 comments on commit 2830c5f

Please sign in to comment.