forked from DNAProject/DNA-java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransactionOutput.java
More file actions
64 lines (57 loc) · 1.58 KB
/
Copy pathTransactionOutput.java
File metadata and controls
64 lines (57 loc) · 1.58 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
package DNA.Core;
import java.io.IOException;
import DNA.*;
import DNA.IO.*;
import DNA.IO.Json.*;
import DNA.Wallets.Wallet;
/**
* 交易输出
*/
public class TransactionOutput implements Serializable {
/**
* 资产编号
*/
public UInt256 assetId;
/**
* 金额
*/
public Fixed8 value;
/**
* 收款地址
*/
public UInt160 scriptHash;
/**
* byte格式数据反序列化
*/
@Override
public void serialize(BinaryWriter writer) throws IOException {
writer.writeSerializable(assetId);
writer.writeSerializable(value);
writer.writeSerializable(scriptHash);
}
@Override
public void deserialize(BinaryReader reader) throws IOException {
try {
assetId = reader.readSerializable(UInt256.class);
value = reader.readSerializable(Fixed8.class);
scriptHash = reader.readSerializable(UInt160.class);
} catch (InstantiationException | IllegalAccessException e) {
throw new IOException();
}
}
public JObject json(int index) {
JObject json = new JObject();
json.set("n", new JNumber(index));
json.set("asset", new JString(assetId.toString()));
json.set("value", new JString(value.toString()));
json.set("high", new JNumber(value.getData() >> 32));
json.set("low", new JNumber(value.getData() & 0xffffffff));
json.set("address", new JString(Wallet.toAddress(scriptHash)));
return json;
}
@Override
public String toString() {
return "TransactionOutput [assetId=" + assetId + ", value=" + value
+ ", scriptHash=" + scriptHash + "]";
}
}