-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathCoinFrom.java
150 lines (122 loc) · 3.7 KB
/
CoinFrom.java
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package io.nuls.base.data;
import io.nuls.base.basic.AddressTool;
import io.nuls.base.basic.NulsByteBuffer;
import io.nuls.base.basic.NulsOutputStreamBuffer;
import io.nuls.core.crypto.HexUtil;
import io.nuls.core.exception.NulsException;
import io.nuls.core.parse.SerializeUtils;
import java.io.IOException;
import java.math.BigInteger;
/**
* @author: Charlie
* @date: 2018/11/23
*/
public class CoinFrom extends Coin {
/**
* byte[8]
*/
private byte[] nonce;
/**
* 0Ordinary transactions,-1Unlock amount transaction(Exit consensus, exit delegation)
*/
private byte locked;
public CoinFrom(){}
public CoinFrom(byte[] address, int assetsChainId, int assetsId){
this.address = address;
this.assetsChainId = assetsChainId;
this.assetsId = assetsId;
}
public CoinFrom(byte[] address, int assetsChainId, int assetsId, BigInteger amount, byte locked){
this(address, assetsChainId, assetsId);
this.amount = amount;
this.locked = locked;
}
public CoinFrom(byte[] address, int assetsChainId, int assetsId, BigInteger amount, byte[] nonce, byte locked){
this(address,assetsChainId,assetsId,amount,locked);
this.nonce = nonce;
}
@Override
protected void serializeToStream(NulsOutputStreamBuffer stream) throws IOException {
stream.writeBytesWithLength(address);
stream.writeUint16(assetsChainId);
stream.writeUint16(assetsId);
stream.writeBigInteger(amount);
stream.writeBytesWithLength(nonce);
stream.write(locked);
}
@Override
public void parse(NulsByteBuffer byteBuffer) throws NulsException {
this.address = byteBuffer.readByLengthByte();
this.assetsChainId = byteBuffer.readUint16();
this.assetsId = byteBuffer.readUint16();
this.amount = byteBuffer.readBigInteger();
this.nonce = byteBuffer.readByLengthByte();
this.locked = byteBuffer.readByte();
}
@Override
public int size() {
int size = 0;
size += SerializeUtils.sizeOfBytes(address);
size += SerializeUtils.sizeOfUint16();
size += SerializeUtils.sizeOfUint16();
size += SerializeUtils.sizeOfBigInteger();
size += SerializeUtils.sizeOfBytes(nonce);
size += 1;
return size;
}
@Override
public String toString() {
return "CoinFrom{" +
"address=" + AddressTool.getStringAddressByBytes(address) +
", assetsChainId=" + assetsChainId +
", assetsId=" + assetsId +
", amount=" + amount +
", nonce=" + HexUtil.encode(nonce) +
", locked=" + locked +
'}';
}
@Override
public byte[] getAddress() {
return address;
}
@Override
public void setAddress(byte[] address) {
this.address = address;
}
@Override
public int getAssetsChainId() {
return assetsChainId;
}
@Override
public void setAssetsChainId(int assetsChainId) {
this.assetsChainId = assetsChainId;
}
@Override
public int getAssetsId() {
return assetsId;
}
@Override
public void setAssetsId(int assetsId) {
this.assetsId = assetsId;
}
@Override
public BigInteger getAmount() {
return amount;
}
@Override
public void setAmount(BigInteger amount) {
this.amount = amount;
}
public byte[] getNonce() {
return nonce;
}
public void setNonce(byte[] nonce) {
this.nonce = nonce;
}
public byte getLocked() {
return locked;
}
public void setLocked(byte locked) {
this.locked = locked;
}
}