mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-02 21:47:18 +00:00
Bloom filtering: Add equals/hashCode/toString to FilteredBlock and PartialMerkleTree then unit test round tripping.
This commit is contained in:
@@ -117,4 +117,34 @@ public class FilteredBlock extends Message {
|
||||
public int getTransactionCount() {
|
||||
return merkleTree.getTransactionCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
FilteredBlock block = (FilteredBlock) o;
|
||||
|
||||
if (!associatedTransactions.equals(block.associatedTransactions)) return false;
|
||||
if (!header.equals(block.header)) return false;
|
||||
if (!merkleTree.equals(block.merkleTree)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = header.hashCode();
|
||||
result = 31 * result + merkleTree.hashCode();
|
||||
result = 31 * result + associatedTransactions.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "FilteredBlock{" +
|
||||
"merkleTree=" + merkleTree +
|
||||
", header=" + header +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.google.bitcoin.core;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -180,4 +181,35 @@ public class PartialMerkleTree extends Message {
|
||||
public int getTransactionCount() {
|
||||
return transactionCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
PartialMerkleTree tree = (PartialMerkleTree) o;
|
||||
|
||||
if (transactionCount != tree.transactionCount) return false;
|
||||
if (!hashes.equals(tree.hashes)) return false;
|
||||
if (!Arrays.equals(matchedChildBits, tree.matchedChildBits)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = transactionCount;
|
||||
result = 31 * result + Arrays.hashCode(matchedChildBits);
|
||||
result = 31 * result + hashes.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PartialMerkleTree{" +
|
||||
"transactionCount=" + transactionCount +
|
||||
", matchedChildBits=" + Arrays.toString(matchedChildBits) +
|
||||
", hashes=" + hashes +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ public class FilteredBlockAndPartialMerkleTreeTests extends TestWithPeerGroup {
|
||||
}
|
||||
|
||||
@Test
|
||||
// Simple deserialization sanity check
|
||||
public void deserializeFilteredBlock() throws Exception {
|
||||
NetworkParameters params = UnitTestParams.get();
|
||||
|
||||
@@ -65,6 +64,9 @@ public class FilteredBlockAndPartialMerkleTreeTests extends TestWithPeerGroup {
|
||||
List<Sha256Hash> txesMatched = block.getTransactionHashes();
|
||||
assertTrue(txesMatched.size() == 1);
|
||||
assertTrue(txesMatched.contains(new Sha256Hash("63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5")));
|
||||
|
||||
// Check round tripping.
|
||||
assertEquals(block, new FilteredBlock(params, block.bitcoinSerialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user