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;
9 import java.util.HashMap;
10 import java.util.List;
13 public class RawTransaction {
17 public Integer version;
25 @SerializedName("time_range")
26 public Integer timeRange;
34 * List of specified inputs for a transaction.
36 public List<AnnotatedInput> inputs;
39 * List of specified outputs for a transaction.
41 public List<AnnotatedOutput> outputs;
43 private static Logger logger = Logger.getLogger(RawTransaction.class);
45 public String toJson() {
46 return Utils.serializer.toJson(this);
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);
56 logger.info("decode-raw-transaction:");
57 logger.info(rawTransaction.toJson());
59 return rawTransaction;
62 public static class AnnotatedInput {
67 private String address;
70 * The number of units of the asset being issued or spent.
72 private Integer amount;
75 * The definition of the asset being issued or spent (possibly null).
77 @SerializedName("asset_definition")
78 private Map<String, Object> assetDefinition;
81 * The id of the asset being issued or spent.
83 @SerializedName("asset_id")
84 private String assetId;
87 * The control program which must be satisfied to transfer this output.
89 @SerializedName("control_program")
90 private String controlProgram;
93 * The id of the output consumed by this input. Null if the input is an
96 @SerializedName("spent_output_id")
97 private String spentOutputId;
100 * The type of the input.<br>
101 * Possible values are "issue" and "spend".
106 public static class AnnotatedOutput {
111 private String address;
114 * The number of units of the asset being controlled.
116 private Integer amount;
119 * The definition of the asset being controlled (possibly null).
121 @SerializedName("asset_definition")
122 private Map<String, Object> assetDefinition;
125 * The id of the asset being controlled.
127 @SerializedName("asset_id")
128 public String assetId;
131 * The control program which must be satisfied to transfer this output.
133 @SerializedName("control_program")
134 private String controlProgram;
137 * The id of the output.
139 @SerializedName("id")
143 * The output's position in a transaction's list of outputs.
145 private Integer position;
148 * The type the output.<br>
149 * Possible values are "control" and "retire".