mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-19 05:33:44 +01:00
Migrate a few asserts to Guava checkArgument/checkState.
This commit is contained in:
parent
0603afe78d
commit
90be18150f
@ -35,11 +35,9 @@ import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import static org.bitcoinj.core.Utils.*;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import org.bitcoinj.script.ScriptChunk;
|
||||
|
||||
/**
|
||||
* <p>A transaction represents the movement of coins from some addresses to some other addresses. It can also represent
|
||||
@ -1203,8 +1201,8 @@ public class Transaction extends ChildMessage {
|
||||
*/
|
||||
public void checkCoinBaseHeight(final int height)
|
||||
throws VerificationException {
|
||||
assert height >= Block.BLOCK_HEIGHT_GENESIS;
|
||||
assert isCoinBase();
|
||||
checkArgument(height >= Block.BLOCK_HEIGHT_GENESIS);
|
||||
checkState(isCoinBase());
|
||||
|
||||
// Check block height is in coinbase input script
|
||||
final TransactionInput in = this.getInputs().get(0);
|
||||
|
@ -150,7 +150,7 @@ public final class HDKeyDerivation {
|
||||
ChildNumber childNumber) throws HDDerivationException {
|
||||
checkArgument(parent.hasPrivKey(), "Parent key must have private key bytes for this method.");
|
||||
byte[] parentPublicKey = parent.getPubKeyPoint().getEncoded(true);
|
||||
assert parentPublicKey.length == 33 : parentPublicKey.length;
|
||||
checkState(parentPublicKey.length == 33, "Parent pubkey must be 33 bytes, but is " + parentPublicKey.length);
|
||||
ByteBuffer data = ByteBuffer.allocate(37);
|
||||
if (childNumber.isHardened()) {
|
||||
data.put(parent.getPrivKeyBytes33());
|
||||
@ -159,7 +159,7 @@ public final class HDKeyDerivation {
|
||||
}
|
||||
data.putInt(childNumber.i());
|
||||
byte[] i = HDUtils.hmacSha512(parent.getChainCode(), data.array());
|
||||
assert i.length == 64 : i.length;
|
||||
checkState(i.length == 64, i.length);
|
||||
byte[] il = Arrays.copyOfRange(i, 0, 32);
|
||||
byte[] chainCode = Arrays.copyOfRange(i, 32, 64);
|
||||
BigInteger ilInt = new BigInteger(1, il);
|
||||
@ -178,12 +178,12 @@ public final class HDKeyDerivation {
|
||||
public static RawKeyBytes deriveChildKeyBytesFromPublic(DeterministicKey parent, ChildNumber childNumber, PublicDeriveMode mode) throws HDDerivationException {
|
||||
checkArgument(!childNumber.isHardened(), "Can't use private derivation with public keys only.");
|
||||
byte[] parentPublicKey = parent.getPubKeyPoint().getEncoded(true);
|
||||
assert parentPublicKey.length == 33 : parentPublicKey.length;
|
||||
checkState(parentPublicKey.length == 33, "Parent pubkey must be 33 bytes, but is " + parentPublicKey.length);
|
||||
ByteBuffer data = ByteBuffer.allocate(37);
|
||||
data.put(parentPublicKey);
|
||||
data.putInt(childNumber.i());
|
||||
byte[] i = HDUtils.hmacSha512(parent.getChainCode(), data.array());
|
||||
assert i.length == 64 : i.length;
|
||||
checkState(i.length == 64, i.length);
|
||||
byte[] il = Arrays.copyOfRange(i, 0, 32);
|
||||
byte[] chainCode = Arrays.copyOfRange(i, 32, 64);
|
||||
BigInteger ilInt = new BigInteger(1, il);
|
||||
|
@ -23,6 +23,7 @@ import org.bitcoinj.core.Coin;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@ -1359,7 +1360,7 @@ public abstract class BtcFormat extends Format {
|
||||
* forget to put the symbols back otherwise equals(), hashCode() and immutability will
|
||||
* break. */
|
||||
private static DecimalFormatSymbols setSymbolAndCode(DecimalFormat numberFormat, String symbol, String code) {
|
||||
assert Thread.holdsLock(numberFormat);
|
||||
checkState(Thread.holdsLock(numberFormat));
|
||||
DecimalFormatSymbols fs = numberFormat.getDecimalFormatSymbols();
|
||||
DecimalFormatSymbols ante = (DecimalFormatSymbols)fs.clone();
|
||||
fs.setInternationalCurrencySymbol(code);
|
||||
@ -1380,7 +1381,7 @@ public abstract class BtcFormat extends Format {
|
||||
* @return The DecimalFormatSymbols before changing
|
||||
*/
|
||||
protected static void prefixUnitsIndicator(DecimalFormat numberFormat, int scale) {
|
||||
assert Thread.holdsLock(numberFormat); // make sure caller intends to reset before changing
|
||||
checkState(Thread.holdsLock(numberFormat)); // make sure caller intends to reset before changing
|
||||
DecimalFormatSymbols fs = numberFormat.getDecimalFormatSymbols();
|
||||
setSymbolAndCode(numberFormat,
|
||||
prefixSymbol(fs.getCurrencySymbol(), scale), prefixCode(fs.getInternationalCurrencySymbol(), scale)
|
||||
|
Loading…
Reference in New Issue
Block a user