Substitute WireTransaction id property getter with calculated merkle root.

This commit is contained in:
Katarzyna Streich 2016-10-13 18:14:30 +01:00
parent ea826988af
commit 6b5ad92f9b

View File

@ -38,7 +38,16 @@ class WireTransaction(
// Cache the serialised form of the transaction and its hash to give us fast access to it. // Cache the serialised form of the transaction and its hash to give us fast access to it.
@Volatile @Transient private var cachedBits: SerializedBytes<WireTransaction>? = null @Volatile @Transient private var cachedBits: SerializedBytes<WireTransaction>? = null
val serialized: SerializedBytes<WireTransaction> get() = cachedBits ?: serialize().apply { cachedBits = this } val serialized: SerializedBytes<WireTransaction> get() = cachedBits ?: serialize().apply { cachedBits = this }
override val id: SecureHash get() = serialized.hash // override val id: SecureHash get() = serialized.hash //todo remove
//We need cashed leaves hashed for Partial Merkle Tree calculation.
@Volatile @Transient private var cachedLeavesHashes: List<SecureHash>? = null
val allLeavesHashes: List<SecureHash> get() = cachedLeavesHashes ?: calculateLeavesHashes().apply { cachedLeavesHashes }
//TODO There is a problem with that it's failing 4 tests. Also in few places in code, there was reference to tx.serialized.hash
// instead of tx.id.
override val id: SecureHash get() = getMerkleRoot(allLeavesHashes)
companion object { companion object {
fun deserialize(bits: SerializedBytes<WireTransaction>, kryo: Kryo = THREAD_LOCAL_KRYO.get()): WireTransaction { fun deserialize(bits: SerializedBytes<WireTransaction>, kryo: Kryo = THREAD_LOCAL_KRYO.get()): WireTransaction {