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 {
16 * The id of the asset being controlled.
18 @SerializedName("asset_id")
19 public String assetId;
22 * The alias of the asset being controlled.
24 @SerializedName("asset_alias")
25 public String assetAlias;
28 * The number of units of the asset being controlled.
35 public String address;
38 * whether the account address is change
40 public boolean change;
43 * The ID of the output.
49 * The control program which must be satisfied to transfer this output.
51 @SerializedName("program")
52 public String program;
54 @SerializedName("control_program_index")
55 public String controlProgramIndex;
58 * source unspent output id
60 @SerializedName("source_id")
61 public String sourceId;
64 * position of source unspent output id in block
66 @SerializedName("source_pos")
70 * The definition of the asset being controlled (possibly null).
72 @SerializedName("valid_height")
73 public int validHeight;
75 private static Logger logger = Logger.getLogger(UnspentOutput.class);
78 * Serializes the Address into a form that is safe to transfer over the wire.
80 * @return the JSON-serialized representation of the Receiver object
82 public String toJson() {
83 return Utils.serializer.toJson(this);
86 public static class QueryBuilder {
89 * id of unspent output.
94 * The id of the account controlling this output (possibly null if a control program
97 @SerializedName("account_id")
98 public String accountId;
101 * The alias of the account controlling this output (possibly null if a control
102 * program is specified).
104 @SerializedName("account_alias")
105 public String accountAlias;
107 public Boolean unconfirmed;
109 @SerializedName("smart_contract")
110 public Boolean smartContract;
114 public Integer count;
116 public QueryBuilder setId(String id) {
121 public QueryBuilder setAccountId(String accountId) {
122 this.accountId = accountId;
126 public QueryBuilder setAccountAlias(String accountAlias) {
127 this.accountAlias = accountAlias;
131 public QueryBuilder setSmartContract(boolean smartContract) {
132 this.smartContract = smartContract;
136 public QueryBuilder setUnconfirmed(boolean unconfirmed) {
137 this.unconfirmed = unconfirmed;
141 public QueryBuilder setFrom(Integer from) {
146 public QueryBuilder setCount(Integer count) {
152 * call list-unspent-outputs api
154 * @param client client object that makes requests to the core
156 * @throws BytomException BytomException
158 public List<UnspentOutput> list(Client client) throws BytomException {
160 Type listType = new ParameterizedTypeImpl(List.class, new Class[]{UnspentOutput.class});
161 List<UnspentOutput> unspentOutputList = client.request("list-unspent-outputs", this, listType);
162 logger.info("list-unspent-outputs:");
163 logger.info("size of unspentOutputList:" + unspentOutputList.size());
164 for (UnspentOutput UTXO : unspentOutputList) {
165 logger.info(UTXO.toJson());
168 return unspentOutputList;