3 import com.google.gson.annotations.SerializedName;
4 import io.bytom.common.ParameterizedTypeImpl;
5 import io.bytom.common.Utils;
6 import io.bytom.exception.BytomException;
7 import io.bytom.http.Client;
8 import org.apache.log4j.Logger;
10 import java.lang.reflect.Type;
11 import java.util.List;
13 public class UnspentOutput {
15 * The id of the account controlling this output (possibly null if a control program
18 @SerializedName("account_id")
19 public String accountId;
22 * The alias of the account controlling this output (possibly null if a control
23 * program is specified).
25 @SerializedName("account_alias")
26 public String accountAlias;
29 * The id of the asset being controlled.
31 @SerializedName("asset_id")
32 public String assetId;
35 * The alias of the asset being controlled.
37 @SerializedName("asset_alias")
38 public String assetAlias;
41 * The number of units of the asset being controlled.
48 public String address;
51 * whether the account address is change
53 public boolean change;
56 * The ID of the output.
62 * The control program which must be satisfied to transfer this output.
64 @SerializedName("program")
65 public String program;
67 @SerializedName("control_program_index")
68 public String controlProgramIndex;
71 * source unspent output id
73 @SerializedName("source_id")
74 public String sourceId;
77 * position of source unspent output id in block
79 @SerializedName("source_pos")
83 * The definition of the asset being controlled (possibly null).
85 @SerializedName("valid_height")
86 public int validHeight;
88 private static Logger logger = Logger.getLogger(UnspentOutput.class);
91 * Serializes the Address into a form that is safe to transfer over the wire.
93 * @return the JSON-serialized representation of the Receiver object
95 public String toJson() {
96 return Utils.serializer.toJson(this);
99 public static class QueryBuilder {
102 * id of unspent output.
106 public QueryBuilder setId(String id) {
112 * call list-unspent-outputs api
114 * @param client client object that makes requests to the core
116 * @throws BytomException BytomException
118 public List<UnspentOutput> list(Client client) throws BytomException {
120 Type listType = new ParameterizedTypeImpl(List.class, new Class[]{UnspentOutput.class});
121 List<UnspentOutput> unspentOutputList = client.request("list-unspent-outputs", this, listType);
122 logger.info("list-unspent-outputs:");
123 logger.info("size of unspentOutputList:" + unspentOutputList.size());
124 for (UnspentOutput UTXO : unspentOutputList) {
125 logger.info(UTXO.toJson());
128 return unspentOutputList;