TransactionInput: rename method messageSize() from getMessageSize()

Keep the old method as deprecated.
This commit is contained in:
Andreas Schildbach 2023-08-10 18:54:15 +02:00
parent 210eaf91b3
commit c58232ef75
4 changed files with 13 additions and 5 deletions

View file

@ -1422,7 +1422,7 @@ public class Transaction extends BaseMessage {
size += 2; // marker, flag
size += VarInt.sizeOf(inputs.size());
for (TransactionInput in : inputs)
size += in.getMessageSize();
size += in.messageSize();
size += VarInt.sizeOf(outputs.size());
for (TransactionOutput out : outputs)
size += out.messageSize();

View file

@ -182,7 +182,7 @@ public class TransactionInput {
* @return byte array containing the transaction input
*/
public byte[] serialize() {
return write(ByteBuffer.allocate(getMessageSize())).array();
return write(ByteBuffer.allocate(messageSize())).array();
}
/** @deprecated use {@link #serialize()} */
@ -197,13 +197,21 @@ public class TransactionInput {
*
* @return size of the serialized message in bytes
*/
public int getMessageSize() {
public int messageSize() {
int size = TransactionOutPoint.BYTES;
size += VarInt.sizeOf(scriptBytes.length) + scriptBytes.length;
size += 4; // sequence
return size;
}
/**
* @deprecated Use {@link #messageSize()}
*/
@Deprecated
public int getMessageSize() {
return messageSize();
}
/**
* Coinbase transactions have special inputs with hashes of zero. If this is such an input, returns true.
*/

View file

@ -126,7 +126,7 @@ public class TransactionInputTest {
@Test
@Parameters(method = "randomInputs")
public void readAndWrite(TransactionInput input) {
ByteBuffer buf = ByteBuffer.allocate(input.getMessageSize());
ByteBuffer buf = ByteBuffer.allocate(input.messageSize());
input.write(buf);
assertFalse(buf.hasRemaining());
((Buffer) buf).rewind();

View file

@ -179,7 +179,7 @@ public class TransactionTest {
TransactionInput input = new TransactionInput(null, ScriptBuilder.createEmpty().program(),
new TransactionOutPoint(0, Sha256Hash.ZERO_HASH));
tx.addInput(input);
length += input.getMessageSize();
length += input.messageSize();
// add fake transaction output
TransactionOutput output = new TransactionOutput(null, Coin.COIN, ADDRESS);