-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add serialization for btc tx to avoid passing boolean, and reuse it when possible #2734
Add serialization for btc tx to avoid passing boolean, and reuse it when possible #2734
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor, looking very good :)
private static BtcTransaction deserializeBtcTransactionFromRLPData(byte[] rlpData, NetworkParameters networkParameters, boolean txHasInputs) { | ||
if (!txHasInputs) { | ||
BtcTransaction tx = new BtcTransaction(networkParameters); | ||
tx.parseNoInputs(rlpData); | ||
return tx; | ||
} | ||
|
||
return new BtcTransaction(networkParameters, rlpData); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private static BtcTransaction deserializeBtcTransactionFromRLPData(byte[] rlpData, NetworkParameters networkParameters, boolean txHasInputs) { | |
if (!txHasInputs) { | |
BtcTransaction tx = new BtcTransaction(networkParameters); | |
tx.parseNoInputs(rlpData); | |
return tx; | |
} | |
return new BtcTransaction(networkParameters, rlpData); | |
} | |
private static BtcTransaction deserializeBtcTransactionFromRLPData( | |
byte[] rlpData, NetworkParameters networkParameters, boolean hasInputs) { | |
if (hasInputs) { | |
return new BtcTransaction(networkParameters, rlpData); | |
} | |
BtcTransaction tx = new BtcTransaction(networkParameters); | |
tx.parseNoInputs(rlpData); | |
return tx; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i prefer to have the less used case inside the if, to improve readability.
(Currently, we only use this deserialization having inputs)
public static byte[] serializeRskTxsWaitingForSignatures( | ||
SortedMap<Keccak256, BtcTransaction> rskTxWaitingForSignaturesMap) { | ||
public static byte[] serializeRskTxsWaitingForSignatures(SortedMap<Keccak256, BtcTransaction> rskTxWaitingForSignaturesMap) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Google Java Style Guide enforces a 100-character line limit, is there any reason why this is being changed across the class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad, sorry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
public static BtcTransaction deserializeSvpFundTx(byte[] data, NetworkParameters networkParameters) { | ||
return deserializeBtcTransaction(data, networkParameters, true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a serialize method that complements this one?
|
||
// Act | ||
byte[] serializedSvpFundTransaction = BridgeSerializationUtils.serializeBtcTransaction(svpFundTx); | ||
BtcTransaction deserializedSvpFundTransaction = BridgeSerializationUtils.deserializeSvpFundTx(serializedSvpFundTransaction, NETWORK_PARAMETERS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if we really need this method that simply acts as a wrapper. Wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats one of the points of this refactor, having specific methods when deserializing txs we know they have inputs to avoid passing the boolean.
We need to keep the whole txHasInputs
thing since its part of bitcoin, but is not the cleanest thing to do 😄
@Test | ||
void serializeAndDeserializeBtcTransaction_withValidDataAndInputs_shouldReturnEqualResults() { | ||
// Arrange | ||
BtcTransaction fundTx = new BtcTransaction(NETWORK_PARAMETERS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fundTx
might give the impression this is something related to svp, what about we call it prevTx
here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree! Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
int n = 0; | ||
|
||
int n = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was moved to be closer from where its being used
… avoid passing boolean
…blank lines to improve readability
…thods to deserialize btc txs with and without inputs.
5a1e6c4
to
44c4644
Compare
Quality Gate passedIssues Measures |
98ed61b
into
feature/powpeg_validation_protocol-phase2
Also add serialization for rsk tx hash to reuse it when possible