OSDN Git Service

14470930de72a444cc0b44b47c3598a5df9ce9c9
[bytom/bytom-java-sdk.git] / src / main / java / io / bytom / api / UnspentOutput.java
1 package io.bytom.api;
2
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;
9
10 import java.lang.reflect.Type;
11 import java.util.List;
12
13 public class UnspentOutput {
14     /**
15      * The id of the account controlling this output (possibly null if a control program
16      * is specified).
17      */
18     @SerializedName("account_id")
19     public String accountId;
20
21     /**
22      * The alias of the account controlling this output (possibly null if a control
23      * program is specified).
24      */
25     @SerializedName("account_alias")
26     public String accountAlias;
27
28     /**
29      * The id of the asset being controlled.
30      */
31     @SerializedName("asset_id")
32     public String assetId;
33
34     /**
35      * The alias of the asset being controlled.
36      */
37     @SerializedName("asset_alias")
38     public String assetAlias;
39
40     /**
41      * The number of units of the asset being controlled.
42      */
43     public long amount;
44
45     /**
46      * address of account
47      */
48     public String address;
49
50     /**
51      * whether the account address is change
52      */
53     public boolean change;
54
55     /**
56      * The ID of the output.
57      */
58     @SerializedName("id")
59     public String id;
60
61     /**
62      * The control program which must be satisfied to transfer this output.
63      */
64     @SerializedName("program")
65     public String program;
66
67     @SerializedName("control_program_index")
68     public String controlProgramIndex;
69
70     /**
71      * source unspent output id
72      */
73     @SerializedName("source_id")
74     public String sourceId;
75
76     /**
77      * position of source unspent output id in block
78      */
79     @SerializedName("source_pos")
80     public int sourcePos;
81
82     /**
83      * The definition of the asset being controlled (possibly null).
84      */
85     @SerializedName("valid_height")
86     public int validHeight;
87
88     private static Logger logger = Logger.getLogger(UnspentOutput.class);
89
90     /**
91      * Serializes the Address into a form that is safe to transfer over the wire.
92      *
93      * @return the JSON-serialized representation of the Receiver object
94      */
95     public String toJson() {
96         return Utils.serializer.toJson(this);
97     }
98
99     public static class QueryBuilder {
100
101         /**
102          * id of unspent output.
103          */
104         public String id;
105
106         public QueryBuilder setId(String id) {
107             this.id = id;
108             return this;
109         }
110
111         /**
112          * call list-unspent-outputs api
113          *
114          * @param client client object that makes requests to the core
115          * @return
116          * @throws BytomException BytomException
117          */
118         public List<UnspentOutput> list(Client client) throws BytomException {
119
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());
126             }
127
128             return unspentOutputList;
129         }
130
131     }
132 }