OSDN Git Service

commit java sdk doc and source code
[bytom/bytom-java-sdk.git] / src / main / java / io / bytom / api / RawTransaction.java
1 package io.bytom.api;
2
3 import com.google.gson.annotations.SerializedName;
4 import io.bytom.common.Utils;
5 import io.bytom.exception.BytomException;
6 import io.bytom.http.Client;
7 import org.apache.log4j.Logger;
8
9 import java.util.HashMap;
10 import java.util.List;
11 import java.util.Map;
12
13 public class RawTransaction {
14     /**
15      * version
16      */
17     public Integer version;
18     /**
19      * size
20      */
21     public Integer size;
22     /**
23      * time_range
24      */
25     @SerializedName("time_range")
26     public Integer timeRange;
27
28     /**
29      * status
30      */
31     public Integer fee;
32
33     /**
34      * List of specified inputs for a transaction.
35      */
36     public List<AnnotatedInput> inputs;
37
38     /**
39      * List of specified outputs for a transaction.
40      */
41     public List<AnnotatedOutput> outputs;
42
43     private static Logger logger = Logger.getLogger(RawTransaction.class);
44
45     public String toJson() {
46         return Utils.serializer.toJson(this);
47     }
48
49
50     public static RawTransaction decode(Client client, String txId) throws BytomException {
51         Map<String, Object> req = new HashMap<String, Object>();
52         req.put("raw_transaction", txId);
53         RawTransaction rawTransaction =
54                 client.request("decode-raw-transaction", req, RawTransaction.class);
55
56         logger.info("decode-raw-transaction:");
57         logger.info(rawTransaction.toJson());
58
59         return rawTransaction;
60     }
61
62     public static class AnnotatedInput {
63
64         /**
65          * address
66          */
67         private String address;
68
69         /**
70          * The number of units of the asset being issued or spent.
71          */
72         private Integer amount;
73
74         /**
75          * The definition of the asset being issued or spent (possibly null).
76          */
77         @SerializedName("asset_definition")
78         private Map<String, Object> assetDefinition;
79
80         /**
81          * The id of the asset being issued or spent.
82          */
83         @SerializedName("asset_id")
84         private String assetId;
85
86         /**
87          * The control program which must be satisfied to transfer this output.
88          */
89         @SerializedName("control_program")
90         private String controlProgram;
91
92         /**
93          * The id of the output consumed by this input. Null if the input is an
94          * issuance.
95          */
96         @SerializedName("spent_output_id")
97         private String spentOutputId;
98
99         /**
100          * The type of the input.<br>
101          * Possible values are "issue" and "spend".
102          */
103         private String type;
104     }
105
106     public static class AnnotatedOutput {
107
108         /**
109          * address
110          */
111         private String address;
112
113         /**
114          * The number of units of the asset being controlled.
115          */
116         private Integer amount;
117
118         /**
119          * The definition of the asset being controlled (possibly null).
120          */
121         @SerializedName("asset_definition")
122         private Map<String, Object> assetDefinition;
123
124         /**
125          * The id of the asset being controlled.
126          */
127         @SerializedName("asset_id")
128         public String assetId;
129
130         /**
131          * The control program which must be satisfied to transfer this output.
132          */
133         @SerializedName("control_program")
134         private String controlProgram;
135
136         /**
137          * The id of the output.
138          */
139         @SerializedName("id")
140         private String id;
141
142         /**
143          * The output's position in a transaction's list of outputs.
144          */
145         private Integer position;
146
147         /**
148          * The type the output.<br>
149          * Possible values are "control" and "retire".
150          */
151         private String type;
152
153     }
154 }