-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransactionBlock.java
64 lines (53 loc) · 1.47 KB
/
TransactionBlock.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
package DSCoinPackage;
import HelperClasses.MerkleTree;
import HelperClasses.CRF;
public class TransactionBlock {
public Transaction[] trarray;
public TransactionBlock previous;
public MerkleTree Tree;
public String trsummary;
public String nonce;
public String dgst;
public TransactionBlock(Transaction[] t) {
trarray = new Transaction[t.length];
for(int i=0;i<t.length;++i){
trarray[i] = new Transaction();
trarray[i].coinID = t[i].coinID;
trarray[i].Source = t[i].Source;
trarray[i].Destination = t[i].Destination;
trarray[i].coinsrc_block = t[i].coinsrc_block;
trarray[i].next = t[i].next;
}
previous = null;
Tree = new MerkleTree();
trsummary = Tree.Build(trarray);
dgst = null;
}
public boolean checkTransaction (Transaction t) {
TransactionBlock src = t.coinsrc_block;
boolean ret = false;
if(src != null)
for(int i = 0;i<src.trarray.length;++i){
if(src.trarray[i].coinID.compareTo(t.coinID) ==0 && src.trarray[i].Destination.UID.compareTo(t.Source.UID) == 0){
ret = true;
break;
}
}
else{
ret = true;
}
if(!ret)
return ret;
TransactionBlock iter = this.previous;
while((iter!=src)&&ret){
for(int i = 0;i<iter.trarray.length;++i){
if(iter.trarray[i].coinID.compareTo(t.coinID)==0){
ret = false;
break;
}
}
iter = iter.previous;
}
return ret;
}
}