View Javadoc
1   package org.duniter.core.client.model.bma;
2   
3   /*
4    * #%L
5    * Duniter4j :: Core API
6    * %%
7    * Copyright (C) 2014 - 2015 EIS
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  
26  
27  import com.fasterxml.jackson.annotation.JsonGetter;
28  import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
29  import com.fasterxml.jackson.annotation.JsonSetter;
30  import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
31  
32  import java.io.Serializable;
33  import java.math.BigInteger;
34  
35  /**
36   * A block from the blockchain.
37   * 
38   * @author Benoit Lavenier <benoit.lavenier@e-is.pro>
39   * @since 1.0
40   */
41  @JsonIgnoreProperties(ignoreUnknown=true)
42  public class BlockchainBlock implements Serializable {
43  
44      private static final long serialVersionUID = -5598140972293452669L;
45      
46      private Integer version;
47      private Long nonce;
48      private Integer number;
49      private Integer powMin;
50  	private Long time;
51      private Long medianTime;
52      private Integer membersCount;
53      private BigInteger monetaryMass;
54      private Integer unitbase;
55      private Integer issuersCount;
56      private Integer issuersFrame;
57      private Integer issuersFrameVar;
58      private String currency;
59      private String issuer;
60      private String hash;
61      private String parameters;
62      private String previousHash;
63      private String previousIssuer;
64      private String innerHash;
65      private BigInteger dividend;
66      private Identity[] identities;
67      private Joiner[] joiners;
68      private Joiner[] leavers;
69      private Joiner[] actives;
70      private Revoked[] revoked;
71      private String[] excluded;
72      private Certification[] certifications;
73      private Transaction[] transactions;
74      private String signature;
75  
76  
77  //  raw": "Version: 1\nType: Block\nCurrency: zeta_brouzouf\nNonce: 8233\nNumber: 1\nDate: 1416589860\nConfirmedDate: 1416589860\nIssuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\nPreviousHash: 00006CD96A01378465318E48310118AC6B2F3625\nPreviousIssuer: HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk\nMembersCount: 4\nIdentities:\nJoiners:\nActives:\nLeavers:\nExcluded:\nCertifications:\nTransactions:\n"
78      private String raw;
79  
80      public Integer getVersion() {
81          return version;
82      }
83      public void setVersion(Integer version) {
84          this.version = version;
85      }
86      public Long getNonce() {
87          return nonce;
88      }
89      public void setNonce(Long nonce) {
90          this.nonce = nonce;
91      }
92  
93      public Integer getPowMin() {
94          return powMin;
95      }
96  
97      public void setPowMin(Integer powMin) {
98          this.powMin = powMin;
99      }
100 
101     public Integer getNumber() {
102 		return number;
103 	}
104 	public void setNumber(Integer number) {
105 		this.number = number;
106 	}
107     public Long getTime() {
108         return time;
109     }
110     public void setTime(Long time) {
111         this.time = time;
112     }
113     public Long getMedianTime() {
114         return medianTime;
115     }
116     public void setMedianTime(Long medianTime) {
117         this.medianTime = medianTime;
118     }
119     public Integer getMembersCount() {
120         return membersCount;
121     }
122     public void setMembersCount(Integer membersCount) {
123         this.membersCount = membersCount;
124     }
125 
126     public BigInteger getMonetaryMass() {
127         return monetaryMass;
128     }
129 
130     public void setMonetaryMass(BigInteger monetaryMass) {
131         this.monetaryMass = monetaryMass;
132     }
133 
134     public String getCurrency() {
135         return currency;
136     }
137     public void setCurrency(String currency) {
138         this.currency = currency;
139     }
140     public String getIssuer() {
141         return issuer;
142     }
143     public void setIssuer(String issuer) {
144         this.issuer = issuer;
145     }
146     public String getSignature() {
147         return signature;
148     }
149     public void setSignature(String signature) {
150         this.signature = signature;
151     }
152     public String getHash() {
153         return hash;
154     }
155     public void setHash(String hash) {
156         this.hash = hash;
157     }
158     public String getParameters() {
159         return parameters;
160     }
161     public void setParameters(String parameters) {
162         this.parameters = parameters;
163     }
164     public String getPreviousHash() {
165         return previousHash;
166     }
167     public void setPreviousHash(String previousHash) {
168         this.previousHash = previousHash;
169     }
170     public String getPreviousIssuer() {
171         return previousIssuer;
172     }
173     public void setPreviousIssuer(String previousIssuer) {
174         this.previousIssuer = previousIssuer;
175     }
176     public BigInteger getDividend() {
177         return dividend;
178     }
179     public void setDividend(BigInteger dividend) {
180         this.dividend = dividend;
181     }
182     public Identity[] getIdentities() {
183         return identities;
184     }
185     public void setIdentities(Identity[] identities) {
186         this.identities = identities;
187     }
188     public Joiner[] getJoiners() {
189         return joiners;
190     }
191     public void setJoiners(Joiner[] joiners) {
192         this.joiners = joiners;
193     }
194 
195     public Integer getUnitbase() {
196         return unitbase;
197     }
198 
199     public void setUnitbase(Integer unitbase) {
200         this.unitbase = unitbase;
201     }
202 
203     @JsonGetter("inner_hash")
204     public String getInnerHash() {
205         return innerHash;
206     }
207 
208     @JsonSetter("inner_hash")
209     public void setInnerHash(String inner_hash) {
210         this.innerHash = inner_hash;
211     }
212 
213     public Joiner[] getLeavers() {
214         return leavers;
215     }
216 
217     public void setLeavers(Joiner[] leavers) {
218         this.leavers = leavers;
219     }
220 
221     public Joiner[] getActives() {
222         return actives;
223     }
224 
225     public void setActives(Joiner[] actives) {
226         this.actives = actives;
227     }
228 
229     public Revoked[] getRevoked() {
230         return revoked;
231     }
232 
233     public void setRevoked(Revoked[] revoked) {
234         this.revoked = revoked;
235     }
236 
237     public String[] getExcluded() {
238         return excluded;
239     }
240 
241     public void setExcluded(String[] excluded) {
242         this.excluded = excluded;
243     }
244 
245     public Certification[] getCertifications() {
246         return certifications;
247     }
248 
249     public void setCertifications(Certification[] certifications) {
250         this.certifications = certifications;
251     }
252 
253     public Transaction[] getTransactions() {
254         return transactions;
255     }
256 
257     public void setTransactions(Transaction[] transactions) {
258         this.transactions = transactions;
259     }
260 
261     public Integer getIssuersCount() {
262         return issuersCount;
263     }
264 
265     public void setIssuersCount(Integer issuersCount) {
266         this.issuersCount = issuersCount;
267     }
268 
269     public Integer getIssuersFrame() {
270         return issuersFrame;
271     }
272 
273     public void setIssuersFrame(Integer issuersFrame) {
274         this.issuersFrame = issuersFrame;
275     }
276 
277     public Integer getIssuersFrameVar() {
278         return issuersFrameVar;
279     }
280 
281     public void setIssuersFrameVar(Integer issuersFrameVar) {
282         this.issuersFrameVar = issuersFrameVar;
283     }
284 
285     public String getRaw() {
286         return raw;
287     }
288 
289     public void setRaw(String raw) {
290         this.raw = raw;
291     }
292 
293     public String toString() {
294         String s = "version=" + version;
295         s += "\nnonce=" + nonce;
296         s += "\ninnerHash=" + innerHash;
297         s += "\nnumber=" + number;
298         s += "\npowMin" + powMin;
299         s += "\ntime=" + time;
300         s += "\nmedianTime=" + medianTime;
301         s += "\nmembersCount=" + membersCount;
302         s += "\nmonetaryMass=" + monetaryMass;
303         s += "\ncurrency=" + currency;
304         s += "\nissuer=" + issuer;
305         s += "\nsignature=" + signature;
306         s += "\nhash=" + hash;
307         s += "\nparameters=" + parameters;
308         s += "\npreviousHash=" + previousHash;
309         s += "\npreviousIssuer=" + previousIssuer;
310         s += "\ndividend=" + dividend;
311         s += "\nmembersChanges:";
312         s += "\nidentities:";
313         if (identities != null) {
314             for (Identity i : identities) {
315                 s += "\n\t" + i.toString();
316             }
317         }
318         s += "\njoiners:";
319         if (joiners != null) {
320             for (Joiner j : joiners) {
321                 s += "\n\t" + j.toString();
322             }
323         }
324         s += "\nactives:";
325         if (actives != null) {
326             for (Joiner a : actives) {
327                 s += "\n\t" + a.toString();
328             }
329         }
330         s += "\nleavers:";
331         if (leavers != null) {
332             for (Joiner l : leavers) {
333                 s += "\n\t" + l.toString();
334             }
335         }
336         s += "\nrevoked:";
337         if (leavers != null) {
338             for (Revoked r : revoked) {
339                 s += "\n\t" + r.toString();
340             }
341         }
342         s += "\nexcluded:";
343         if (excluded != null) {
344             for (String e : excluded) {
345                 s += "\n\t" + e;
346             }
347         }
348         s += "\ncertifications:";
349         if (certifications != null) {
350             for (Certification c : certifications) {
351                 s += "\n\t" + c.toString();
352             }
353         }
354 
355         return s;
356     }
357 
358     @JsonDeserialize
359     public static class Identity implements Serializable {
360 
361         private static final long serialVersionUID = 8080689271400316984L;
362 
363         private String publicKey;
364 
365         private String signature;
366 
367         private String blockUid;
368 
369         private String userId;
370 
371         public String getPublicKey() {
372             return publicKey;
373         }
374 
375         public void setPublicKey(String publicKey) {
376             this.publicKey = publicKey;
377         }
378 
379         public String getSignature() {
380             return signature;
381         }
382 
383         public void setSignature(String signature) {
384             this.signature = signature;
385         }
386 
387         public String getUserId() {
388             return userId;
389         }
390 
391         public void setUserId(String uid) {
392             this.userId = uid;
393         }
394 
395 
396         public String getBlockUid() {
397             return blockUid;
398         }
399 
400         public void setBlockUid(String blockUid) {
401             this.blockUid = blockUid;
402         }
403 
404         @Override
405         public String toString() {
406             StringBuilder sb = new StringBuilder()
407                     .append(publicKey)
408                     .append(":").append(signature)
409                     .append(":").append(blockUid)
410                     .append("").append(userId);
411 
412             return sb.toString();
413         }
414     }
415 
416     public static class Joiner extends Identity {
417 
418         private static final long serialVersionUID = 8448049949323699700L;
419 
420         private String publicKey;
421 
422         private String signature;
423 
424         private String userId;
425 
426         private String membershipBlockUid;
427 
428         private String idtyBlockUid;
429 
430         public String getPublicKey() {
431             return publicKey;
432         }
433 
434         public void setPublicKey(String pubkey) {
435             this.publicKey = pubkey;
436         }
437 
438         public String getSignature() {
439             return signature;
440         }
441 
442         public void setSignature(String signature) {
443             this.signature = signature;
444         }
445 
446         public String getUserId() {
447             return userId;
448         }
449 
450         public void setUserId(String uid) {
451             this.userId = uid;
452         }
453 
454         public String getMembershipBlockUid() {
455             return membershipBlockUid;
456         }
457 
458         public void setMembershipBlockUid(String membershipBlockUid) {
459             this.membershipBlockUid = membershipBlockUid;
460         }
461 
462         public String getIdtyBlockUid() {
463             return idtyBlockUid;
464         }
465 
466         public void setIdtyBlockUid(String idtyBlockUid) {
467             this.idtyBlockUid = idtyBlockUid;
468         }
469 
470         @Override
471         public String toString() {
472 
473             StringBuilder sb = new StringBuilder()
474                     .append(publicKey)
475                     .append(":").append(signature)
476                     .append(":").append(membershipBlockUid)
477                     .append(":").append(idtyBlockUid)
478                     .append(":").append(userId);
479 
480             return sb.toString();
481         }
482     }
483 
484 
485     public static class Revoked implements Serializable {
486         private String pubkey;
487         private String signature;
488 
489 
490         public String getPubkey() {
491             return pubkey;
492         }
493 
494         public void setPubkey(String pubkey) {
495             this.pubkey = pubkey;
496         }
497         public String getSignature() {
498             return signature;
499         }
500         public void setSignature(String signature) {
501             this.signature = signature;
502         }
503 
504         @Override
505         public String toString() {
506 
507             StringBuilder sb = new StringBuilder()
508                     .append(pubkey)
509                     .append(":").append(signature);
510 
511             return sb.toString();
512         }
513     }
514 
515     public static class Certification implements Serializable {
516         private String fromPubkey;
517         private String toPubkey;
518         private String blockId;
519         private String signature;
520 
521         public String getFromPubkey() {
522             return fromPubkey;
523         }
524 
525         public void setFromPubkey(String fromPubkey) {
526             this.fromPubkey = fromPubkey;
527         }
528 
529         public String getToPubkey() {
530             return toPubkey;
531         }
532 
533         public void setToPubkey(String toPubkey) {
534             this.toPubkey = toPubkey;
535         }
536 
537         public String getSignature() {
538             return signature;
539         }
540         public void setSignature(String signature) {
541             this.signature = signature;
542         }
543 
544         public String getBlockId() {
545             return blockId;
546         }
547 
548         public void setBlockId(String blockId) {
549             this.blockId = blockId;
550         }
551 
552         @Override
553         public String toString() {
554 
555             StringBuilder sb = new StringBuilder()
556                     .append(fromPubkey)
557                     .append(":").append(toPubkey)
558                     .append(":").append(blockId)
559                     .append(":").append(signature);
560 
561             return sb.toString();
562         }
563     }
564 
565     @JsonIgnoreProperties(ignoreUnknown = true)
566     public static class Transaction implements Serializable {
567         private static final long serialVersionUID = 1L;
568 
569         private String[] signatures;
570 
571         private int version;
572 
573         private String currency;
574 
575         private String[] issuers;
576 
577         private String[] inputs;
578 
579         private String[] unlocks;
580 
581         private String[] outputs;
582 
583         private long time;
584 
585         private long locktime;
586 
587         private String blockstamp;
588 
589         private long blockstampTime;
590 
591         private String comment;
592 
593         private long blockNumber;
594 
595         public String[] getSignatures() {
596             return signatures;
597         }
598 
599         public void setSignatures(String[] signatures) {
600             this.signatures = signatures;
601         }
602 
603         public int getVersion() {
604             return version;
605         }
606 
607         public void setVersion(int version) {
608             this.version = version;
609         }
610 
611         public String getCurrency() {
612             return currency;
613         }
614 
615         public void setCurrency(String currency) {
616             this.currency = currency;
617         }
618 
619         public String[] getIssuers() {
620             return issuers;
621         }
622 
623         public void setIssuers(String[] issuers) {
624             this.issuers = issuers;
625         }
626 
627         public String[] getInputs() {
628             return inputs;
629         }
630 
631         public void setInputs(String[] inputs) {
632             this.inputs = inputs;
633         }
634 
635         public String[] getUnlocks() {
636             return unlocks;
637         }
638 
639         public void setUnlocks(String[] unlocks) {
640             this.unlocks = unlocks;
641         }
642 
643         public String[] getOutputs() {
644             return outputs;
645         }
646 
647         public void setOutputs(String[] outputs) {
648             this.outputs = outputs;
649         }
650 
651         public long getTime() {
652             return time;
653         }
654 
655         public void setTime(long time) {
656             this.time = time;
657         }
658 
659         public long getBlockstampTime() {
660             return blockstampTime;
661         }
662 
663         public void setBlockstampTime(long blockstampTime) {
664             this.blockstampTime = blockstampTime;
665         }
666 
667         public long getLocktime() {
668             return locktime;
669         }
670 
671         public void setLocktime(long locktime) {
672             this.locktime = locktime;
673         }
674 
675         public String getBlockstamp() {
676             return blockstamp;
677         }
678 
679         public void setBlockstamp(String blockstamp) {
680             this.blockstamp = blockstamp;
681         }
682 
683         public String getComment() {
684             return comment;
685         }
686 
687         public void setComment(String comment) {
688             this.comment = comment;
689         }
690 
691         @JsonGetter("block_number")
692         public long getBlockNumber() {
693             return blockNumber;
694         }
695 
696         @JsonSetter("block_number")
697         public void setBlockNumber(long blockNumber) {
698             this.blockNumber = blockNumber;
699         }
700 
701         @Override
702         public String toString() {
703             StringBuilder sb = new StringBuilder();
704             sb.append("\nsignatures:");
705             if (signatures != null) {
706                 for (String e : signatures) {
707                     sb.append("\n\t").append(e);
708                 }
709             }
710             sb.append("\nversion: ").append(version);
711             sb.append("\ncurrency: ").append(currency);
712             sb.append("\nissuers:");
713             if (issuers != null) {
714                 for (String e : issuers) {
715                     sb.append("\n\t").append(e);
716                 }
717             }
718             sb.append("\ninputs:");
719             if (inputs != null) {
720                 for (String e : inputs) {
721                     sb.append("\n\t").append(e);
722                 }
723             }
724             sb.append("\nunlocks:");
725             if (unlocks != null) {
726                 for (String e : unlocks) {
727                     sb.append("\n\t").append(e);
728                 }
729             }
730             sb.append("\noutputs:");
731             if (outputs != null) {
732                 for (String e : outputs) {
733                     sb.append("\n\t").append(e);
734                 }
735             }
736             return sb.toString();
737         }
738     }
739 }