mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-13 11:36:15 +01:00
Wallet, Transaction: use Guava IntMath.divide() for the round-up divisions
The previous trick was confusing.
This commit is contained in:
parent
964adb1e63
commit
26cc0db3e2
2 changed files with 7 additions and 2 deletions
|
@ -34,12 +34,14 @@ import org.bitcoinj.wallet.WalletTransaction.Pool;
|
|||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.math.IntMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.*;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
|
||||
import static org.bitcoinj.core.NetworkParameters.ProtocolVersion.WITNESS_VERSION;
|
||||
|
@ -340,7 +342,7 @@ public class Transaction extends ChildMessage {
|
|||
public int getVsize() {
|
||||
if (!hasWitnesses())
|
||||
return getMessageSize();
|
||||
return (getWeight() + 3) / 4; // round up
|
||||
return IntMath.divide(getWeight(), 4, RoundingMode.CEILING); // round up
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.bitcoinj.wallet;
|
|||
|
||||
import com.google.common.annotations.*;
|
||||
import com.google.common.collect.*;
|
||||
import com.google.common.math.IntMath;
|
||||
import com.google.common.util.concurrent.*;
|
||||
import com.google.protobuf.*;
|
||||
import net.jcip.annotations.*;
|
||||
|
@ -75,6 +76,7 @@ import org.bouncycastle.crypto.params.*;
|
|||
import javax.annotation.*;
|
||||
import java.io.*;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
|
@ -5201,7 +5203,8 @@ public class Wallet extends BaseTaggableObject
|
|||
} else if (ScriptPattern.isP2WPKH(script)) {
|
||||
key = findKeyFromPubKeyHash(ScriptPattern.extractHashFromP2WH(script), Script.ScriptType.P2WPKH);
|
||||
checkNotNull(key, "Coin selection includes unspendable outputs");
|
||||
vsize += (script.getNumberOfBytesRequiredToSpend(key, redeemScript) + 3) / 4; // round up
|
||||
vsize += IntMath.divide(script.getNumberOfBytesRequiredToSpend(key, redeemScript), 4,
|
||||
RoundingMode.CEILING); // round up
|
||||
} else if (ScriptPattern.isP2SH(script)) {
|
||||
redeemScript = findRedeemDataFromScriptHash(ScriptPattern.extractHashFromP2SH(script)).redeemScript;
|
||||
checkNotNull(redeemScript, "Coin selection includes unspendable outputs");
|
||||
|
|
Loading…
Add table
Reference in a new issue