From 8a99965ac9c705c1469bced7361d9e0a83b3639b Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Thu, 8 Jul 2021 21:58:09 +0200 Subject: [PATCH] UTXO: Remove Java serialization. --- core/src/main/java/org/bitcoinj/core/UTXO.java | 15 ++------------- .../src/test/java/org/bitcoinj/core/UTXOTest.java | 11 +++++------ 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/core/UTXO.java b/core/src/main/java/org/bitcoinj/core/UTXO.java index b6fd8b8e0..52c0a372e 100644 --- a/core/src/main/java/org/bitcoinj/core/UTXO.java +++ b/core/src/main/java/org/bitcoinj/core/UTXO.java @@ -1,5 +1,6 @@ /* * Copyright 2012 Matt Corallo. + * Copyright 2021 Andreas Schildbach * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,10 +31,7 @@ import java.util.Objects; * It avoids having to store the entire parentTransaction just to get the hash and index. * Useful when working with free standing outputs. */ -public class UTXO implements Serializable { - - private static final long serialVersionUID = 4736241649298988166L; - +public class UTXO { private Coin value; private Script script; private Sha256Hash hash; @@ -183,13 +181,4 @@ public class UTXO implements Serializable { in.read(coinbaseByte); coinbase = coinbaseByte[0] == 1; } - - - private void writeObject(ObjectOutputStream o) throws IOException { - serializeToStream(o); - } - - private void readObject(ObjectInputStream o) throws IOException, ClassNotFoundException { - deserializeFromStream(o); - } } diff --git a/core/src/test/java/org/bitcoinj/core/UTXOTest.java b/core/src/test/java/org/bitcoinj/core/UTXOTest.java index bc8f76154..a5ba276d1 100644 --- a/core/src/test/java/org/bitcoinj/core/UTXOTest.java +++ b/core/src/test/java/org/bitcoinj/core/UTXOTest.java @@ -21,8 +21,7 @@ import static org.junit.Assert.assertEquals; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; +import java.io.InputStream; import org.bitcoinj.script.ScriptBuilder; import org.junit.Test; @@ -30,13 +29,13 @@ import org.junit.Test; public class UTXOTest { @Test - public void testJavaSerialization() throws Exception { + public void testSerialization() throws Exception { ECKey key = new ECKey(); UTXO utxo = new UTXO(Sha256Hash.of(new byte[]{1,2,3}), 1, Coin.COIN, 10, true, ScriptBuilder.createP2PKOutputScript(key)); ByteArrayOutputStream os = new ByteArrayOutputStream(); - new ObjectOutputStream(os).writeObject(utxo); - UTXO utxoCopy = (UTXO) new ObjectInputStream( - new ByteArrayInputStream(os.toByteArray())).readObject(); + utxo.serializeToStream(os); + InputStream is = new ByteArrayInputStream(os.toByteArray()); + UTXO utxoCopy = new UTXO(is); assertEquals(utxo, utxoCopy); assertEquals(utxo.getValue(), utxoCopy.getValue()); assertEquals(utxo.getHeight(), utxoCopy.getHeight());