mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 21:32:35 +01:00
Script: take into account the various witness length fields in getNumberOfBytesRequiredToSpend()
This (hopefully entirely) fixes the slight fee underspending for spends from P2WPKH.
This commit is contained in:
parent
26cc0db3e2
commit
4ea8546cd3
@ -606,7 +606,12 @@ public class Script {
|
||||
// scriptSig is empty
|
||||
// witness: <sig> <pubKey>
|
||||
int compressedPubKeySize = 33;
|
||||
return SIG_SIZE + (pubKey != null ? pubKey.getPubKey().length : compressedPubKeySize);
|
||||
int publicKeyLength = pubKey != null ? pubKey.getPubKey().length : compressedPubKeySize;
|
||||
return VarInt.sizeOf(2) // number of witness pushes
|
||||
+ VarInt.sizeOf(SIG_SIZE) // size of signature push
|
||||
+ SIG_SIZE // signature push
|
||||
+ VarInt.sizeOf(publicKeyLength) // size of pubKey push
|
||||
+ publicKeyLength; // pubKey push
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported script type");
|
||||
}
|
||||
|
@ -2696,7 +2696,13 @@ public class WalletTest extends TestWithWallet {
|
||||
SendRequest request = SendRequest.to(OTHER_SEGWIT_ADDRESS, CENT);
|
||||
request.feePerKb = Transaction.DEFAULT_TX_FEE;
|
||||
mySegwitWallet.completeTx(request);
|
||||
assertEquals(Coin.valueOf(14000), request.tx.getFee());
|
||||
|
||||
// Fee test, absolute and per virtual kilobyte
|
||||
Coin fee = request.tx.getFee();
|
||||
int vsize = request.tx.getVsize();
|
||||
Coin feePerVkb = fee.multiply(1000).divide(vsize);
|
||||
assertEquals(Coin.valueOf(14100), fee);
|
||||
assertEquals(Transaction.DEFAULT_TX_FEE, feePerVkb);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user