mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-19 05:33:44 +01:00
UTXO: Remove Java serialization.
This commit is contained in:
parent
d9157218ea
commit
8a99965ac9
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user