mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-13 11:36:15 +01:00
Fix length and parseLazy handling. Resolves issue 92
This commit is contained in:
parent
37a63265ef
commit
228f30f663
2 changed files with 10 additions and 9 deletions
|
@ -179,7 +179,7 @@ public class Block extends Message {
|
|||
// provided we will have to
|
||||
// invoke a light parse of transactions to calculate the length.
|
||||
if (length == UNKNOWN_LENGTH) {
|
||||
log.warn("Performing lite parse of block transaction as block was initialised from byte array without providing length. This should never need to happen.");
|
||||
assert !parseLazy : "Performing lite parse of block transaction as block was initialised from byte array without providing length. This should never need to happen." + " parseLazy: " + parseLazy;
|
||||
parseTransactions();
|
||||
length = cursor - offset;
|
||||
} else {
|
||||
|
|
|
@ -100,11 +100,8 @@ public abstract class Message implements Serializable {
|
|||
parse();
|
||||
parsed = true;
|
||||
}
|
||||
|
||||
// assert (parseLazy ? !parsed : parsed && (parseRetain ? bytes != null : bytes == null))
|
||||
// : "parseLazy : " + parseLazy + " parsed: " + parsed
|
||||
// + " parseRetain:" + parseRetain
|
||||
// + " bytes == null" + bytes == null;
|
||||
|
||||
assert this.length != UNKNOWN_LENGTH: "Length field has not been set in constructor for " + getClass().getSimpleName() + " after " + (parseLazy ? "lite" : "full") + " parse. Refer to Message.parseLite() for detail of required Length field contract.";
|
||||
|
||||
if (SELF_CHECK && !this.getClass().getSimpleName().equals("VersionMessage")) {
|
||||
checkParse();
|
||||
|
@ -140,7 +137,10 @@ public abstract class Message implements Serializable {
|
|||
* This is only required for subclasses of ChildClass as root level messages will have their length passed
|
||||
* into the constructor.
|
||||
* <p/>
|
||||
* It is expected that the length field will be set before this method returns.
|
||||
* Implementations should adhere to the following contract: If parseLazy = true the 'length'
|
||||
* field must be set before returning. If parseLazy = false the length field must be set either
|
||||
* within the parseLite() method OR the parse() method. The overriding requirement is that length
|
||||
* must be set to non UNKNOWN_MESSAGE value by the time the constructor exits.
|
||||
*
|
||||
* @return
|
||||
* @throws ProtocolException
|
||||
|
@ -372,8 +372,9 @@ public abstract class Message implements Serializable {
|
|||
if (length != UNKNOWN_LENGTH)
|
||||
return length;
|
||||
checkParse();
|
||||
if (length != UNKNOWN_LENGTH)
|
||||
length = cursor - offset;
|
||||
assert length != UNKNOWN_LENGTH: "Length field has not been set in " + getClass().getSimpleName() + " after full parse.";
|
||||
//if (length == UNKNOWN_LENGTH)
|
||||
// length = cursor - offset;
|
||||
return length;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue