OSDN Git Service

commit java sdk doc and source code
[bytom/bytom-java-sdk.git] / src / main / java / io / bytom / api / Balance.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.lang.reflect.Type;
10 import java.util.List;
11 import java.util.Map;
12
13 public class Balance {
14
15     /**
16      * account id
17      */
18     @SerializedName("account_id")
19     public String accountId;
20
21     /**
22      * name of account
23      */
24     @SerializedName("account_alias")
25     public String accountAlias;
26
27     /**
28      * sum of the unspent outputs.
29      * specified asset balance of account.
30      */
31     public long amount;
32
33     /**
34      * asset id
35      */
36     @SerializedName("asset_id")
37     public String assetId;
38
39     /**
40      * name of asset
41      */
42     @SerializedName("asset_alias")
43     public String assetAlias;
44
45     @SerializedName("asset_definition")
46     public Map<String, Object> definition;
47
48     private static Logger logger = Logger.getLogger(Balance.class);
49
50     /**
51      * Serializes the Balance into a form that is safe to transfer over the wire.
52      *
53      * @return the JSON-serialized representation of the Receiver object
54      */
55     public String toJson() {
56         return Utils.serializer.toJson(this);
57     }
58
59
60     public static class QueryBuilder {
61
62         /**
63          * Call list-Balances api
64          *
65          * @param client
66          * @return
67          * @throws BytomException
68          */
69         public List<Balance> list(Client client) throws BytomException {
70
71             // TODO: 2018/5/23 need tx and test
72             Type listType = new ParameterizedTypeImpl(List.class, new Class[]{Balance.class});
73             List<Balance> balanceList = client.request("list-balances", null, listType);
74             logger.info("list-balances:");
75             logger.info("size of :" + balanceList.size());
76             logger.info(balanceList.get(0).toJson());
77
78             return balanceList;
79         }
80     }
81 }