mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-14 19:25:51 +00:00
Introduce little code simplifications.
This commit is contained in:
parent
6d2e35b765
commit
fd52c86bf9
@ -836,10 +836,8 @@ public class Block extends Message {
|
||||
public Sha256Hash getMerkleRoot() {
|
||||
maybeParseHeader();
|
||||
if (merkleRoot == null) {
|
||||
|
||||
//TODO check if this is really necessary.
|
||||
unCacheHeader();
|
||||
|
||||
merkleRoot = calculateMerkleRoot();
|
||||
}
|
||||
return merkleRoot;
|
||||
|
@ -109,8 +109,8 @@ public class FilteredBlock extends Message {
|
||||
if (getTransactionHashes().contains(hash)) {
|
||||
associatedTransactions.put(hash, tx);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Returns the {@link PartialMerkleTree} object that provides the mathematical proof of transaction inclusion in the block. */
|
||||
@ -152,9 +152,6 @@ public class FilteredBlock extends Message {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FilteredBlock{" +
|
||||
"merkleTree=" + merkleTree +
|
||||
", header=" + header +
|
||||
'}';
|
||||
return "FilteredBlock{merkleTree=" + merkleTree + ", header=" + header + '}';
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ public class InventoryItem {
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type.toString() + ": " + hash;
|
||||
|
@ -157,7 +157,7 @@ public class RejectMessage extends Message {
|
||||
getReasonString(), getReasonCode().code);
|
||||
else
|
||||
return String.format("Reject: %s for reason '%s' (%d)", getRejectedMessage(),
|
||||
getReasonString(), getReasonCode().code);
|
||||
getReasonString(), getReasonCode().code);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +57,7 @@ public class TransactionInput extends ChildMessage implements Serializable {
|
||||
private byte[] scriptBytes;
|
||||
// The Script object obtained from parsing scriptBytes. Only filled in on demand and if the transaction is not
|
||||
// coinbase.
|
||||
transient private WeakReference<Script> scriptSig;
|
||||
private transient WeakReference<Script> scriptSig;
|
||||
/** Value of the output connected to the input, if known. This field does not participate in equals()/hashCode(). */
|
||||
@Nullable
|
||||
private Coin value;
|
||||
@ -177,7 +177,6 @@ public class TransactionInput extends ChildMessage implements Serializable {
|
||||
maybeParse();
|
||||
script = new Script(scriptBytes);
|
||||
scriptSig = new WeakReference<Script>(script);
|
||||
return script;
|
||||
}
|
||||
return script;
|
||||
}
|
||||
|
@ -206,8 +206,9 @@ public class TransactionOutput extends ChildMessage implements Serializable {
|
||||
* over the parents list to discover this.
|
||||
*/
|
||||
public int getIndex() {
|
||||
for (int i = 0; i < getParentTransaction().getOutputs().size(); i++) {
|
||||
if (getParentTransaction().getOutputs().get(i) == this)
|
||||
List<TransactionOutput> outputs = getParentTransaction().getOutputs();
|
||||
for (int i = 0; i < outputs.size(); i++) {
|
||||
if (outputs.get(i) == this)
|
||||
return i;
|
||||
}
|
||||
throw new IllegalStateException("Output linked to wrong parent transaction?");
|
||||
@ -256,7 +257,7 @@ public class TransactionOutput extends ChildMessage implements Serializable {
|
||||
availableForSpending = false;
|
||||
spentBy = input;
|
||||
if (parent != null)
|
||||
if (log.isDebugEnabled()) log.debug("Marked {}:{} as spent by {}", getParentTransaction().getHash(), getIndex(), input);
|
||||
if (log.isDebugEnabled()) log.debug("Marked {}:{} as spent by {}", getParentTransactionHash(), getIndex(), input);
|
||||
else
|
||||
if (log.isDebugEnabled()) log.debug("Marked floating output as spent by {}", input);
|
||||
}
|
||||
@ -266,7 +267,7 @@ public class TransactionOutput extends ChildMessage implements Serializable {
|
||||
*/
|
||||
public void markAsUnspent() {
|
||||
if (parent != null)
|
||||
if (log.isDebugEnabled()) log.debug("Un-marked {}:{} as spent by {}", getParentTransaction().getHash(), getIndex(), spentBy);
|
||||
if (log.isDebugEnabled()) log.debug("Un-marked {}:{} as spent by {}", getParentTransactionHash(), getIndex(), spentBy);
|
||||
else
|
||||
if (log.isDebugEnabled()) log.debug("Un-marked floating output as spent by {}", spentBy);
|
||||
availableForSpending = true;
|
||||
@ -374,10 +375,7 @@ public class TransactionOutput extends ChildMessage implements Serializable {
|
||||
*/
|
||||
@Nullable
|
||||
public Transaction getParentTransaction() {
|
||||
if(parent != null) {
|
||||
return (Transaction) parent;
|
||||
}
|
||||
return null;
|
||||
return (Transaction)parent;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -385,10 +383,7 @@ public class TransactionOutput extends ChildMessage implements Serializable {
|
||||
*/
|
||||
@Nullable
|
||||
public Sha256Hash getParentTransactionHash() {
|
||||
if (getParentTransaction() != null) {
|
||||
return getParentTransaction().getHash();
|
||||
}
|
||||
return null;
|
||||
return parent == null ? null : parent.getHash();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,12 +191,6 @@ public class UTXO implements Serializable {
|
||||
bos.write(0xFF & (height >> 16));
|
||||
bos.write(0xFF & (height >> 24));
|
||||
|
||||
byte[] coinbaseByte = new byte[1];
|
||||
if (coinbase) {
|
||||
coinbaseByte[0] = 1;
|
||||
} else {
|
||||
coinbaseByte[0] = 0;
|
||||
}
|
||||
bos.write(coinbaseByte);
|
||||
bos.write(new byte[] { (byte)(coinbase ? 1 : 0) });
|
||||
}
|
||||
}
|
||||
|
@ -44,11 +44,6 @@ public class ListenerRegistration<T> {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (item != null) {
|
||||
list.remove(item);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return item != null && list.remove(item);
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ public class DeterministicSeed implements EncryptableItem {
|
||||
public static final int MAX_SEED_ENTROPY_BITS = 512;
|
||||
|
||||
@Nullable private final byte[] seed;
|
||||
@Nullable private List<String> mnemonicCode;
|
||||
@Nullable private EncryptedData encryptedMnemonicCode;
|
||||
@Nullable private final List<String> mnemonicCode; // only one of mnemonicCode/encryptedMnemonicCode will be set
|
||||
@Nullable private final EncryptedData encryptedMnemonicCode;
|
||||
@Nullable private EncryptedData encryptedSeed;
|
||||
private final long creationTimeSeconds;
|
||||
|
||||
@ -135,17 +135,13 @@ public class DeterministicSeed implements EncryptableItem {
|
||||
if (isEncrypted())
|
||||
return "DeterministicSeed [encrypted]";
|
||||
else
|
||||
return "DeterministicSeed " + toHexString() +
|
||||
((mnemonicCode != null) ? " " + Joiner.on(" ").join(mnemonicCode) : "");
|
||||
return "DeterministicSeed " + toHexString() + " " + Joiner.on(" ").join(mnemonicCode);
|
||||
}
|
||||
|
||||
/** Returns the seed as hex or null if encrypted. */
|
||||
@Nullable
|
||||
public String toHexString() {
|
||||
if (seed != null)
|
||||
return HEX.encode(seed);
|
||||
else
|
||||
return null;
|
||||
return seed != null ? HEX.encode(seed) : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
Loading…
x
Reference in New Issue
Block a user