TransactionWitness: rename method messageSize() from getMessageSize()

Keep the old method as deprecated.
This commit is contained in:
Andreas Schildbach 2023-08-10 18:57:20 +02:00
parent c58232ef75
commit e7b11c0713
3 changed files with 12 additions and 4 deletions

View File

@ -1428,7 +1428,7 @@ public class Transaction extends BaseMessage {
size += out.messageSize();
if (useSegwit)
for (TransactionInput in : inputs)
size += in.getWitness().getMessageSize();
size += in.getWitness().messageSize();
size += 4; // locktime
return size;
}

View File

@ -138,7 +138,7 @@ public class TransactionWitness {
* @return byte array containing the transaction witness
*/
public byte[] serialize() {
return write(ByteBuffer.allocate(getMessageSize())).array();
return write(ByteBuffer.allocate(messageSize())).array();
}
/**
@ -147,13 +147,21 @@ public class TransactionWitness {
*
* @return size of the serialized message in bytes
*/
public int getMessageSize() {
public int messageSize() {
int size = VarInt.sizeOf(pushes.size());
for (byte[] push : pushes)
size += VarInt.sizeOf(push.length) + push.length;
return size;
}
/**
* @deprecated Use {@link #messageSize()}
*/
@Deprecated
public int getMessageSize() {
return messageSize();
}
@Override
public String toString() {
List<String> stringPushes = new ArrayList<>(pushes.size());

View File

@ -73,7 +73,7 @@ public class TransactionWitnessTest {
@Test
@Parameters(method = "randomWitness")
public void readAndWrite(TransactionWitness witness) {
ByteBuffer buf = ByteBuffer.allocate(witness.getMessageSize());
ByteBuffer buf = ByteBuffer.allocate(witness.messageSize());
witness.write(buf);
assertFalse(buf.hasRemaining());
((Buffer) buf).rewind();