mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-22 06:21:47 +01:00
Message: rename methods serialize()
and messageSize()
Provide deprecated implementations of `bitcoinSerialize()` and `getMessageSize()`.
This commit is contained in:
parent
6ddf8d8cf5
commit
5eb67285db
32 changed files with 129 additions and 113 deletions
|
@ -922,7 +922,7 @@ public abstract class AbstractBlockChain {
|
|||
try {
|
||||
falsePositives.remove(tx.getTxId());
|
||||
if (clone)
|
||||
tx = Transaction.read(ByteBuffer.wrap(tx.bitcoinSerialize()));
|
||||
tx = Transaction.read(ByteBuffer.wrap(tx.serialize()));
|
||||
listener.receiveFromBlock(tx, block, blockType, relativityOffset++);
|
||||
} catch (ScriptException e) {
|
||||
// We don't want scripts we don't understand to break the block chain so just note that this tx was
|
||||
|
|
|
@ -42,7 +42,7 @@ public abstract class BaseMessage implements Message {
|
|||
* @return serialized data in Bitcoin protocol format
|
||||
*/
|
||||
@Override
|
||||
public final byte[] bitcoinSerialize() {
|
||||
public final byte[] serialize() {
|
||||
// No cached array available so serialize parts by stream.
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream(100); // initial size just a guess
|
||||
try {
|
||||
|
@ -53,10 +53,10 @@ public abstract class BaseMessage implements Message {
|
|||
return stream.toByteArray();
|
||||
}
|
||||
|
||||
/** @deprecated use {@link #bitcoinSerialize()} */
|
||||
/** @deprecated use {@link #serialize()} */
|
||||
@Deprecated
|
||||
public byte[] unsafeBitcoinSerialize() {
|
||||
return bitcoinSerialize();
|
||||
return serialize();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -76,7 +76,7 @@ public abstract class BaseMessage implements Message {
|
|||
* @return size of this object when serialized (in bytes)
|
||||
*/
|
||||
@Override
|
||||
public int getMessageSize() {
|
||||
return bitcoinSerialize().length;
|
||||
public int messageSize() {
|
||||
return serialize().length;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ public class BitcoinSerializer extends MessageSerializer {
|
|||
if (name == null) {
|
||||
throw new Error("BitcoinSerializer doesn't currently know how to serialize " + message.getClass());
|
||||
}
|
||||
serialize(name, message.bitcoinSerialize(), out);
|
||||
serialize(name, message.serialize(), out);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -259,13 +259,13 @@ public class Block extends BaseMessage {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMessageSize() {
|
||||
public int messageSize() {
|
||||
int size = HEADER_SIZE;
|
||||
List<Transaction> transactions = getTransactions();
|
||||
if (transactions != null) {
|
||||
size += VarInt.sizeOf(transactions.size());
|
||||
for (Transaction tx : transactions) {
|
||||
size += tx.getMessageSize();
|
||||
size += tx.messageSize();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
|
@ -1056,7 +1056,7 @@ public class Block extends BaseMessage {
|
|||
// transactions that reference spent or non-existent inputs.
|
||||
if (block.transactions.isEmpty())
|
||||
throw new VerificationException("Block had no transactions");
|
||||
if (block.getMessageSize() > MAX_BLOCK_SIZE)
|
||||
if (block.messageSize() > MAX_BLOCK_SIZE)
|
||||
throw new VerificationException("Block larger than MAX_BLOCK_SIZE");
|
||||
block.checkTransactions(height, flags);
|
||||
block.checkMerkleRoot();
|
||||
|
|
|
@ -33,7 +33,7 @@ public abstract class EmptyMessage extends BaseMessage {
|
|||
}
|
||||
|
||||
@Override
|
||||
public final int getMessageSize() {
|
||||
public final int messageSize() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,12 +32,28 @@ public interface Message {
|
|||
*
|
||||
* @return size of this object when serialized (in bytes)
|
||||
*/
|
||||
int getMessageSize();
|
||||
int messageSize();
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #messageSize()}
|
||||
*/
|
||||
@Deprecated
|
||||
default int getMessageSize() {
|
||||
return messageSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize this message to a byte array that conforms to the Bitcoin wire protocol.
|
||||
*
|
||||
* @return serialized data in Bitcoin protocol format
|
||||
*/
|
||||
byte[] bitcoinSerialize();
|
||||
byte[] serialize();
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #serialize()}
|
||||
*/
|
||||
@Deprecated
|
||||
default byte[] bitcoinSerialize() {
|
||||
return serialize();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1917,7 +1917,7 @@ public class PeerGroup implements TransactionBroadcaster {
|
|||
|
||||
private int countAndMeasureSize(Collection<Transaction> transactions) {
|
||||
for (Transaction transaction : transactions)
|
||||
bytesInLastSecond += transaction.getMessageSize();
|
||||
bytesInLastSecond += transaction.messageSize();
|
||||
return transactions.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ public class StoredBlock {
|
|||
buffer.putInt(getHeight());
|
||||
// Using unsafeBitcoinSerialize here can give us direct access to the same bytes we read off the wire,
|
||||
// avoiding serialization round-trips.
|
||||
byte[] bytes = getHeader().bitcoinSerialize();
|
||||
byte[] bytes = getHeader().serialize();
|
||||
buffer.put(bytes, 0, Block.HEADER_SIZE); // Trim the trailing 00 byte (zero transactions).
|
||||
}
|
||||
|
||||
|
|
|
@ -362,7 +362,7 @@ public class Transaction extends BaseMessage {
|
|||
/** Gets the transaction weight as defined in BIP141. */
|
||||
public int getWeight() {
|
||||
if (!hasWitnesses())
|
||||
return getMessageSize() * 4;
|
||||
return this.messageSize() * 4;
|
||||
try (final ByteArrayOutputStream stream = new ByteArrayOutputStream(255)) { // just a guess at an average tx length
|
||||
bitcoinSerializeToStream(stream, false);
|
||||
final int baseSize = stream.size();
|
||||
|
@ -378,7 +378,7 @@ public class Transaction extends BaseMessage {
|
|||
/** Gets the virtual transaction size as defined in BIP141. */
|
||||
public int getVsize() {
|
||||
if (!hasWitnesses())
|
||||
return getMessageSize();
|
||||
return this.messageSize();
|
||||
return IntMath.divide(getWeight(), 4, RoundingMode.CEILING); // round up
|
||||
}
|
||||
|
||||
|
@ -674,7 +674,7 @@ public class Transaction extends BaseMessage {
|
|||
* can do so.
|
||||
*/
|
||||
public int getMessageSizeForPriorityCalc() {
|
||||
int size = getMessageSize();
|
||||
int size = this.messageSize();
|
||||
for (TransactionInput input : inputs) {
|
||||
// 41: min size of an input
|
||||
// 110: enough to cover a compressed pubkey p2sh redemption (somewhat arbitrary).
|
||||
|
@ -726,7 +726,7 @@ public class Transaction extends BaseMessage {
|
|||
s.append(", wtxid ").append(wTxId);
|
||||
s.append('\n');
|
||||
int weight = getWeight();
|
||||
int size = getMessageSize();
|
||||
int size = this.messageSize();
|
||||
int vsize = getVsize();
|
||||
s.append(indent).append("weight: ").append(weight).append(" wu, ");
|
||||
if (size != vsize)
|
||||
|
@ -1194,7 +1194,7 @@ public class Transaction extends BaseMessage {
|
|||
try {
|
||||
// Create a copy of this transaction to operate upon because we need make changes to the inputs and outputs.
|
||||
// It would not be thread-safe to change the attributes of the transaction object itself.
|
||||
Transaction tx = Transaction.read(ByteBuffer.wrap(bitcoinSerialize()));
|
||||
Transaction tx = Transaction.read(ByteBuffer.wrap(serialize()));
|
||||
|
||||
// Clear input scripts in preparation for signing. If we're signing a fresh
|
||||
// transaction that step isn't very helpful, but it doesn't add much cost relative to the actual
|
||||
|
@ -1423,7 +1423,7 @@ public class Transaction extends BaseMessage {
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMessageSize() {
|
||||
public int messageSize() {
|
||||
boolean useSegwit = hasWitnesses() && allowWitness(protocolVersion);
|
||||
int size = 4; // version
|
||||
if (useSegwit)
|
||||
|
@ -1813,7 +1813,7 @@ public class Transaction extends BaseMessage {
|
|||
public static void verify(Network network, Transaction tx) throws VerificationException {
|
||||
if (tx.inputs.size() == 0 || tx.outputs.size() == 0)
|
||||
throw new VerificationException.EmptyInputsOrOutputs();
|
||||
if (tx.getMessageSize() > Block.MAX_BLOCK_SIZE)
|
||||
if (tx.messageSize() > Block.MAX_BLOCK_SIZE)
|
||||
throw new VerificationException.LargerThanMaxBlockSize();
|
||||
|
||||
HashSet<TransactionOutPoint> outpoints = new HashSet<>();
|
||||
|
|
|
@ -345,7 +345,7 @@ public class PaymentProtocol {
|
|||
@Nullable List<Protos.Output> refundOutputs, @Nullable String memo, @Nullable byte[] merchantData) {
|
||||
Protos.Payment.Builder builder = Protos.Payment.newBuilder();
|
||||
for (Transaction transaction : transactions) {
|
||||
builder.addTransactions(ByteString.copyFrom(transaction.bitcoinSerialize()));
|
||||
builder.addTransactions(ByteString.copyFrom(transaction.serialize()));
|
||||
}
|
||||
if (refundOutputs != null) {
|
||||
for (Protos.Output output : refundOutputs)
|
||||
|
|
|
@ -1744,7 +1744,7 @@ public class Script {
|
|||
// Clone the transaction because executing the script involves editing it, and if we die, we'll leave
|
||||
// the tx half broken (also it's not so thread safe to work on it directly.
|
||||
try {
|
||||
txContainingThis = Transaction.read(ByteBuffer.wrap(txContainingThis.bitcoinSerialize()));
|
||||
txContainingThis = Transaction.read(ByteBuffer.wrap(txContainingThis.serialize()));
|
||||
} catch (ProtocolException e) {
|
||||
throw new RuntimeException(e); // Should not happen unless we were given a totally broken transaction.
|
||||
}
|
||||
|
|
|
@ -222,7 +222,7 @@ public class FakeTxBuilder {
|
|||
* Roundtrip a transaction so that it appears as if it has just come from the wire
|
||||
*/
|
||||
public static Transaction roundTripTransaction(Transaction tx) {
|
||||
return Transaction.read(ByteBuffer.wrap(tx.bitcoinSerialize()));
|
||||
return Transaction.read(ByteBuffer.wrap(tx.serialize()));
|
||||
}
|
||||
|
||||
public static class DoubleSpends {
|
||||
|
|
|
@ -2028,7 +2028,7 @@ public class Wallet extends BaseTaggableObject
|
|||
|
||||
// Clone transaction to avoid multiple wallets pointing to the same transaction. This can happen when
|
||||
// two wallets depend on the same transaction.
|
||||
Transaction cloneTx = params.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(tx.bitcoinSerialize()));
|
||||
Transaction cloneTx = params.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(tx.serialize()));
|
||||
cloneTx.setPurpose(tx.getPurpose());
|
||||
Optional<Instant> updateTime = tx.updateTime();
|
||||
if (updateTime.isPresent())
|
||||
|
@ -2051,7 +2051,7 @@ public class Wallet extends BaseTaggableObject
|
|||
|
||||
// Clone transaction to avoid multiple wallets pointing to the same transaction. This can happen when
|
||||
// two wallets depend on the same transaction.
|
||||
Transaction cloneTx = params.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(tx.bitcoinSerialize()));
|
||||
Transaction cloneTx = params.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(tx.serialize()));
|
||||
cloneTx.setPurpose(tx.getPurpose());
|
||||
Optional<Instant> updateTime = tx.updateTime();
|
||||
if (updateTime.isPresent())
|
||||
|
@ -2647,9 +2647,9 @@ public class Wallet extends BaseTaggableObject
|
|||
// so the exact nature of the mutation can be examined.
|
||||
log.warn("Saw two pending transactions double spend each other");
|
||||
log.warn(" offending input is input {}", tx.getInputs().indexOf(input));
|
||||
log.warn("{}: {}", tx.getTxId(), ByteUtils.formatHex(tx.bitcoinSerialize()));
|
||||
log.warn("{}: {}", tx.getTxId(), ByteUtils.formatHex(tx.serialize()));
|
||||
Transaction other = output.getSpentBy().getParentTransaction();
|
||||
log.warn("{}: {}", other.getTxId(), ByteUtils.formatHex(other.bitcoinSerialize()));
|
||||
log.warn("{}: {}", other.getTxId(), ByteUtils.formatHex(other.serialize()));
|
||||
}
|
||||
} else if (result == TransactionInput.ConnectionResult.SUCCESS) {
|
||||
// Otherwise we saw a transaction spend our coins, but we didn't try and spend them ourselves yet.
|
||||
|
@ -4512,7 +4512,7 @@ public class Wallet extends BaseTaggableObject
|
|||
signTransaction(req);
|
||||
|
||||
// Check size.
|
||||
final int size = req.tx.bitcoinSerialize().length;
|
||||
final int size = req.tx.serialize().length;
|
||||
if (size > Transaction.MAX_STANDARD_TX_SIZE)
|
||||
throw new ExceededMaxTransactionSize();
|
||||
|
||||
|
@ -5721,7 +5721,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.serialize().length < Transaction.MAX_STANDARD_TX_SIZE);
|
||||
return rekeyTx;
|
||||
} catch (VerificationException e) {
|
||||
throw new RuntimeException(e); // Cannot happen.
|
||||
|
|
|
@ -93,6 +93,6 @@ public class AddressV1MessageTest {
|
|||
assertEquals("6hzph5hv6337r6p2.onion", a3.getHostname());
|
||||
assertEquals(0, a3.getPort());
|
||||
|
||||
assertEquals(MESSAGE_HEX, ByteUtils.formatHex(message.bitcoinSerialize()));
|
||||
assertEquals(MESSAGE_HEX, ByteUtils.formatHex(message.serialize()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,6 +114,6 @@ public class AddressV2MessageTest {
|
|||
assertEquals("kpgvmscirrdqpekbqjsvw5teanhatztpp2gl6eee4zkowvwfxwenqaid.onion", a4.getHostname());
|
||||
assertEquals(0, a4.getPort());
|
||||
|
||||
assertEquals(MESSAGE_HEX, ByteUtils.formatHex(message.bitcoinSerialize()));
|
||||
assertEquals(MESSAGE_HEX, ByteUtils.formatHex(message.serialize()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,18 +77,18 @@ public class BitcoinSerializerTest {
|
|||
assertEquals("10.0.0.1", peerAddress.getAddr().getHostAddress());
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream(ADDRESS_MESSAGE_BYTES.length);
|
||||
serializer.serialize(addressMessage, bos);
|
||||
assertEquals(31, addressMessage.getMessageSize());
|
||||
assertEquals(31, addressMessage.messageSize());
|
||||
|
||||
addressMessage.addAddress(PeerAddress.inet(InetAddress.getLocalHost(), MAINNET.getPort(),
|
||||
Services.none(), TimeUtils.currentTime().truncatedTo(ChronoUnit.SECONDS)));
|
||||
bos = new ByteArrayOutputStream(61);
|
||||
serializer.serialize(addressMessage, bos);
|
||||
assertEquals(61, addressMessage.getMessageSize());
|
||||
assertEquals(61, addressMessage.messageSize());
|
||||
|
||||
addressMessage.removeAddress(0);
|
||||
bos = new ByteArrayOutputStream(31);
|
||||
serializer.serialize(addressMessage, bos);
|
||||
assertEquals(31, addressMessage.getMessageSize());
|
||||
assertEquals(31, addressMessage.messageSize());
|
||||
|
||||
//this wont be true due to dynamic timestamps.
|
||||
//assertTrue(LazyParseByteCacheTest.arrayContains(bos.toByteArray(), addrMessage));
|
||||
|
|
|
@ -145,7 +145,7 @@ public class BlockTest {
|
|||
@Test
|
||||
public void testHeaderParse() {
|
||||
Block header = block700000.cloneAsHeader();
|
||||
Block reparsed = TESTNET.getDefaultSerializer().makeBlock(ByteBuffer.wrap(header.bitcoinSerialize()));
|
||||
Block reparsed = TESTNET.getDefaultSerializer().makeBlock(ByteBuffer.wrap(header.serialize()));
|
||||
assertEquals(reparsed, header);
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ public class BlockTest {
|
|||
// proves that transaction serialization works, along with all its subobjects like scripts and in/outpoints.
|
||||
//
|
||||
// NB: This tests the bitcoin serialization protocol.
|
||||
assertArrayEquals(block700000Bytes, block700000.bitcoinSerialize());
|
||||
assertArrayEquals(block700000Bytes, block700000.serialize());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -325,7 +325,7 @@ public class BlockTest {
|
|||
stream.write(VarInt.of(Integer.MAX_VALUE).serialize());
|
||||
}
|
||||
};
|
||||
byte[] serializedBlock = block.bitcoinSerialize();
|
||||
byte[] serializedBlock = block.serialize();
|
||||
try {
|
||||
TESTNET.getDefaultSerializer().makeBlock(ByteBuffer.wrap(serializedBlock));
|
||||
fail("We expect BufferUnderflowException with the fixed code and OutOfMemoryError with the buggy code, so this is weird");
|
||||
|
|
|
@ -54,7 +54,7 @@ public class BloomFilterTest {
|
|||
assertTrue(filter.contains(ByteUtils.parseHex("b9300670b4c5366e95b2699e8b18bc75e5f729c5")));
|
||||
|
||||
// Value generated by Bitcoin Core
|
||||
assertEquals("03614e9b050000000000000001", ByteUtils.formatHex(filter.bitcoinSerialize()));
|
||||
assertEquals("03614e9b050000000000000001", ByteUtils.formatHex(filter.serialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -73,7 +73,7 @@ public class BloomFilterTest {
|
|||
assertTrue(filter.contains(ByteUtils.parseHex("b9300670b4c5366e95b2699e8b18bc75e5f729c5")));
|
||||
|
||||
// Value generated by Bitcoin Core
|
||||
assertEquals("03ce4299050000000100008002", ByteUtils.formatHex(filter.bitcoinSerialize()));
|
||||
assertEquals("03ce4299050000000100008002", ByteUtils.formatHex(filter.serialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -97,6 +97,6 @@ public class BloomFilterTest {
|
|||
BloomFilter filter = wallet.getBloomFilter(wallet.getBloomFilterElementCount(), 0.001, 0);
|
||||
|
||||
// Value generated by Bitcoin Core
|
||||
assertEquals("082ae5edc8e51d4a03080000000000000002", ByteUtils.formatHex(filter.bitcoinSerialize()));
|
||||
assertEquals("082ae5edc8e51d4a03080000000000000002", ByteUtils.formatHex(filter.serialize()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -271,7 +271,7 @@ public class ChainSplitTest {
|
|||
}
|
||||
|
||||
private Block roundtrip(Block b2) throws ProtocolException {
|
||||
return TESTNET.getDefaultSerializer().makeBlock(ByteBuffer.wrap(b2.bitcoinSerialize()));
|
||||
return TESTNET.getDefaultSerializer().makeBlock(ByteBuffer.wrap(b2.serialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -39,7 +39,7 @@ public class FeeFilterMessageTest {
|
|||
FeeFilterMessage ffm = FeeFilterMessage.read(ByteBuffer.wrap(buf));
|
||||
assertEquals(feeRate, ffm.feeRate());
|
||||
|
||||
byte[] serialized = ffm.bitcoinSerialize();
|
||||
byte[] serialized = ffm.serialize();
|
||||
FeeFilterMessage ffm2 = FeeFilterMessage.read(ByteBuffer.wrap(serialized));
|
||||
assertEquals(feeRate, ffm2.feeRate());
|
||||
}
|
||||
|
|
|
@ -193,7 +193,7 @@ public class FullBlockTestGenerator {
|
|||
if (outStream != null && element instanceof BlockAndValidity) {
|
||||
try {
|
||||
ByteUtils.writeInt32BE(params.getPacketMagic(), outStream);
|
||||
byte[] block = ((BlockAndValidity) element).block.bitcoinSerialize();
|
||||
byte[] block = ((BlockAndValidity) element).block.serialize();
|
||||
byte[] length = new byte[4];
|
||||
ByteUtils.writeInt32LE(block.length, length, 0);
|
||||
outStream.write(length);
|
||||
|
@ -447,28 +447,28 @@ public class FullBlockTestGenerator {
|
|||
NewBlock b23 = createNextBlock(b15, chainHeadHeight + 7, out6, null);
|
||||
{
|
||||
Transaction tx = new Transaction();
|
||||
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b23.block.getMessageSize() - 65];
|
||||
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b23.block.messageSize() - 65];
|
||||
Arrays.fill(outputScript, (byte) OP_FALSE);
|
||||
tx.addOutput(new TransactionOutput(tx, ZERO, outputScript));
|
||||
addOnlyInputToTransaction(tx, b23);
|
||||
b23.addTransaction(tx);
|
||||
}
|
||||
b23.solve();
|
||||
checkState(b23.block.getMessageSize() == Block.MAX_BLOCK_SIZE);
|
||||
checkState(b23.block.messageSize() == Block.MAX_BLOCK_SIZE);
|
||||
blocks.add(new BlockAndValidity(b23, true, false, b23.getHash(), chainHeadHeight + 7, "b23"));
|
||||
spendableOutputs.offer(b23.getCoinbaseOutput());
|
||||
|
||||
NewBlock b24 = createNextBlock(b15, chainHeadHeight + 7, out6, null);
|
||||
{
|
||||
Transaction tx = new Transaction();
|
||||
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b24.block.getMessageSize() - 64];
|
||||
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b24.block.messageSize() - 64];
|
||||
Arrays.fill(outputScript, (byte) OP_FALSE);
|
||||
tx.addOutput(new TransactionOutput(tx, ZERO, outputScript));
|
||||
addOnlyInputToTransaction(tx, b24);
|
||||
b24.addTransaction(tx);
|
||||
}
|
||||
b24.solve();
|
||||
checkState(b24.block.getMessageSize() == Block.MAX_BLOCK_SIZE + 1);
|
||||
checkState(b24.block.messageSize() == Block.MAX_BLOCK_SIZE + 1);
|
||||
blocks.add(new BlockAndValidity(b24, false, true, b23.getHash(), chainHeadHeight + 7, "b24"));
|
||||
|
||||
// Extend the b24 chain to make sure bitcoind isn't accepting b24
|
||||
|
@ -717,7 +717,7 @@ public class FullBlockTestGenerator {
|
|||
}
|
||||
b39numP2SHOutputs++;
|
||||
|
||||
while (b39.block.getMessageSize() < Block.MAX_BLOCK_SIZE)
|
||||
while (b39.block.messageSize() < Block.MAX_BLOCK_SIZE)
|
||||
{
|
||||
Transaction tx = new Transaction();
|
||||
|
||||
|
@ -727,7 +727,7 @@ public class FullBlockTestGenerator {
|
|||
tx.addInput(new TransactionInput(tx, new byte[]{OP_1}, lastOutPoint));
|
||||
lastOutPoint = new TransactionOutPoint(1, tx.getTxId());
|
||||
|
||||
if (b39.block.getMessageSize() + tx.getMessageSize() < Block.MAX_BLOCK_SIZE) {
|
||||
if (b39.block.messageSize() + tx.messageSize() < Block.MAX_BLOCK_SIZE) {
|
||||
b39.addTransaction(tx);
|
||||
b39numP2SHOutputs++;
|
||||
} else
|
||||
|
@ -1066,7 +1066,7 @@ public class FullBlockTestGenerator {
|
|||
|
||||
Block b56;
|
||||
try {
|
||||
b56 = params.getDefaultSerializer().makeBlock(ByteBuffer.wrap(b57.block.bitcoinSerialize()));
|
||||
b56 = params.getDefaultSerializer().makeBlock(ByteBuffer.wrap(b57.block.serialize()));
|
||||
} catch (ProtocolException e) {
|
||||
throw new RuntimeException(e); // Cannot happen.
|
||||
}
|
||||
|
@ -1107,7 +1107,7 @@ public class FullBlockTestGenerator {
|
|||
|
||||
Block b56p2;
|
||||
try {
|
||||
b56p2 = params.getDefaultSerializer().makeBlock(ByteBuffer.wrap(b57p2.block.bitcoinSerialize()));
|
||||
b56p2 = params.getDefaultSerializer().makeBlock(ByteBuffer.wrap(b57p2.block.serialize()));
|
||||
} catch (ProtocolException e) {
|
||||
throw new RuntimeException(e); // Cannot happen.
|
||||
}
|
||||
|
@ -1207,15 +1207,15 @@ public class FullBlockTestGenerator {
|
|||
{
|
||||
b64Original = createNextBlock(b60, chainHeadHeight + 19, out18, null);
|
||||
Transaction tx = new Transaction();
|
||||
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b64Original.block.getMessageSize() - 65];
|
||||
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - b64Original.block.messageSize() - 65];
|
||||
Arrays.fill(outputScript, (byte) OP_FALSE);
|
||||
tx.addOutput(new TransactionOutput(tx, ZERO, outputScript));
|
||||
addOnlyInputToTransaction(tx, b64Original);
|
||||
b64Original.addTransaction(tx);
|
||||
b64Original.solve();
|
||||
checkState(b64Original.block.getMessageSize() == Block.MAX_BLOCK_SIZE);
|
||||
checkState(b64Original.block.messageSize() == Block.MAX_BLOCK_SIZE);
|
||||
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream(b64Original.block.getMessageSize() + 8);
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream(b64Original.block.messageSize() + 8);
|
||||
b64Original.block.writeHeader(stream);
|
||||
|
||||
byte[] varIntBytes = new byte[9];
|
||||
|
@ -1230,7 +1230,7 @@ public class FullBlockTestGenerator {
|
|||
|
||||
// The following checks are checking to ensure block serialization functions in the way needed for this test
|
||||
// If they fail, it is likely not an indication of error, but an indication that this test needs rewritten
|
||||
checkState(stream.size() == b64Original.block.getMessageSize() + 8);
|
||||
checkState(stream.size() == b64Original.block.messageSize() + 8);
|
||||
// This check fails because it was created for "retain mode" and the likely encoding is not "optimal".
|
||||
// We since removed this capability retain the original encoding, but could not rewrite this test data.
|
||||
// checkState(stream.size() == b64.getMessageSize());
|
||||
|
@ -1356,7 +1356,7 @@ public class FullBlockTestGenerator {
|
|||
}
|
||||
b72.solve();
|
||||
|
||||
Block b71 = params.getDefaultSerializer().makeBlock(ByteBuffer.wrap(b72.block.bitcoinSerialize()));
|
||||
Block b71 = params.getDefaultSerializer().makeBlock(ByteBuffer.wrap(b72.block.serialize()));
|
||||
b71.addTransaction(b72.block.getTransactions().get(2));
|
||||
checkState(b71.getHash().equals(b72.getHash()));
|
||||
blocks.add(new BlockAndValidity(b71, false, true, b69.getHash(), chainHeadHeight + 21, "b71"));
|
||||
|
@ -1631,7 +1631,7 @@ public class FullBlockTestGenerator {
|
|||
for (int i = 0; i < LARGE_REORG_SIZE; i++) {
|
||||
nextBlock = createNextBlock(nextBlock, nextHeight, largeReorgOutput, null);
|
||||
Transaction tx = new Transaction();
|
||||
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - nextBlock.block.getMessageSize() - 65];
|
||||
byte[] outputScript = new byte[Block.MAX_BLOCK_SIZE - nextBlock.block.messageSize() - 65];
|
||||
Arrays.fill(outputScript, (byte) OP_FALSE);
|
||||
tx.addOutput(new TransactionOutput(tx, ZERO, outputScript));
|
||||
addOnlyInputToTransaction(tx, nextBlock);
|
||||
|
@ -1682,7 +1682,7 @@ public class FullBlockTestGenerator {
|
|||
final int TRANSACTION_CREATION_BLOCKS = 100;
|
||||
for (blockCountAfter1001 = 0; blockCountAfter1001 < TRANSACTION_CREATION_BLOCKS; blockCountAfter1001++) {
|
||||
NewBlock block = createNextBlock(lastBlock, nextHeight++, null, null);
|
||||
while (block.block.getMessageSize() < Block.MAX_BLOCK_SIZE - 500) {
|
||||
while (block.block.messageSize() < Block.MAX_BLOCK_SIZE - 500) {
|
||||
Transaction tx = new Transaction();
|
||||
tx.addInput(lastOutput.hash(), lastOutput.index(), OP_NOP_SCRIPT);
|
||||
tx.addOutput(ZERO, OP_TRUE_SCRIPT);
|
||||
|
@ -1700,7 +1700,7 @@ public class FullBlockTestGenerator {
|
|||
Iterator<Sha256Hash> hashes = hashesToSpend.iterator();
|
||||
for (int i = 0; hashes.hasNext(); i++) {
|
||||
NewBlock block = createNextBlock(lastBlock, nextHeight++, null, null);
|
||||
while (block.block.getMessageSize() < Block.MAX_BLOCK_SIZE - 500 && hashes.hasNext()) {
|
||||
while (block.block.messageSize() < Block.MAX_BLOCK_SIZE - 500 && hashes.hasNext()) {
|
||||
Transaction tx = new Transaction();
|
||||
tx.addInput(hashes.next(), 0, OP_NOP_SCRIPT);
|
||||
tx.addOutput(ZERO, OP_TRUE_SCRIPT);
|
||||
|
|
|
@ -98,17 +98,17 @@ public class ParseByteCacheTest {
|
|||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
serializer.serialize(tx1, bos);
|
||||
tx1BytesWithHeader = bos.toByteArray();
|
||||
tx1Bytes = tx1.bitcoinSerialize();
|
||||
tx1Bytes = tx1.serialize();
|
||||
|
||||
bos.reset();
|
||||
serializer.serialize(tx2, bos);
|
||||
tx2BytesWithHeader = bos.toByteArray();
|
||||
tx2Bytes = tx2.bitcoinSerialize();
|
||||
tx2Bytes = tx2.serialize();
|
||||
|
||||
bos.reset();
|
||||
serializer.serialize(b1, bos);
|
||||
b1BytesWithHeader = bos.toByteArray();
|
||||
b1Bytes = b1.bitcoinSerialize();
|
||||
b1Bytes = b1.serialize();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -173,7 +173,7 @@ public class TransactionTest {
|
|||
@Test
|
||||
public void testMessageSize() {
|
||||
Transaction tx = new Transaction();
|
||||
int length = tx.getMessageSize();
|
||||
int length = tx.messageSize();
|
||||
|
||||
// add fake transaction input
|
||||
TransactionInput input = new TransactionInput(null, ScriptBuilder.createEmpty().program(),
|
||||
|
@ -187,7 +187,7 @@ public class TransactionTest {
|
|||
length += output.getMessageSize();
|
||||
|
||||
// message size has now grown
|
||||
assertEquals(length, tx.getMessageSize());
|
||||
assertEquals(length, tx.messageSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -223,7 +223,7 @@ public class TransactionTest {
|
|||
// verify signature
|
||||
input.getScriptSig().correctlySpends(tx, 0, null, null, ScriptBuilder.createOutputScript(fromAddress), null);
|
||||
|
||||
byte[] rawTx = tx.bitcoinSerialize();
|
||||
byte[] rawTx = tx.serialize();
|
||||
|
||||
assertNotNull(rawTx);
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ public class TransactionTest {
|
|||
input.getScriptSig().correctlySpends(tx, 0, input.getWitness(), input.getValue(),
|
||||
ScriptBuilder.createOutputScript(fromAddress), null);
|
||||
|
||||
byte[] rawTx = tx.bitcoinSerialize();
|
||||
byte[] rawTx = tx.serialize();
|
||||
|
||||
assertNotNull(rawTx);
|
||||
}
|
||||
|
@ -264,11 +264,11 @@ public class TransactionTest {
|
|||
for (TransactionInput in : tx.getInputs())
|
||||
assertFalse(in.hasWitness());
|
||||
assertEquals(3, tx.getOutputs().size());
|
||||
assertEquals(hex, ByteUtils.formatHex(tx.bitcoinSerialize()));
|
||||
assertEquals(hex, ByteUtils.formatHex(tx.serialize()));
|
||||
assertEquals("Uncorrect hash", "38d4cfeb57d6685753b7a3b3534c3cb576c34ca7344cd4582f9613ebf0c2b02a",
|
||||
tx.getTxId().toString());
|
||||
assertEquals(tx.getWTxId(), tx.getTxId());
|
||||
assertEquals(hex.length() / 2, tx.getMessageSize());
|
||||
assertEquals(hex.length() / 2, tx.messageSize());
|
||||
|
||||
// Roundtrip with witness
|
||||
hex = "0100000000010213206299feb17742091c3cb2ab45faa3aa87922d3c030cafb3f798850a2722bf0000000000feffffffa12f2424b9599898a1d30f06e1ce55eba7fabfeee82ae9356f07375806632ff3010000006b483045022100fcc8cf3014248e1a0d6dcddf03e80f7e591605ad0dbace27d2c0d87274f8cd66022053fcfff64f35f22a14deb657ac57f110084fb07bb917c3b42e7d033c54c7717b012102b9e4dcc33c9cc9cb5f42b96dddb3b475b067f3e21125f79e10c853e5ca8fba31feffffff02206f9800000000001976a9144841b9874d913c430048c78a7b18baebdbea440588ac8096980000000000160014e4873ef43eac347471dd94bc899c51b395a509a502483045022100dd8250f8b5c2035d8feefae530b10862a63030590a851183cb61b3672eb4f26e022057fe7bc8593f05416c185d829b574290fb8706423451ebd0a0ae50c276b87b43012102179862f40b85fa43487500f1d6b13c864b5eb0a83999738db0f7a6b91b2ec64f00db080000";
|
||||
|
@ -278,11 +278,11 @@ public class TransactionTest {
|
|||
assertTrue(tx.getInput(0).hasWitness());
|
||||
assertFalse(tx.getInput(1).hasWitness());
|
||||
assertEquals(2, tx.getOutputs().size());
|
||||
assertEquals(hex, ByteUtils.formatHex(tx.bitcoinSerialize()));
|
||||
assertEquals(hex, ByteUtils.formatHex(tx.serialize()));
|
||||
assertEquals("Uncorrect hash", "99e7484eafb6e01622c395c8cae7cb9f8822aab6ba993696b39df8b60b0f4b11",
|
||||
tx.getTxId().toString());
|
||||
assertNotEquals(tx.getWTxId(), tx.getTxId());
|
||||
assertEquals(hex.length() / 2, tx.getMessageSize());
|
||||
assertEquals(hex.length() / 2, tx.messageSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -298,8 +298,8 @@ public class TransactionTest {
|
|||
+ "9093510d00000000" + "1976a914" + "3bde42dbee7e4dbe6a21b2d50ce2f0167faa8159" + "88ac" // txOut
|
||||
+ "11000000"; // nLockTime
|
||||
Transaction tx = Transaction.read(ByteBuffer.wrap(ByteUtils.parseHex(txHex)));
|
||||
assertEquals(txHex, ByteUtils.formatHex(tx.bitcoinSerialize()));
|
||||
assertEquals(txHex.length() / 2, tx.getMessageSize());
|
||||
assertEquals(txHex, ByteUtils.formatHex(tx.serialize()));
|
||||
assertEquals(txHex.length() / 2, tx.messageSize());
|
||||
assertEquals(2, tx.getInputs().size());
|
||||
assertEquals(2, tx.getOutputs().size());
|
||||
TransactionInput txIn0 = tx.getInput(0);
|
||||
|
@ -363,8 +363,8 @@ public class TransactionTest {
|
|||
+ "21" // push length
|
||||
+ "025476c2e83188368da1ff3e292e7acafcdb3566bb0ad253f62fc70f07aeee6357" // push
|
||||
+ "11000000"; // nLockTime
|
||||
assertEquals(signedTxHex, ByteUtils.formatHex(tx.bitcoinSerialize()));
|
||||
assertEquals(signedTxHex.length() / 2, tx.getMessageSize());
|
||||
assertEquals(signedTxHex, ByteUtils.formatHex(tx.serialize()));
|
||||
assertEquals(signedTxHex.length() / 2, tx.messageSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -379,8 +379,8 @@ public class TransactionTest {
|
|||
+ "0008af2f00000000" + "1976a914" + "fd270b1ee6abcaea97fea7ad0402e8bd8ad6d77c" + "88ac" // txOut
|
||||
+ "92040000"; // nLockTime
|
||||
Transaction tx = Transaction.read(ByteBuffer.wrap(ByteUtils.parseHex(txHex)));
|
||||
assertEquals(txHex, ByteUtils.formatHex(tx.bitcoinSerialize()));
|
||||
assertEquals(txHex.length() / 2, tx.getMessageSize());
|
||||
assertEquals(txHex, ByteUtils.formatHex(tx.serialize()));
|
||||
assertEquals(txHex.length() / 2, tx.messageSize());
|
||||
assertEquals(1, tx.getInputs().size());
|
||||
assertEquals(2, tx.getOutputs().size());
|
||||
TransactionInput txIn = tx.getInput(0);
|
||||
|
@ -433,8 +433,8 @@ public class TransactionTest {
|
|||
+ "21" // push length
|
||||
+ "03ad1d8e89212f0b92c74d23bb710c00662ad1470198ac48c43f7d6f93a2a26873" // push
|
||||
+ "92040000"; // nLockTime
|
||||
assertEquals(signedTxHex, ByteUtils.formatHex(tx.bitcoinSerialize()));
|
||||
assertEquals(signedTxHex.length() / 2, tx.getMessageSize());
|
||||
assertEquals(signedTxHex, ByteUtils.formatHex(tx.serialize()));
|
||||
assertEquals(signedTxHex.length() / 2, tx.messageSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -568,7 +568,7 @@ public class TransactionTest {
|
|||
@Test
|
||||
public void testPrioSizeCalc() {
|
||||
Transaction tx1 = FakeTxBuilder.createFakeTx(TESTNET.network(), Coin.COIN, ADDRESS);
|
||||
int size1 = tx1.getMessageSize();
|
||||
int size1 = tx1.messageSize();
|
||||
int size2 = tx1.getMessageSizeForPriorityCalc();
|
||||
assertEquals(113, size1 - size2);
|
||||
tx1.getInput(0).setScriptSig(Script.parse(new byte[109]));
|
||||
|
@ -669,7 +669,7 @@ public class TransactionTest {
|
|||
@Test
|
||||
public void parseTransactionWithHugeDeclaredInputsSize() {
|
||||
Transaction tx = new HugeDeclaredSizeTransaction(true, false, false);
|
||||
byte[] serializedTx = tx.bitcoinSerialize();
|
||||
byte[] serializedTx = tx.serialize();
|
||||
try {
|
||||
Transaction.read(ByteBuffer.wrap(serializedTx));
|
||||
fail("We expect BufferUnderflowException with the fixed code and OutOfMemoryError with the buggy code, so this is weird");
|
||||
|
@ -681,7 +681,7 @@ public class TransactionTest {
|
|||
@Test
|
||||
public void parseTransactionWithHugeDeclaredOutputsSize() {
|
||||
Transaction tx = new HugeDeclaredSizeTransaction(false, true, false);
|
||||
byte[] serializedTx = tx.bitcoinSerialize();
|
||||
byte[] serializedTx = tx.serialize();
|
||||
try {
|
||||
Transaction.read(ByteBuffer.wrap(serializedTx));
|
||||
fail("We expect BufferUnderflowException with the fixed code and OutOfMemoryError with the buggy code, so this is weird");
|
||||
|
@ -693,7 +693,7 @@ public class TransactionTest {
|
|||
@Test
|
||||
public void parseTransactionWithHugeDeclaredWitnessPushCountSize() {
|
||||
Transaction tx = new HugeDeclaredSizeTransaction(false, false, true);
|
||||
byte[] serializedTx = tx.bitcoinSerialize();
|
||||
byte[] serializedTx = tx.serialize();
|
||||
try {
|
||||
Transaction.read(ByteBuffer.wrap(serializedTx));
|
||||
fail("We expect BufferUnderflowException with the fixed code and OutOfMemoryError with the buggy code, so this is weird");
|
||||
|
@ -767,7 +767,7 @@ public class TransactionTest {
|
|||
// example from https://en.bitcoin.it/wiki/Weight_units
|
||||
String txHex = "0100000000010115e180dc28a2327e687facc33f10f2a20da717e5548406f7ae8b4c811072f85603000000171600141d7cd6c75c2e86f4cbf98eaed221b30bd9a0b928ffffffff019caef505000000001976a9141d7cd6c75c2e86f4cbf98eaed221b30bd9a0b92888ac02483045022100f764287d3e99b1474da9bec7f7ed236d6c81e793b20c4b5aa1f3051b9a7daa63022016a198031d5554dbb855bdbe8534776a4be6958bd8d530dc001c32b828f6f0ab0121038262a6c6cec93c2d3ecd6c6072efea86d02ff8e3328bbd0242b20af3425990ac00000000";
|
||||
Transaction tx = Transaction.read(ByteBuffer.wrap(ByteUtils.parseHex(txHex)));
|
||||
assertEquals(218, tx.getMessageSize());
|
||||
assertEquals(218, tx.messageSize());
|
||||
assertEquals(542, tx.getWeight());
|
||||
assertEquals(136, tx.getVsize());
|
||||
}
|
||||
|
@ -777,7 +777,7 @@ public class TransactionTest {
|
|||
// Non segwit tx with zero input and outputs
|
||||
String txHex = "010000000000f1f2f3f4";
|
||||
Transaction tx = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(ByteUtils.parseHex(txHex)));
|
||||
assertEquals(txHex, ByteUtils.formatHex(tx.bitcoinSerialize()));
|
||||
assertEquals(txHex, ByteUtils.formatHex(tx.serialize()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -788,6 +788,6 @@ public class TransactionTest {
|
|||
String txHex = "0100000000010100000000000000016af1f2f3f4";
|
||||
int protoVersionNoWitness = serializer.getProtocolVersion() | Transaction.SERIALIZE_TRANSACTION_NO_WITNESS;
|
||||
Transaction tx = serializer.withProtocolVersion(protoVersionNoWitness).makeTransaction(ByteBuffer.wrap(ByteUtils.parseHex(txHex)));
|
||||
assertEquals(txHex, ByteUtils.formatHex(tx.bitcoinSerialize()));
|
||||
assertEquals(txHex, ByteUtils.formatHex(tx.serialize()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ public class TxConfidenceTableTest {
|
|||
|
||||
@Test
|
||||
public void pinHandlers() {
|
||||
Transaction tx = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(tx1.bitcoinSerialize()));
|
||||
Transaction tx = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(tx1.serialize()));
|
||||
Sha256Hash hash = tx.getTxId();
|
||||
table.seen(hash, address1);
|
||||
assertEquals(1, tx.getConfidence().numBroadcastPeers());
|
||||
|
|
|
@ -74,7 +74,7 @@ public class VersionMessageTest {
|
|||
ver.subVer = "/bitcoinj/";
|
||||
ver.localServices = Services.of(1);
|
||||
ver.receivingAddr = new InetSocketAddress(InetAddress.getByName("4.3.2.1"), 8333);
|
||||
byte[] serialized = ver.bitcoinSerialize();
|
||||
byte[] serialized = ver.serialize();
|
||||
VersionMessage ver2 = VersionMessage.read(ByteBuffer.wrap(serialized));
|
||||
assertEquals(1234, ver2.bestHeight);
|
||||
assertEquals(Instant.ofEpochSecond(23456), ver2.time);
|
||||
|
@ -92,7 +92,7 @@ public class VersionMessageTest {
|
|||
ver.subVer = "/bitcoinj/";
|
||||
ver.localServices = Services.of(1);
|
||||
ver.receivingAddr = new InetSocketAddress(InetAddress.getByName("2002:db8:85a3:0:0:8a2e:370:7335"), 8333);
|
||||
byte[] serialized = ver.bitcoinSerialize();
|
||||
byte[] serialized = ver.serialize();
|
||||
VersionMessage ver2 = VersionMessage.read(ByteBuffer.wrap(serialized));
|
||||
assertEquals(1234, ver2.bestHeight);
|
||||
assertEquals(Instant.ofEpochSecond(23456), ver2.time);
|
||||
|
|
|
@ -147,7 +147,7 @@ public class WalletProtobufSerializerTest {
|
|||
assertEquals(1, wallet1.getTransactions(true).size());
|
||||
assertEquals(v1, wallet1.getBalance(Wallet.BalanceType.ESTIMATED));
|
||||
Transaction t1copy = wallet1.getTransaction(t1.getTxId());
|
||||
assertArrayEquals(t1.bitcoinSerialize(), t1copy.bitcoinSerialize());
|
||||
assertArrayEquals(t1.serialize(), t1copy.serialize());
|
||||
assertEquals(2, t1copy.getConfidence().numBroadcastPeers());
|
||||
assertNotNull(t1copy.getConfidence().lastBroadcastTime());
|
||||
assertEquals(TransactionConfidence.Source.NETWORK, t1copy.getConfidence().getSource());
|
||||
|
|
|
@ -693,7 +693,7 @@ public class WalletTest extends TestWithWallet {
|
|||
// Send 0.10 to somebody else.
|
||||
Transaction send1 = wallet.createSend(OTHER_ADDRESS, valueOf(0, 10));
|
||||
// Reserialize.
|
||||
Transaction send2 = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(send1.bitcoinSerialize()));
|
||||
Transaction send2 = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(send1.serialize()));
|
||||
assertEquals(nanos, send2.getValueSentFromMe(wallet));
|
||||
assertEquals(ZERO.subtract(valueOf(0, 10)), send2.getValue(wallet));
|
||||
}
|
||||
|
@ -709,7 +709,7 @@ public class WalletTest extends TestWithWallet {
|
|||
|
||||
assertTrue(wallet.isConsistent());
|
||||
|
||||
Transaction txClone = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(tx.bitcoinSerialize()));
|
||||
Transaction txClone = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(tx.serialize()));
|
||||
try {
|
||||
wallet.receiveFromBlock(txClone, null, BlockChain.NewBlockType.BEST_CHAIN, 0);
|
||||
fail("Illegal argument not thrown when it should have been.");
|
||||
|
@ -837,7 +837,7 @@ public class WalletTest extends TestWithWallet {
|
|||
// Create a double spend of just the first one.
|
||||
Address BAD_GUY = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Transaction send2 = wallet.createSend(BAD_GUY, COIN);
|
||||
send2 = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(send2.bitcoinSerialize()));
|
||||
send2 = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(send2.serialize()));
|
||||
// Broadcast send1, it's now pending.
|
||||
wallet.commitTx(send1);
|
||||
assertEquals(ZERO, wallet.getBalance()); // change of 10 cents is not yet mined so not included in the balance.
|
||||
|
@ -862,7 +862,7 @@ public class WalletTest extends TestWithWallet {
|
|||
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, value.add(value2));
|
||||
Transaction send1 = Objects.requireNonNull(wallet.createSend(OTHER_ADDRESS, value2));
|
||||
Transaction send2 = Objects.requireNonNull(wallet.createSend(OTHER_ADDRESS, value2));
|
||||
byte[] buf = send1.bitcoinSerialize();
|
||||
byte[] buf = send1.serialize();
|
||||
buf[43] = 0; // Break the signature: bitcoinj won't check in SPV mode and this is easier than other mutations.
|
||||
send1 = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(buf));
|
||||
wallet.commitTx(send2);
|
||||
|
@ -919,7 +919,7 @@ public class WalletTest extends TestWithWallet {
|
|||
// Create a double spend.
|
||||
Address BAD_GUY = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
|
||||
Transaction send2 = wallet.createSend(BAD_GUY, valueOf(0, 50));
|
||||
send2 = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(send2.bitcoinSerialize()));
|
||||
send2 = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(send2.serialize()));
|
||||
// Broadcast send1.
|
||||
wallet.commitTx(send1);
|
||||
assertEquals(send1, received.getOutput(0).getSpentBy().getParentTransaction());
|
||||
|
@ -1347,7 +1347,7 @@ public class WalletTest extends TestWithWallet {
|
|||
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||
Threading.waitForUserCode();
|
||||
assertNull(reasons[0]);
|
||||
final Transaction t1Copy = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(t1.bitcoinSerialize()));
|
||||
final Transaction t1Copy = TESTNET.getDefaultSerializer().makeTransaction(ByteBuffer.wrap(t1.serialize()));
|
||||
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, t1Copy);
|
||||
Threading.waitForUserCode();
|
||||
assertFalse(flags[0]);
|
||||
|
@ -2345,7 +2345,7 @@ public class WalletTest extends TestWithWallet {
|
|||
SendRequest request15 = SendRequest.to(OTHER_ADDRESS, CENT);
|
||||
for (int i = 0; i < 29; i++)
|
||||
request15.tx.addOutput(CENT, OTHER_ADDRESS);
|
||||
assertTrue(request15.tx.bitcoinSerialize().length > 1000);
|
||||
assertTrue(request15.tx.serialize().length > 1000);
|
||||
request15.feePerKb = Transaction.DEFAULT_TX_FEE;
|
||||
request15.ensureMinRequiredFee = true;
|
||||
wallet.completeTx(request15);
|
||||
|
@ -2362,7 +2362,7 @@ public class WalletTest extends TestWithWallet {
|
|||
request16.ensureMinRequiredFee = true;
|
||||
for (int i = 0; i < 29; i++)
|
||||
request16.tx.addOutput(CENT, OTHER_ADDRESS);
|
||||
assertTrue(request16.tx.bitcoinSerialize().length > 1000);
|
||||
assertTrue(request16.tx.serialize().length > 1000);
|
||||
wallet.completeTx(request16);
|
||||
// Just the reference fee should be added if feePerKb == 0
|
||||
// Hardcoded tx length because actual length may vary depending on actual signature length
|
||||
|
@ -2384,14 +2384,14 @@ public class WalletTest extends TestWithWallet {
|
|||
assertEquals(Coin.valueOf(99900), 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.serialize().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.serialize().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).
|
||||
|
@ -2412,13 +2412,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.serialize().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.serialize().length >= 998);
|
||||
assertTrue(spend18.serialize().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
|
||||
|
@ -2524,7 +2524,7 @@ public class WalletTest extends TestWithWallet {
|
|||
Coin dustThresholdMinusOne = new TransactionOutput(null, Coin.COIN, OTHER_ADDRESS).getMinNonDustValue().subtract(SATOSHI);
|
||||
request26.tx.addOutput(CENT.subtract(fee.add(dustThresholdMinusOne)),
|
||||
OTHER_ADDRESS);
|
||||
assertTrue(request26.tx.bitcoinSerialize().length > 1000);
|
||||
assertTrue(request26.tx.serialize().length > 1000);
|
||||
request26.feePerKb = SATOSHI;
|
||||
request26.ensureMinRequiredFee = true;
|
||||
wallet.completeTx(request26);
|
||||
|
|
|
@ -111,7 +111,7 @@ public class GenerateLowSTests {
|
|||
+ inputTransaction.getTxId() + "\", "
|
||||
+ output.getIndex() + ", \""
|
||||
+ scriptToString(output.getScriptPubKey()) + "\"]],\n"
|
||||
+ "\"" + ByteUtils.formatHex(proposedTransaction.partialTx.bitcoinSerialize()) + "\", \""
|
||||
+ "\"" + ByteUtils.formatHex(proposedTransaction.partialTx.serialize()) + "\", \""
|
||||
+ Script.VerifyFlag.P2SH.name() + "," + Script.VerifyFlag.LOW_S.name() + "\"],");
|
||||
|
||||
final BigInteger highS = HIGH_S_DIFFERENCE.subtract(signature.s);
|
||||
|
@ -126,7 +126,7 @@ public class GenerateLowSTests {
|
|||
+ inputTransaction.getTxId() + "\", "
|
||||
+ output.getIndex() + ", \""
|
||||
+ scriptToString(output.getScriptPubKey()) + "\"]],\n"
|
||||
+ "\"" + ByteUtils.formatHex(proposedTransaction.partialTx.bitcoinSerialize()) + "\", \""
|
||||
+ "\"" + ByteUtils.formatHex(proposedTransaction.partialTx.serialize()) + "\", \""
|
||||
+ Script.VerifyFlag.P2SH.name() + "\"],");
|
||||
|
||||
// Lastly a conventional high-S transaction with the LOW_S flag, for the tx_invalid.json set
|
||||
|
@ -135,7 +135,7 @@ public class GenerateLowSTests {
|
|||
+ inputTransaction.getTxId() + "\", "
|
||||
+ output.getIndex() + ", \""
|
||||
+ scriptToString(output.getScriptPubKey()) + "\"]],\n"
|
||||
+ "\"" + ByteUtils.formatHex(proposedTransaction.partialTx.bitcoinSerialize()) + "\", \""
|
||||
+ "\"" + ByteUtils.formatHex(proposedTransaction.partialTx.serialize()) + "\", \""
|
||||
+ Script.VerifyFlag.P2SH.name() + "," + Script.VerifyFlag.LOW_S.name() + "\"],");
|
||||
}
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ public class FilteredBlockAndPartialMerkleTreeTest extends TestWithPeerGroup {
|
|||
assertTrue(txesMatched.contains(Sha256Hash.wrap("63194f18be0af63f2c6bc9dc0f777cbefed3d9415c4af83f3ee3a3d669c00cb5")));
|
||||
|
||||
// Check round tripping.
|
||||
assertEquals(block, FilteredBlock.read(ByteBuffer.wrap(block.bitcoinSerialize())));
|
||||
assertEquals(block, FilteredBlock.read(ByteBuffer.wrap(block.serialize())));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -181,7 +181,7 @@ public class FilteredBlockAndPartialMerkleTreeTest extends TestWithPeerGroup {
|
|||
|
||||
BloomFilter filter = wallet.getBloomFilter(wallet.getKeyChainGroupSize()*2, 0.001, 0xDEADBEEF);
|
||||
// Compare the serialized bloom filter to a known-good value
|
||||
assertArrayEquals(ByteUtils.parseHex("0e1b091ca195e45a9164889b6bc46a09000000efbeadde02"), filter.bitcoinSerialize());
|
||||
assertArrayEquals(ByteUtils.parseHex("0e1b091ca195e45a9164889b6bc46a09000000efbeadde02"), filter.serialize());
|
||||
|
||||
// Create a peer.
|
||||
peerGroup.start();
|
||||
|
|
|
@ -828,7 +828,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
|
|||
// Send the chain that doesn't have all the transactions in it. The blocks after the exhaustion point should all
|
||||
// be ignored.
|
||||
int epoch = wallet.getKeyChainGroupCombinedKeyLookaheadEpochs();
|
||||
BloomFilter filter = BloomFilter.read(ByteBuffer.wrap(p1.lastReceivedFilter.bitcoinSerialize()));
|
||||
BloomFilter filter = BloomFilter.read(ByteBuffer.wrap(p1.lastReceivedFilter.serialize()));
|
||||
filterAndSend(p1, blocks, filter);
|
||||
Block exhaustionPoint = blocks.get(3);
|
||||
pingAndWait(p1);
|
||||
|
|
|
@ -865,7 +865,7 @@ public class PeerTest extends TestWithNetworkConnections {
|
|||
bits = Arrays.copyOf(bits, bits.length / 2);
|
||||
stream.write(bits);
|
||||
}
|
||||
}.bitcoinSerialize(), out);
|
||||
}.serialize(), out);
|
||||
writeTarget.writeTarget.writeBytes(out.toByteArray());
|
||||
try {
|
||||
result.get();
|
||||
|
|
|
@ -86,7 +86,7 @@ public class TestFeeLevel {
|
|||
request.feePerKb = feeRateToTest;
|
||||
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.serialize().length);
|
||||
System.out.println("TX is " + request.tx);
|
||||
System.out.println("Waiting for " + kit.peerGroup().getMaxConnections() + " connected peers");
|
||||
kit.peerGroup().addDisconnectedEventListener((peer, peerCount) -> System.out.println(peerCount +
|
||||
|
|
Loading…
Add table
Reference in a new issue