TransactionInput, TransactionOutPoint: in write(), prefer calling write() over serialize()

The reason is `write()` re-uses the `ByteBuffer`, whereas `serialize()` allocates
an intermediate byte array.
This commit is contained in:
Andreas Schildbach 2025-02-05 13:57:09 +01:00
parent a5aaa8924a
commit f7c7e421fc
2 changed files with 2 additions and 2 deletions

View file

@ -170,7 +170,7 @@ public class TransactionInput {
* @throws BufferOverflowException if the input doesn't fit the remaining buffer
*/
public ByteBuffer write(ByteBuffer buf) throws BufferOverflowException {
buf.put(outpoint.serialize());
outpoint.write(buf);
Buffers.writeLengthPrefixedBytes(buf, scriptBytes);
ByteUtils.writeInt32LE(sequence, buf);
return buf;

View file

@ -103,7 +103,7 @@ public class TransactionOutPoint {
* @throws BufferOverflowException if the outpoint doesn't fit the remaining buffer
*/
public ByteBuffer write(ByteBuffer buf) throws BufferOverflowException {
buf.put(hash.serialize());
hash.write(buf);
ByteUtils.writeInt32LE(index, buf);
return buf;
}