mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-08-01 12:31:23 +00:00
Work done can never be negative. Assert for that fact, because we've seen negative values in the wild.
This commit is contained in:
committed by
Mike Hearn
parent
fa3037a4b2
commit
918665a6e4
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright 2011 Google Inc.
|
||||
* Copyright 2014 Andreas Schildbach
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +19,6 @@ package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.utils.ListenerRegistration;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
|
||||
@@ -29,6 +29,8 @@ import java.util.ListIterator;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import static com.google.common.base.Preconditions.*;
|
||||
|
||||
/**
|
||||
* <p>A TransactionConfidence object tracks data you can use to make a confidence decision about a transaction.
|
||||
* It also contains some pre-canned rules for common scenarios: if you aren't really sure what level of confidence
|
||||
@@ -187,7 +189,7 @@ public class TransactionConfidence implements Serializable {
|
||||
* a future from {@link #getDepthFuture(int)}.</p>
|
||||
*/
|
||||
public void addEventListener(Listener listener, Executor executor) {
|
||||
Preconditions.checkNotNull(listener);
|
||||
checkNotNull(listener);
|
||||
listeners.addIfAbsent(new ListenerRegistration<Listener>(listener, executor));
|
||||
}
|
||||
|
||||
@@ -206,7 +208,7 @@ public class TransactionConfidence implements Serializable {
|
||||
}
|
||||
|
||||
public boolean removeEventListener(Listener listener) {
|
||||
Preconditions.checkNotNull(listener);
|
||||
checkNotNull(listener);
|
||||
return ListenerRegistration.removeFromList(listener, listeners);
|
||||
}
|
||||
|
||||
@@ -335,6 +337,7 @@ public class TransactionConfidence implements Serializable {
|
||||
|
||||
this.depth++;
|
||||
this.workDone = this.workDone.add(block.getWork());
|
||||
checkState(workDone.signum() >= 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -371,6 +374,7 @@ public class TransactionConfidence implements Serializable {
|
||||
}
|
||||
|
||||
public synchronized void setWorkDone(BigInteger workDone) {
|
||||
checkArgument(workDone.signum() >= 0);
|
||||
this.workDone = workDone;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user