18
18
package org .twostack .bitcoin .address ;
19
19
20
20
import org .twostack .bitcoin .params .NetworkAddressType ;
21
+ import org .twostack .bitcoin .params .NetworkType ;
21
22
23
+ import java .io .IOException ;
24
+ import java .io .ObjectInputStream ;
25
+ import java .io .ObjectOutputStream ;
22
26
import java .io .Serializable ;
27
+ import java .lang .reflect .Field ;
23
28
import java .util .Arrays ;
24
29
import java .util .Objects ;
25
30
39
44
* </p>
40
45
*/
41
46
public abstract class PrefixedChecksummedBytes implements Serializable , Cloneable {
42
- protected final transient NetworkAddressType networkAddressType ;
47
+ protected final transient NetworkType networkType ;
43
48
protected final byte [] bytes ;
44
49
45
- protected PrefixedChecksummedBytes (NetworkAddressType networkAddressType , byte [] bytes ) {
46
- this .networkAddressType = checkNotNull (networkAddressType );
50
+ protected PrefixedChecksummedBytes (NetworkType networkType , byte [] bytes ) {
51
+ this .networkType = checkNotNull (networkType );
47
52
this .bytes = checkNotNull (bytes );
48
53
}
49
54
50
55
/**
51
56
* @return network this data is valid for
52
57
*/
53
- public final NetworkAddressType getNetworkAddressType () {
54
- return networkAddressType ;
58
+ public final NetworkType getNetworkType () {
59
+ return networkType ;
55
60
}
56
61
62
+
57
63
@ Override
58
64
public int hashCode () {
59
- return Objects .hash (networkAddressType , Arrays .hashCode (bytes ));
65
+ return Objects .hash (networkType , Arrays .hashCode (bytes ));
60
66
}
61
67
62
68
@ Override
63
69
public boolean equals (Object o ) {
64
70
if (this == o ) return true ;
65
71
if (o == null || getClass () != o .getClass ()) return false ;
66
72
PrefixedChecksummedBytes other = (PrefixedChecksummedBytes ) o ;
67
- return this .networkAddressType .equals (other .networkAddressType ) && Arrays .equals (this .bytes , other .bytes );
73
+ return this .networkType .equals (other .networkType ) && Arrays .equals (this .bytes , other .bytes );
68
74
}
69
75
70
76
/**
@@ -78,21 +84,21 @@ public PrefixedChecksummedBytes clone() throws CloneNotSupportedException {
78
84
}
79
85
80
86
// Java serialization
81
- //
82
- // private void writeObject(ObjectOutputStream out) throws IOException {
83
- // out.defaultWriteObject();
84
- // out.writeUTF(params.getId());
85
- // }
86
87
87
- // private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
88
- // in.defaultReadObject();
89
- // try {
90
- // Field paramsField = PrefixedChecksummedBytes.class.getDeclaredField("params");
91
- // paramsField.setAccessible(true);
92
- // paramsField.set(this, checkNotNull(NetworkParameters.fromID(in.readUTF())));
93
- // paramsField.setAccessible(false);
94
- // } catch (NoSuchFieldException | IllegalAccessException x) {
95
- // throw new RuntimeException(x);
96
- // }
97
- // }
88
+ private void writeObject (ObjectOutputStream out ) throws IOException {
89
+ out .defaultWriteObject ();
90
+ out .writeUTF (networkType .name ());
91
+ }
92
+
93
+ private void readObject (ObjectInputStream in ) throws IOException , ClassNotFoundException {
94
+ in .defaultReadObject ();
95
+ try {
96
+ Field paramsField = PrefixedChecksummedBytes .class .getDeclaredField ("networkType" );
97
+ paramsField .setAccessible (true );
98
+ paramsField .set (this , checkNotNull (NetworkType .valueOf (in .readUTF ())));
99
+ paramsField .setAccessible (false );
100
+ } catch (NoSuchFieldException | IllegalAccessException x ) {
101
+ throw new RuntimeException (x );
102
+ }
103
+ }
98
104
}
0 commit comments