forked from DNAProject/DNA-java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionInput.java
More file actions
77 lines (69 loc) · 1.81 KB
/
Copy pathTransactionInput.java
File metadata and controls
77 lines (69 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package DNA.Core;
import java.io.IOException;
import DNA.UInt256;
import DNA.IO.BinaryReader;
import DNA.IO.BinaryWriter;
import DNA.IO.Serializable;
import DNA.IO.Json.JNumber;
import DNA.IO.Json.JObject;
import DNA.IO.Json.JString;
/**
* 交易输入
*/
public class TransactionInput implements Serializable {
/**
* 引用交易的散列值
*/
public UInt256 prevHash;
/**
* 引用交易输出的索引
*/
public short prevIndex;
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (null == obj) {
return false;
}
if (!(obj instanceof TransactionInput)) {
return false;
}
TransactionInput other = (TransactionInput) obj;
return prevHash.equals(other.prevHash) && prevIndex == other.prevIndex;
}
@Override
public int hashCode() {
return prevHash.hashCode() + prevIndex;
}
/**
* byte格式数据反序列化
*/
@Override
public void deserialize(BinaryReader reader) throws IOException {
try {
prevHash = reader.readSerializable(UInt256.class);
prevIndex = reader.readShort();
// prevIndex = (short) reader.readVarInt();
} catch (InstantiationException | IllegalAccessException e) {
}
}
@Override
public void serialize(BinaryWriter writer) throws IOException {
writer.writeSerializable(prevHash);
writer.writeShort(prevIndex);
// writer.writeVarInt(prevIndex);
}
public JObject json() {
JObject json = new JObject();
json.set("txid", new JString(prevHash.toString()));
json.set("vout", new JNumber(Short.toUnsignedInt(prevIndex)));
return json;
}
@Override
public String toString() {
return "TransactionInput [prevHash=" + prevHash + ", prevIndex="
+ prevIndex + "]";
}
}