Skip to content

Commit

Permalink
DogecoinWrapper: remove redundant check
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarguindzberg committed Sep 30, 2021
1 parent b912e94 commit 3e3b132
Showing 1 changed file with 30 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,49 +166,45 @@ public Map<Sha256Hash, List<Proof>> getTransactionsToSendToEth() {
}

public void onBlock(FilteredBlock filteredBlock) {
if (config.isDogeLockTxRelayEnabled() || config.isOperatorEnabled()) {
synchronized (this) {
log.debug("onBlock {}", filteredBlock.getHash());
List<Sha256Hash> hashes = new ArrayList<>();
PartialMerkleTree tree = filteredBlock.getPartialMerkleTree();
tree.getTxnHashAndMerkleRoot(hashes);
for (Sha256Hash txToSendToEth : dogeTxToRelayToEthProofsMap.keySet()) {
if (hashes.contains(txToSendToEth)) {
List<Proof> proofs = dogeTxToRelayToEthProofsMap.get(txToSendToEth);
boolean alreadyIncluded = false;
for (Proof proof : proofs) {
if (proof.getBlockHash().equals(filteredBlock.getHash())) {
alreadyIncluded = true;
}
synchronized (this) {
log.debug("onBlock {}", filteredBlock.getHash());
List<Sha256Hash> hashes = new ArrayList<>();
PartialMerkleTree tree = filteredBlock.getPartialMerkleTree();
tree.getTxnHashAndMerkleRoot(hashes);
for (Sha256Hash txToSendToEth : dogeTxToRelayToEthProofsMap.keySet()) {
if (hashes.contains(txToSendToEth)) {
List<Proof> proofs = dogeTxToRelayToEthProofsMap.get(txToSendToEth);
boolean alreadyIncluded = false;
for (Proof proof : proofs) {
if (proof.getBlockHash().equals(filteredBlock.getHash())) {
alreadyIncluded = true;
}
if (!alreadyIncluded) {
Proof proof = new Proof(filteredBlock.getHash(), tree);
proofs.add(proof);
log.info("New proof for tx " + txToSendToEth + " in block " + filteredBlock.getHash());
try {
flushProofs();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
} else {
log.info("Proof for tx " + txToSendToEth + " in block " + filteredBlock.getHash() + " already stored");
}
if (!alreadyIncluded) {
Proof proof = new Proof(filteredBlock.getHash(), tree);
proofs.add(proof);
log.info("New proof for tx " + txToSendToEth + " in block " + filteredBlock.getHash());
try {
flushProofs();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
} else {
log.info("Proof for tx " + txToSendToEth + " in block " + filteredBlock.getHash() + " already stored");
}
}
}
}
}

public void onTransaction(Transaction tx) {
if (config.isDogeLockTxRelayEnabled() || config.isOperatorEnabled()) {
log.debug("onTransaction {}", tx.getTxId());
synchronized (this) {
dogeTxToRelayToEthProofsMap.put(tx.getTxId(), new ArrayList<Proof>());
try {
flushProofs();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
log.debug("onTransaction {}", tx.getTxId());
synchronized (this) {
dogeTxToRelayToEthProofsMap.put(tx.getTxId(), new ArrayList<Proof>());
try {
flushProofs();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
}
Expand Down

0 comments on commit 3e3b132

Please sign in to comment.