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