1+ package org .tron .core .capsule ;
2+
3+ import com .google .protobuf .ByteString ;
4+ import com .google .protobuf .InvalidProtocolBufferException ;
5+ import lombok .extern .slf4j .Slf4j ;
6+ import org .tron .core .exception .BadItemException ;
7+ import org .tron .protos .Protocol .TransactionInfo ;
8+
9+ @ Slf4j
10+ public class TransactionInfoCapsule implements ProtoCapsule <TransactionInfo > {
11+
12+ private TransactionInfo transactionInfo ;
13+
14+ /**
15+ * constructor TransactionCapsule.
16+ */
17+ public TransactionInfoCapsule (TransactionInfo trxRet ) {
18+ this .transactionInfo = trxRet ;
19+ }
20+
21+ public TransactionInfoCapsule (byte [] data ) throws BadItemException {
22+ try {
23+ this .transactionInfo = TransactionInfo .parseFrom (data );
24+ } catch (InvalidProtocolBufferException e ) {
25+ throw new BadItemException ("TransactionInfoCapsule proto data parse exception" );
26+ }
27+ }
28+
29+ public TransactionInfoCapsule () {
30+ this .transactionInfo = TransactionInfo .newBuilder ().build ();
31+ }
32+
33+ public long getFee () {
34+ return transactionInfo .getFee ();
35+ }
36+
37+ public void setId (byte [] id ) {
38+ this .transactionInfo = this .transactionInfo .toBuilder ()
39+ .setId (ByteString .copyFrom (id )).build ();
40+ }
41+
42+ public byte [] getId () {
43+ return transactionInfo .getId ().toByteArray ();
44+ }
45+
46+ public void setFee (long fee ) {
47+ this .transactionInfo = this .transactionInfo .toBuilder ().setFee (fee ).build ();
48+ }
49+
50+ public void addFee (long fee ) {
51+ this .transactionInfo = this .transactionInfo .toBuilder ()
52+ .setFee (this .transactionInfo .getFee () + fee ).build ();
53+ }
54+
55+ public long getBlockNumber () {
56+ return transactionInfo .getBlockNumber ();
57+ }
58+
59+ public void setBlockNumber (long num ) {
60+ this .transactionInfo = this .transactionInfo .toBuilder ().setBlockNumber (num )
61+ .build ();
62+ }
63+
64+ public long getBlockTimeStamp () {
65+ return transactionInfo .getBlockTimeStamp ();
66+ }
67+
68+ public void setBlockTimeStamp (long time ) {
69+ this .transactionInfo = this .transactionInfo .toBuilder ().setBlockTimeStamp (time )
70+ .build ();
71+ }
72+
73+ @ Override
74+ public byte [] getData () {
75+ return this .transactionInfo .toByteArray ();
76+ }
77+
78+ @ Override
79+ public TransactionInfo getInstance () {
80+ return this .transactionInfo ;
81+ }
82+ }
0 commit comments