mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-11-01 21:17:13 +00:00
Use Message.unsafeBitcoinSerialize() whenever it's very clear we won't modify the array.
This commit is contained in:
@@ -886,7 +886,7 @@ public class Block extends Message {
|
||||
ScriptBuilder.createOutputScript(ECKey.fromPublicOnly(pubKeyTo)).getProgram()));
|
||||
transactions.add(coinbase);
|
||||
coinbase.setParent(this);
|
||||
coinbase.length = coinbase.bitcoinSerialize().length;
|
||||
coinbase.length = coinbase.unsafeBitcoinSerialize().length;
|
||||
adjustLength(transactions.size(), coinbase.length);
|
||||
}
|
||||
|
||||
|
||||
@@ -332,14 +332,14 @@ public class BloomFilter extends Message {
|
||||
if (contains(chunk.data)) {
|
||||
boolean isSendingToPubKeys = script.isSentToRawPubKey() || script.isSentToMultiSig();
|
||||
if (flag == BloomUpdate.UPDATE_ALL || (flag == BloomUpdate.UPDATE_P2PUBKEY_ONLY && isSendingToPubKeys))
|
||||
insert(output.getOutPointFor().bitcoinSerialize());
|
||||
insert(output.getOutPointFor().unsafeBitcoinSerialize());
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found) return true;
|
||||
for (TransactionInput input : tx.getInputs()) {
|
||||
if (contains(input.getOutpoint().bitcoinSerialize())) {
|
||||
if (contains(input.getOutpoint().unsafeBitcoinSerialize())) {
|
||||
return true;
|
||||
}
|
||||
for (ScriptChunk chunk : input.getScriptSig().getChunks()) {
|
||||
|
||||
@@ -234,8 +234,7 @@ public class Transaction extends ChildMessage {
|
||||
@Override
|
||||
public Sha256Hash getHash() {
|
||||
if (hash == null) {
|
||||
byte[] bits = bitcoinSerialize();
|
||||
hash = Sha256Hash.wrapReversed(Sha256Hash.hashTwice(bits));
|
||||
hash = Sha256Hash.wrapReversed(Sha256Hash.hashTwice(unsafeBitcoinSerialize()));
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
@@ -713,7 +712,7 @@ public class Transaction extends ChildMessage {
|
||||
}
|
||||
inputs.clear();
|
||||
// You wanted to reserialize, right?
|
||||
this.length = this.bitcoinSerialize().length;
|
||||
this.length = this.unsafeBitcoinSerialize().length;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -801,7 +800,7 @@ public class Transaction extends ChildMessage {
|
||||
}
|
||||
outputs.clear();
|
||||
// You wanted to reserialize, right?
|
||||
this.length = this.bitcoinSerialize().length;
|
||||
this.length = this.unsafeBitcoinSerialize().length;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -224,7 +224,7 @@ public class TransactionOutput extends ChildMessage {
|
||||
// formula is wrong for anything that's not a pay-to-address output, unfortunately, we must follow Bitcoin Core's
|
||||
// wrongness in order to ensure we're considered standard. A better formula would either estimate the
|
||||
// size of data needed to satisfy all different script types, or just hard code 33 below.
|
||||
final long size = this.bitcoinSerialize().length + 148;
|
||||
final long size = this.unsafeBitcoinSerialize().length + 148;
|
||||
Coin[] nonDustAndRemainder = feePerKbRequired.multiply(size).divideAndRemainder(1000);
|
||||
return nonDustAndRemainder[1].equals(Coin.ZERO) ? nonDustAndRemainder[0] : nonDustAndRemainder[0].add(Coin.SATOSHI);
|
||||
}
|
||||
|
||||
@@ -4284,7 +4284,7 @@ public class Wallet extends BaseTaggableObject
|
||||
private boolean adjustOutputDownwardsForFee(Transaction tx, CoinSelection coinSelection, Coin baseFee, Coin feePerKb) {
|
||||
TransactionOutput output = tx.getOutput(0);
|
||||
// Check if we need additional fee due to the transaction's size
|
||||
int size = tx.bitcoinSerialize().length;
|
||||
int size = tx.unsafeBitcoinSerialize().length;
|
||||
size += estimateBytesForSigning(coinSelection);
|
||||
Coin fee = baseFee.add(feePerKb.multiply((size / 1000) + 1));
|
||||
output.setValue(output.getValue().subtract(fee));
|
||||
@@ -4870,7 +4870,7 @@ public class Wallet extends BaseTaggableObject
|
||||
}
|
||||
}
|
||||
for (TransactionOutPoint point : bloomOutPoints)
|
||||
filter.insert(point.bitcoinSerialize());
|
||||
filter.insert(point.unsafeBitcoinSerialize());
|
||||
return filter;
|
||||
} finally {
|
||||
endBloomFilterCalculation();
|
||||
@@ -5104,7 +5104,7 @@ public class Wallet extends BaseTaggableObject
|
||||
additionalValueForNextCategory = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(
|
||||
Transaction.MIN_NONDUST_OUTPUT.add(Coin.SATOSHI));
|
||||
} else {
|
||||
size += changeOutput.bitcoinSerialize().length + VarInt.sizeOf(req.tx.getOutputs().size()) - VarInt.sizeOf(req.tx.getOutputs().size() - 1);
|
||||
size += changeOutput.unsafeBitcoinSerialize().length + VarInt.sizeOf(req.tx.getOutputs().size()) - VarInt.sizeOf(req.tx.getOutputs().size() - 1);
|
||||
// This solution is either category 1 or 2
|
||||
if (!eitherCategory2Or3) // must be category 1
|
||||
additionalValueForNextCategory = null;
|
||||
@@ -5126,7 +5126,7 @@ public class Wallet extends BaseTaggableObject
|
||||
|
||||
// Estimate transaction size and loop again if we need more fee per kb. The serialized tx doesn't
|
||||
// include things we haven't added yet like input signatures/scripts or the change output.
|
||||
size += req.tx.bitcoinSerialize().length;
|
||||
size += req.tx.unsafeBitcoinSerialize().length;
|
||||
size += estimateBytesForSigning(selection);
|
||||
if (size/1000 > lastCalculatedSize/1000 && req.feePerKb.signum() > 0) {
|
||||
lastCalculatedSize = size;
|
||||
@@ -5464,7 +5464,7 @@ public class Wallet extends BaseTaggableObject
|
||||
if (sign)
|
||||
signTransaction(req);
|
||||
// KeyTimeCoinSelector should never select enough inputs to push us oversize.
|
||||
checkState(rekeyTx.bitcoinSerialize().length < Transaction.MAX_STANDARD_TX_SIZE);
|
||||
checkState(rekeyTx.unsafeBitcoinSerialize().length < Transaction.MAX_STANDARD_TX_SIZE);
|
||||
return rekeyTx;
|
||||
} catch (VerificationException e) {
|
||||
throw new RuntimeException(e); // Cannot happen.
|
||||
|
||||
@@ -333,7 +333,7 @@ public class PaymentChannelClient implements IPaymentChannelClient {
|
||||
|
||||
Protos.ProvideRefund.Builder provideRefundBuilder = Protos.ProvideRefund.newBuilder()
|
||||
.setMultisigKey(ByteString.copyFrom(myKey.getPubKey()))
|
||||
.setTx(ByteString.copyFrom(((PaymentChannelV1ClientState)state).getIncompleteRefundTransaction().bitcoinSerialize()));
|
||||
.setTx(ByteString.copyFrom(((PaymentChannelV1ClientState)state).getIncompleteRefundTransaction().unsafeBitcoinSerialize()));
|
||||
|
||||
conn.sendToServer(Protos.TwoWayChannelMessage.newBuilder()
|
||||
.setProvideRefund(provideRefundBuilder)
|
||||
@@ -348,7 +348,7 @@ public class PaymentChannelClient implements IPaymentChannelClient {
|
||||
state.storeChannelInWallet(serverId);
|
||||
|
||||
Protos.ProvideContract.Builder provideContractBuilder = Protos.ProvideContract.newBuilder()
|
||||
.setTx(ByteString.copyFrom(state.getContract().bitcoinSerialize()))
|
||||
.setTx(ByteString.copyFrom(state.getContract().unsafeBitcoinSerialize()))
|
||||
.setClientKey(ByteString.copyFrom(myKey.getPubKey()));
|
||||
try {
|
||||
// Make an initial payment of the dust limit, and put it into the message as well. The size of the
|
||||
@@ -390,7 +390,7 @@ public class PaymentChannelClient implements IPaymentChannelClient {
|
||||
state.storeChannelInWallet(serverId);
|
||||
|
||||
Protos.ProvideContract.Builder contractMsg = Protos.ProvideContract.newBuilder()
|
||||
.setTx(ByteString.copyFrom(state.getContract().bitcoinSerialize()));
|
||||
.setTx(ByteString.copyFrom(state.getContract().unsafeBitcoinSerialize()));
|
||||
try {
|
||||
// Make an initial payment of the dust limit, and put it into the message as well. The size of the
|
||||
// server-requested dust limit was already sanity checked by this point.
|
||||
|
||||
@@ -527,7 +527,7 @@ public class PaymentChannelServer {
|
||||
if (result != null) {
|
||||
// Result can be null on various error paths, like if we never actually opened
|
||||
// properly and so on.
|
||||
msg.getSettlementBuilder().setTx(ByteString.copyFrom(result.bitcoinSerialize()));
|
||||
msg.getSettlementBuilder().setTx(ByteString.copyFrom(result.unsafeBitcoinSerialize()));
|
||||
log.info("Sending CLOSE back with broadcast settlement tx.");
|
||||
} else {
|
||||
log.info("Sending CLOSE back without broadcast settlement tx.");
|
||||
|
||||
@@ -304,9 +304,9 @@ public class StoredPaymentChannelClientStates implements WalletExtension {
|
||||
final ClientState.StoredClientPaymentChannel.Builder value = ClientState.StoredClientPaymentChannel.newBuilder()
|
||||
.setMajorVersion(channel.majorVersion)
|
||||
.setId(ByteString.copyFrom(channel.id.getBytes()))
|
||||
.setContractTransaction(ByteString.copyFrom(channel.contract.bitcoinSerialize()))
|
||||
.setContractTransaction(ByteString.copyFrom(channel.contract.unsafeBitcoinSerialize()))
|
||||
.setRefundFees(channel.refundFees.value)
|
||||
.setRefundTransaction(ByteString.copyFrom(channel.refund.bitcoinSerialize()))
|
||||
.setRefundTransaction(ByteString.copyFrom(channel.refund.unsafeBitcoinSerialize()))
|
||||
.setMyKey(ByteString.copyFrom(new byte[0])) // Not used, but protobuf message requires
|
||||
.setMyPublicKey(ByteString.copyFrom(channel.myKey.getPubKey()))
|
||||
.setServerKey(ByteString.copyFrom(channel.serverKey.getPubKey()))
|
||||
|
||||
@@ -241,10 +241,10 @@ public class StoredPaymentChannelServerStates implements WalletExtension {
|
||||
.setMajorVersion(channel.majorVersion)
|
||||
.setBestValueToMe(channel.bestValueToMe.value)
|
||||
.setRefundTransactionUnlockTimeSecs(channel.refundTransactionUnlockTimeSecs)
|
||||
.setContractTransaction(ByteString.copyFrom(channel.contract.bitcoinSerialize()))
|
||||
.setContractTransaction(ByteString.copyFrom(channel.contract.unsafeBitcoinSerialize()))
|
||||
.setMyKey(ByteString.copyFrom(channel.myKey.getPrivKeyBytes()));
|
||||
if (channel.majorVersion == 1) {
|
||||
channelBuilder.setClientOutput(ByteString.copyFrom(channel.clientOutput.bitcoinSerialize()));
|
||||
channelBuilder.setClientOutput(ByteString.copyFrom(channel.clientOutput.unsafeBitcoinSerialize()));
|
||||
} else {
|
||||
channelBuilder.setClientKey(ByteString.copyFrom(channel.clientKey.getPubKey()));
|
||||
}
|
||||
|
||||
@@ -156,16 +156,16 @@ public class BlockTest {
|
||||
tx.addInput(new TransactionInput(params, null, new byte[] {(byte) ScriptOpCodes.OP_FALSE},
|
||||
new TransactionOutPoint(params, 0, Sha256Hash.of(new byte[] { 1 }))));
|
||||
int origTxLength = 8 + 2 + 8 + 1 + 10 + 40 + 1 + 1;
|
||||
assertEquals(tx.bitcoinSerialize().length, tx.length);
|
||||
assertEquals(tx.unsafeBitcoinSerialize().length, tx.length);
|
||||
assertEquals(origTxLength, tx.length);
|
||||
block.addTransaction(tx);
|
||||
assertEquals(block.bitcoinSerialize().length, block.length);
|
||||
assertEquals(block.unsafeBitcoinSerialize().length, block.length);
|
||||
assertEquals(origBlockLen + tx.length, block.length);
|
||||
block.getTransactions().get(1).getInputs().get(0).setScriptBytes(new byte[] {(byte) ScriptOpCodes.OP_FALSE, (byte) ScriptOpCodes.OP_FALSE});
|
||||
assertEquals(block.length, origBlockLen + tx.length);
|
||||
assertEquals(tx.length, origTxLength + 1);
|
||||
block.getTransactions().get(1).getInputs().get(0).clearScriptBytes();
|
||||
assertEquals(block.length, block.bitcoinSerialize().length);
|
||||
assertEquals(block.length, block.unsafeBitcoinSerialize().length);
|
||||
assertEquals(block.length, origBlockLen + tx.length);
|
||||
assertEquals(tx.length, origTxLength - 1);
|
||||
block.getTransactions().get(1).addInput(new TransactionInput(params, null, new byte[] {(byte) ScriptOpCodes.OP_FALSE},
|
||||
|
||||
@@ -43,7 +43,7 @@ public class BloomFilterTest {
|
||||
assertTrue(filter.contains(HEX.decode("b9300670b4c5366e95b2699e8b18bc75e5f729c5")));
|
||||
|
||||
// Value generated by Bitcoin Core
|
||||
assertTrue(Arrays.equals(HEX.decode("03614e9b050000000000000001"), filter.bitcoinSerialize()));
|
||||
assertTrue(Arrays.equals(HEX.decode("03614e9b050000000000000001"), filter.unsafeBitcoinSerialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,7 +62,7 @@ public class BloomFilterTest {
|
||||
assertTrue(filter.contains(HEX.decode("b9300670b4c5366e95b2699e8b18bc75e5f729c5")));
|
||||
|
||||
// Value generated by Bitcoin Core
|
||||
assertTrue(Arrays.equals(HEX.decode("03ce4299050000000100008002"), filter.bitcoinSerialize()));
|
||||
assertTrue(Arrays.equals(HEX.decode("03ce4299050000000100008002"), filter.unsafeBitcoinSerialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,6 +87,6 @@ public class BloomFilterTest {
|
||||
BloomFilter filter = wallet.getBloomFilter(wallet.getBloomFilterElementCount(), 0.001, 0);
|
||||
|
||||
// Value generated by Bitcoin Core
|
||||
assertTrue(Arrays.equals(HEX.decode("082ae5edc8e51d4a03080000000000000002"), filter.bitcoinSerialize()));
|
||||
assertTrue(Arrays.equals(HEX.decode("082ae5edc8e51d4a03080000000000000002"), filter.unsafeBitcoinSerialize()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ public class FilteredBlockAndPartialMerkleTreeTests extends TestWithPeerGroup {
|
||||
|
||||
BloomFilter filter = wallet.getBloomFilter(wallet.getKeyChainGroupSize()*2, 0.001, 0xDEADBEEF);
|
||||
// Compare the serialized bloom filter to a known-good value
|
||||
assertArrayEquals(filter.bitcoinSerialize(), HEX.decode("0e1b091ca195e45a9164889b6bc46a09000000efbeadde02"));
|
||||
assertArrayEquals(HEX.decode("0e1b091ca195e45a9164889b6bc46a09000000efbeadde02"), filter.unsafeBitcoinSerialize());
|
||||
|
||||
// Create a peer.
|
||||
peerGroup.start();
|
||||
|
||||
@@ -33,7 +33,7 @@ public class PeerAddressTest
|
||||
String fromSpec = "010000000000000000000000000000000000ffff0a000001208d";
|
||||
PeerAddress pa = new PeerAddress(MainNetParams.get(),
|
||||
HEX.decode(fromSpec), 0, 0);
|
||||
String reserialized = Utils.HEX.encode(pa.bitcoinSerialize());
|
||||
String reserialized = Utils.HEX.encode(pa.unsafeBitcoinSerialize());
|
||||
assertEquals(reserialized,fromSpec );
|
||||
}
|
||||
|
||||
|
||||
@@ -634,7 +634,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
||||
// Now we connect p3 and there is a new bloom filter sent, that DOES match the relevant outpoint.
|
||||
InboundMessageQueuer p3 = connectPeer(3);
|
||||
assertTrue(p3.lastReceivedFilter.contains(key.getPubKey()));
|
||||
assertTrue(p3.lastReceivedFilter.contains(outpoint.bitcoinSerialize()));
|
||||
assertTrue(p3.lastReceivedFilter.contains(outpoint.unsafeBitcoinSerialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1719,10 +1719,10 @@ public class WalletTest extends TestWithWallet {
|
||||
TransactionOutPoint outPoint = new TransactionOutPoint(params, 0, t1);
|
||||
|
||||
// Note that this has a 1e-12 chance of failing this unit test due to a false positive
|
||||
assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.bitcoinSerialize()));
|
||||
assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));
|
||||
|
||||
wallet.receiveFromBlock(t1, b1, BlockChain.NewBlockType.BEST_CHAIN, 0);
|
||||
assertTrue(wallet.getBloomFilter(1e-12).contains(outPoint.bitcoinSerialize()));
|
||||
assertTrue(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1779,10 +1779,10 @@ public class WalletTest extends TestWithWallet {
|
||||
TransactionOutPoint outPoint = new TransactionOutPoint(params, 0, t1);
|
||||
|
||||
// Note that this has a 1e-12 chance of failing this unit test due to a false positive
|
||||
assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.bitcoinSerialize()));
|
||||
assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));
|
||||
|
||||
wallet.receiveFromBlock(t1, b1, BlockChain.NewBlockType.BEST_CHAIN, 0);
|
||||
assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.bitcoinSerialize()));
|
||||
assertFalse(wallet.getBloomFilter(1e-12).contains(outPoint.unsafeBitcoinSerialize()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1798,10 +1798,10 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
TransactionOutPoint outPoint = new TransactionOutPoint(params, 0, t1);
|
||||
|
||||
assertFalse(wallet.getBloomFilter(0.001).contains(outPoint.bitcoinSerialize()));
|
||||
assertFalse(wallet.getBloomFilter(0.001).contains(outPoint.unsafeBitcoinSerialize()));
|
||||
|
||||
wallet.receiveFromBlock(t1, b1, BlockChain.NewBlockType.BEST_CHAIN, 0);
|
||||
assertTrue(wallet.getBloomFilter(0.001).contains(outPoint.bitcoinSerialize()));
|
||||
assertTrue(wallet.getBloomFilter(0.001).contains(outPoint.unsafeBitcoinSerialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2497,7 +2497,7 @@ public class WalletTest extends TestWithWallet {
|
||||
SendRequest request15 = SendRequest.to(notMyAddr, CENT);
|
||||
for (int i = 0; i < 29; i++)
|
||||
request15.tx.addOutput(CENT, notMyAddr);
|
||||
assertTrue(request15.tx.bitcoinSerialize().length > 1000);
|
||||
assertTrue(request15.tx.unsafeBitcoinSerialize().length > 1000);
|
||||
request15.feePerKb = SATOSHI;
|
||||
wallet.completeTx(request15);
|
||||
assertEquals(SATOSHI.multiply(2), request15.tx.getFee());
|
||||
@@ -2514,7 +2514,7 @@ public class WalletTest extends TestWithWallet {
|
||||
request16.feePerKb = ZERO;
|
||||
for (int i = 0; i < 29; i++)
|
||||
request16.tx.addOutput(CENT, notMyAddr);
|
||||
assertTrue(request16.tx.bitcoinSerialize().length > 1000);
|
||||
assertTrue(request16.tx.unsafeBitcoinSerialize().length > 1000);
|
||||
wallet.completeTx(request16);
|
||||
// Of course the fee shouldn't be added if feePerKb == 0
|
||||
assertEquals(ZERO, request16.tx.getFee());
|
||||
@@ -2536,14 +2536,14 @@ public class WalletTest extends TestWithWallet {
|
||||
assertEquals(SATOSHI, request17.tx.getFee());
|
||||
assertEquals(1, request17.tx.getInputs().size());
|
||||
// Calculate its max length to make sure it is indeed 999
|
||||
int theoreticalMaxLength17 = request17.tx.bitcoinSerialize().length + myKey.getPubKey().length + 75;
|
||||
int theoreticalMaxLength17 = request17.tx.unsafeBitcoinSerialize().length + myKey.getPubKey().length + 75;
|
||||
for (TransactionInput in : request17.tx.getInputs())
|
||||
theoreticalMaxLength17 -= in.getScriptBytes().length;
|
||||
assertEquals(999, theoreticalMaxLength17);
|
||||
Transaction spend17 = request17.tx;
|
||||
{
|
||||
// Its actual size must be between 996 and 999 (inclusive) as signatures have a 3-byte size range (almost always)
|
||||
final int length = spend17.bitcoinSerialize().length;
|
||||
final int length = spend17.unsafeBitcoinSerialize().length;
|
||||
assertTrue(Integer.toString(length), length >= 996 && length <= 999);
|
||||
}
|
||||
// Now check that it got a fee of 1 since its max size is 999 (1kb).
|
||||
@@ -2565,13 +2565,13 @@ public class WalletTest extends TestWithWallet {
|
||||
assertEquals(1, request18.tx.getInputs().size());
|
||||
// Calculate its max length to make sure it is indeed 1001
|
||||
Transaction spend18 = request18.tx;
|
||||
int theoreticalMaxLength18 = spend18.bitcoinSerialize().length + myKey.getPubKey().length + 75;
|
||||
int theoreticalMaxLength18 = spend18.unsafeBitcoinSerialize().length + myKey.getPubKey().length + 75;
|
||||
for (TransactionInput in : spend18.getInputs())
|
||||
theoreticalMaxLength18 -= in.getScriptBytes().length;
|
||||
assertEquals(1001, theoreticalMaxLength18);
|
||||
// Its actual size must be between 998 and 1000 (inclusive) as signatures have a 3-byte size range (almost always)
|
||||
assertTrue(spend18.bitcoinSerialize().length >= 998);
|
||||
assertTrue(spend18.bitcoinSerialize().length <= 1001);
|
||||
assertTrue(spend18.unsafeBitcoinSerialize().length >= 998);
|
||||
assertTrue(spend18.unsafeBitcoinSerialize().length <= 1001);
|
||||
// Now check that it did get a fee since its max size is 1000
|
||||
assertEquals(25, spend18.getOutputs().size());
|
||||
// We optimize for priority, so the output selected should be the largest one
|
||||
@@ -2689,7 +2689,7 @@ public class WalletTest extends TestWithWallet {
|
||||
request26.tx.addOutput(CENT, notMyAddr);
|
||||
request26.tx.addOutput(CENT.subtract(
|
||||
Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT)), notMyAddr);
|
||||
assertTrue(request26.tx.bitcoinSerialize().length > 1000);
|
||||
assertTrue(request26.tx.unsafeBitcoinSerialize().length > 1000);
|
||||
request26.feePerKb = SATOSHI;
|
||||
wallet.completeTx(request26);
|
||||
assertEquals(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.add(Transaction.MIN_NONDUST_OUTPUT), request26.tx.getFee());
|
||||
@@ -2755,7 +2755,7 @@ public class WalletTest extends TestWithWallet {
|
||||
|
||||
//
|
||||
SendRequest request4 = SendRequest.to(notMyAddr, balance.subtract(SATOSHI));
|
||||
request4.feePerKb = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.divide(request3.tx.bitcoinSerialize().length);
|
||||
request4.feePerKb = Transaction.REFERENCE_DEFAULT_MIN_TX_FEE.divide(request3.tx.unsafeBitcoinSerialize().length);
|
||||
wallet.completeTx(request4);
|
||||
assertEquals(SATOSHI, request4.tx.getFee());
|
||||
assertEquals(request4.tx.getInputs().size(), i - 2); // We should have spent all inputs - 2
|
||||
|
||||
@@ -112,7 +112,7 @@ public class WalletProtobufSerializerTest {
|
||||
assertEquals(1, wallet1.getTransactions(true).size());
|
||||
assertEquals(v1, wallet1.getBalance(Wallet.BalanceType.ESTIMATED));
|
||||
Transaction t1copy = wallet1.getTransaction(t1.getHash());
|
||||
assertArrayEquals(t1.bitcoinSerialize(), t1copy.bitcoinSerialize());
|
||||
assertArrayEquals(t1.unsafeBitcoinSerialize(), t1copy.unsafeBitcoinSerialize());
|
||||
assertEquals(2, t1copy.getConfidence().numBroadcastPeers());
|
||||
assertNotNull(t1copy.getConfidence().getLastBroadcastedAt());
|
||||
assertEquals(TransactionConfidence.Source.NETWORK, t1copy.getConfidence().getSource());
|
||||
|
||||
@@ -105,7 +105,7 @@ public class GenerateLowSTests {
|
||||
+ inputTransaction.getHashAsString() + "\", "
|
||||
+ output.getIndex() + ", \""
|
||||
+ scriptToString(output.getScriptPubKey()) + "\"]],\n"
|
||||
+ "\"" + Utils.HEX.encode(proposedTransaction.partialTx.bitcoinSerialize()) + "\", \""
|
||||
+ "\"" + Utils.HEX.encode(proposedTransaction.partialTx.unsafeBitcoinSerialize()) + "\", \""
|
||||
+ Script.VerifyFlag.P2SH.name() + "," + Script.VerifyFlag.LOW_S.name() + "\"],");
|
||||
|
||||
final BigInteger highS = HIGH_S_DIFFERENCE.subtract(signature.s);
|
||||
@@ -120,7 +120,7 @@ public class GenerateLowSTests {
|
||||
+ inputTransaction.getHashAsString() + "\", "
|
||||
+ output.getIndex() + ", \""
|
||||
+ scriptToString(output.getScriptPubKey()) + "\"]],\n"
|
||||
+ "\"" + Utils.HEX.encode(proposedTransaction.partialTx.bitcoinSerialize()) + "\", \""
|
||||
+ "\"" + Utils.HEX.encode(proposedTransaction.partialTx.unsafeBitcoinSerialize()) + "\", \""
|
||||
+ Script.VerifyFlag.P2SH.name() + "\"],");
|
||||
|
||||
// Lastly a conventional high-S transaction with the LOW_S flag, for the tx_invalid.json set
|
||||
@@ -129,7 +129,7 @@ public class GenerateLowSTests {
|
||||
+ inputTransaction.getHashAsString() + "\", "
|
||||
+ output.getIndex() + ", \""
|
||||
+ scriptToString(output.getScriptPubKey()) + "\"]],\n"
|
||||
+ "\"" + Utils.HEX.encode(proposedTransaction.partialTx.bitcoinSerialize()) + "\", \""
|
||||
+ "\"" + Utils.HEX.encode(proposedTransaction.partialTx.unsafeBitcoinSerialize()) + "\", \""
|
||||
+ Script.VerifyFlag.P2SH.name() + "," + Script.VerifyFlag.LOW_S.name() + "\"],");
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class TestFeeLevel {
|
||||
request.feePerKb = feeToTest;
|
||||
request.ensureMinRequiredFee = false;
|
||||
kit.wallet().completeTx(request);
|
||||
System.out.println("Size in bytes is " + request.tx.bitcoinSerialize().length);
|
||||
System.out.println("Size in bytes is " + request.tx.unsafeBitcoinSerialize().length);
|
||||
System.out.println("TX is " + request.tx);
|
||||
System.out.println("Waiting for " + kit.peerGroup().getMaxConnections() + " connected peers");
|
||||
kit.peerGroup().addDisconnectedEventListener(new PeerDisconnectedEventListener() {
|
||||
|
||||
Reference in New Issue
Block a user