• R/O
  • HTTP
  • SSH
  • HTTPS

bytom-java-sdk: Commit

Official Java SDK for Bytom


Commit MetaInfo

Révision993ff69166b981bef22f701c0aed3269519e3295 (tree)
l'heure2018-06-14 20:15:59
Auteursuccessli <successli@outl...>
Commitersuccessli

Message de Log

add createBatch and deleteBatch method to account, and test it.

Change Summary

Modification

--- a/src/main/java/io/bytom/api/Account.java
+++ b/src/main/java/io/bytom/api/Account.java
@@ -2,12 +2,15 @@ package io.bytom.api;
22
33 import com.google.gson.Gson;
44 import com.google.gson.annotations.SerializedName;
5+import com.sun.org.apache.xpath.internal.operations.Bool;
56 import io.bytom.common.ParameterizedTypeImpl;
67 import io.bytom.common.Utils;
78 import io.bytom.exception.*;
9+import io.bytom.http.BatchResponse;
810 import io.bytom.http.Client;
911 import org.apache.log4j.Logger;
1012
13+import java.io.IOException;
1114 import java.lang.reflect.Type;
1215 import java.util.*;
1316
@@ -40,7 +43,7 @@ public class Account {
4043 /**
4144 * create-account
4245 *
43- * @param client client object that makes requests to the core
46+ * @param client client object that makes requests to the core
4447 * @param builder Account.Builder to make parameters
4548 * @return Account return a account object
4649 * @throws BytomException BytomException
@@ -53,6 +56,62 @@ public class Account {
5356 }
5457
5558 /**
59+ * create-batch-account
60+ *
61+ * @param client
62+ * @param builders
63+ * @return
64+ */
65+ public static BatchResponse<Account> createBatch(Client client, List<Builder> builders) {
66+
67+ Map<Integer, Account> successes = new HashMap<>();
68+ Map<Integer, BytomException> errors = new HashMap<>();
69+ //record create account sequence
70+ Integer seq = 0;
71+ for (Builder builder : builders) {
72+ try {
73+ Account account = client.request("create-account", builder, Account.class);
74+ successes.put(seq, account);
75+ } catch (BytomException bytomException) {
76+ errors.put(seq, bytomException);
77+ logger.info("Create No."+(seq+1) +" "+"account failed."+bytomException.getMessage());
78+ logger.info("You can call create() method in Account class to create this account again.");
79+ }
80+ seq ++;
81+ }
82+ return new BatchResponse<>(successes, errors);
83+ }
84+
85+ /**
86+ * delete batch account
87+ *
88+ * @param client
89+ * @param accountInfos
90+ * @return
91+ */
92+ public static BatchResponse<Boolean> deleteBatch(Client client, List<String> accountInfos) {
93+ Map<Integer, Boolean> successes = new HashMap<>();
94+ Map<Integer, BytomException> errors = new HashMap<>();
95+ //record delete account sequence
96+ Integer seq = 0;
97+ for (String accountInfo : accountInfos) {
98+ try {
99+ Map<String, String> req = new HashMap<>();
100+ req.put("account_info", accountInfo);
101+ client.request("delete-account", req);
102+
103+ successes.put(seq, Boolean.TRUE);
104+ } catch (BytomException bytomException) {
105+ errors.put(seq, bytomException);
106+ logger.info("Delete No."+(seq+1) +" "+"account_info is "+accountInfo+" failed."+bytomException.getMessage());
107+ logger.info("You can call delete() method in Account class to delete this account again.");
108+ }
109+ seq ++;
110+ }
111+ return new BatchResponse<>(successes, errors);
112+ }
113+
114+ /**
56115 * list-accounts
57116 *
58117 * @param client client object that makes requests to the core
@@ -63,14 +122,15 @@ public class Account {
63122 Type listType = new ParameterizedTypeImpl(List.class, new Class[]{Account.class});
64123 List<Account> accountList = client.request("list-accounts", null, listType);
65124 logger.info("list-accounts:");
66- logger.info("size of accountList:"+accountList.size());
125+ logger.info("size of accountList:" + accountList.size());
67126 logger.info(accountList);
68127 return accountList;
69128 }
70129
71130 /**
72131 * delete-account
73- * @param client client object that makes requests to the core
132+ *
133+ * @param client client object that makes requests to the core
74134 * @param account_info account_info
75135 * @throws BytomException BytomException
76136 */
@@ -82,12 +142,13 @@ public class Account {
82142
83143 public static class Builder {
84144
85- public List<String> root_xpubs;
145+ public List<String> root_xpubs = new ArrayList<>();
86146
87147 public String alias;
88148
89149 public Integer quorum;
90150
151+
91152 /**
92153 * add a xpub to root_xpubs
93154 *
@@ -112,6 +173,7 @@ public class Account {
112173
113174 /**
114175 * set alias to alias
176+ *
115177 * @param alias alias
116178 * @return this Builder object
117179 */
@@ -283,6 +345,7 @@ public class Account {
283345
284346 /**
285347 * list-addresses
348+ *
286349 * @param client client object that makes requests to the core
287350 * @return list of address object
288351 * @throws BytomException BytomException
@@ -299,7 +362,8 @@ public class Account {
299362
300363 /**
301364 * validate-address
302- * @param client client object that makes requests to the core
365+ *
366+ * @param client client object that makes requests to the core
303367 * @param address an address string
304368 * @return an address object
305369 * @throws BytomException BytomException
--- a/src/main/java/io/bytom/exception/APIException.java
+++ b/src/main/java/io/bytom/exception/APIException.java
@@ -46,124 +46,133 @@ import com.google.gson.annotations.SerializedName;
4646 * CH761 - Some outputs are reserved; try again<br>
4747 */
4848 public class APIException extends BytomException {
49- /**
50- * Unique identifier for the error.
51- */
52- public String code;
53-
54- /**
55- * Message describing the general nature of the error.
56- */
57- @SerializedName("message")
58- public String chainMessage;
59-
60- /**
61- * Additional information about the error (possibly null).
62- */
63- public String detail;
64-
65- /**
66- * Specifies whether the error is temporary, or a change to the request is necessary.
67- */
68- public boolean temporary;
69-
70- /**
71- * Unique identifier of the request to the server.
72- */
73- public String requestId;
74-
75- /**
76- * HTTP status code returned by the server.
77- */
78- public int statusCode;
79-
80- /**
81- * Initializes exception with its message and requestId attributes.
82- * @param message error message
83- * @param requestId unique identifier of the request
84- */
85- public APIException(String message, String requestId) {
86- super(message);
87- this.requestId = requestId;
88- }
89-
90- /**
91- * Intitializes exception with its code, message, detail &amp; temporary field set.
92- * @param code error code
93- * @param message error message
94- * @param detail additional error information
95- * @param temporary unique identifier of the request
96- */
97- public APIException(String code, String message, String detail, boolean temporary) {
98- super(message);
99- this.chainMessage = message;
100- this.code = code;
101- this.detail = detail;
102- this.temporary = temporary;
103- }
104-
105- /**
106- * Initializes exception with its code, message, detail &amp; requestId attributes.
107- * @param code error code
108- * @param message error message
109- * @param detail additional error information
110- * @param requestId unique identifier of the request
111- */
112- public APIException(String code, String message, String detail, String requestId) {
113- super(message);
114- this.chainMessage = message;
115- this.code = code;
116- this.detail = detail;
117- this.requestId = requestId;
118- }
119-
120- /**
121- * Initializes exception with all of its attributes.
122- * @param code error code
123- * @param message error message
124- * @param detail additional error information
125- * @param temporary specifies if the error is temporary
126- * @param requestId unique identifier of the request
127- * @param statusCode HTTP status code
128- */
129- public APIException(
130- String code,
131- String message,
132- String detail,
133- boolean temporary,
134- String requestId,
135- int statusCode) {
136- super(message);
137- this.chainMessage = message;
138- this.code = code;
139- this.detail = detail;
140- this.temporary = temporary;
141- this.requestId = requestId;
142- this.statusCode = statusCode;
143- }
144-
145- /**
146- * Constructs a detailed message of the error.
147- * @return detailed error message
148- */
149- @Override
150- public String getMessage() {
151- String s = "";
152-
153- if (this.code != null && this.code.length() > 0) {
154- s += "Code: " + this.code + " ";
49+ /**
50+ * Unique identifier for the error.
51+ */
52+ public String code;
53+
54+ /**
55+ * Message describing the general nature of the error.
56+ */
57+ @SerializedName("message")
58+ public String chainMessage;
59+
60+ /**
61+ * Additional information about the error (possibly null).
62+ */
63+ public String detail;
64+
65+ /**
66+ * Specifies whether the error is temporary, or a change to the request is necessary.
67+ */
68+ public boolean temporary;
69+
70+ /**
71+ * Unique identifier of the request to the server.
72+ */
73+ public String requestId;
74+
75+ /**
76+ * HTTP status code returned by the server.
77+ */
78+ public int statusCode;
79+
80+ public APIException(String message) {
81+ super(message);
15582 }
15683
157- s += "Message: " + this.chainMessage;
84+ /**
85+ * Initializes exception with its message and requestId attributes.
86+ *
87+ * @param message error message
88+ * @param requestId unique identifier of the request
89+ */
90+ public APIException(String message, String requestId) {
91+ super(message);
92+ this.requestId = requestId;
93+ }
94+
95+ /**
96+ * Intitializes exception with its code, message, detail &amp; temporary field set.
97+ *
98+ * @param code error code
99+ * @param message error message
100+ * @param detail additional error information
101+ * @param temporary unique identifier of the request
102+ */
103+ public APIException(String code, String message, String detail, boolean temporary) {
104+ super(message);
105+ this.chainMessage = message;
106+ this.code = code;
107+ this.detail = detail;
108+ this.temporary = temporary;
109+ }
158110
159- if (this.detail != null && this.detail.length() > 0) {
160- s += " Detail: " + this.detail;
111+ /**
112+ * Initializes exception with its code, message, detail &amp; requestId attributes.
113+ *
114+ * @param code error code
115+ * @param message error message
116+ * @param detail additional error information
117+ * @param requestId unique identifier of the request
118+ */
119+ public APIException(String code, String message, String detail, String requestId) {
120+ super(message);
121+ this.chainMessage = message;
122+ this.code = code;
123+ this.detail = detail;
124+ this.requestId = requestId;
161125 }
162126
163- if (this.requestId != null) {
164- s += " Request-ID: " + this.requestId;
127+ /**
128+ * Initializes exception with all of its attributes.
129+ *
130+ * @param code error code
131+ * @param message error message
132+ * @param detail additional error information
133+ * @param temporary specifies if the error is temporary
134+ * @param requestId unique identifier of the request
135+ * @param statusCode HTTP status code
136+ */
137+ public APIException(
138+ String code,
139+ String message,
140+ String detail,
141+ boolean temporary,
142+ String requestId,
143+ int statusCode) {
144+ super(message);
145+ this.chainMessage = message;
146+ this.code = code;
147+ this.detail = detail;
148+ this.temporary = temporary;
149+ this.requestId = requestId;
150+ this.statusCode = statusCode;
165151 }
166152
167- return s;
168- }
153+ /**
154+ * Constructs a detailed message of the error.
155+ *
156+ * @return detailed error message
157+ */
158+ @Override
159+ public String getMessage() {
160+ String s = "";
161+
162+ if (this.code != null && this.code.length() > 0) {
163+ s += "Code: " + this.code + " ";
164+ }
165+
166+ s += "Message: " + this.chainMessage;
167+
168+ if (this.detail != null && this.detail.length() > 0) {
169+ s += " Detail: " + this.detail;
170+ }
171+
172+ if (this.requestId != null) {
173+ s += " Request-ID: " + this.requestId;
174+ }
175+
176+ return s;
177+ }
169178 }
--- a/src/main/java/io/bytom/http/BatchResponse.java
+++ b/src/main/java/io/bytom/http/BatchResponse.java
@@ -1,140 +1,114 @@
11 package io.bytom.http;
22
3-import io.bytom.exception.*;
4-import com.google.gson.Gson;
5-import com.google.gson.JsonArray;
6-import com.google.gson.JsonElement;
7-import com.google.gson.JsonParser;
8-import com.squareup.okhttp.Response;
3+import io.bytom.common.Utils;
4+import io.bytom.exception.BytomException;
95
10-import java.io.IOException;
11-import java.lang.reflect.Type;
126 import java.util.*;
137
148 /**
159 * BatchResponse provides a convenient interface for handling the results of
1610 * batched API calls. The response contains one success or error per outgoing
17- * request item in the batch. Errors are always of type APIExcpetion.
11+ * request item in the batch. Errors are always of type BytomException.
1812 */
1913 public class BatchResponse<T> {
20- private Response response;
21- private Map<Integer, T> successesByIndex = new LinkedHashMap<>();
22- private Map<Integer, APIException> errorsByIndex = new LinkedHashMap<>();
14+ private Map<Integer, T> successesByIndex = new LinkedHashMap<>();
15+ private Map<Integer, BytomException> errorsByIndex = new LinkedHashMap<>();
2316
24- /**
25- * This constructor is used when deserializing a response from an API call.
26- */
27- public BatchResponse(Response response, Gson serializer, Type tClass, Type eClass)
28- throws BytomException, IOException {
29- this.response = response;
17+ public String toJson() {
18+ return Utils.serializer.toJson(this);
19+ }
3020
31- try {
32- JsonArray root = new JsonParser().parse(response.body().charStream()).getAsJsonArray();
33- for (int i = 0; i < root.size(); i++) {
34- JsonElement elem = root.get(i);
21+ /**
22+ * This constructor is used for synthetically generating a batch response
23+ * object from a map of successes and a map of errors. It ensures that
24+ * the successes and errors are stored in an order-preserving fashion.
25+ */
26+ public BatchResponse(Map<Integer, T> successes, Map<Integer, BytomException> errors) {
27+ List<Integer> successIndexes = new ArrayList<>();
28+ Iterator<Integer> successIter = successes.keySet().iterator();
29+ while (successIter.hasNext()) {
30+ successIndexes.add(successIter.next());
31+ }
32+ Collections.sort(successIndexes);
3533
36- // Test for interleaved errors
37- APIException err = serializer.fromJson(elem, eClass);
38- if (err.code != null) {
39- errorsByIndex.put(i, err);
40- continue;
34+ for (int i : successIndexes) {
35+ successesByIndex.put(i, successes.get(i));
4136 }
4237
43- successesByIndex.put(i, (T) serializer.fromJson(elem, tClass));
44- }
45- } catch (IllegalStateException e) {
46- throw new JSONException(
47- "Unable to read body: " + e.getMessage(), response.headers().get("Chain-Request-ID"));
38+ List<Integer> errorIndexes = new ArrayList<>();
39+ Iterator<Integer> errorIter = errors.keySet().iterator();
40+ while (errorIter.hasNext()) {
41+ errorIndexes.add(errorIter.next());
42+ }
43+ Collections.sort(errorIndexes);
44+ for (int i : errorIndexes) {
45+ errorsByIndex.put(i, errors.get(i));
46+ }
4847 }
49- }
50-
51- /**
52- * This constructor is used for synthetically generating a batch response
53- * object from a map of successes and a map of errors. It ensures that
54- * the successes and errors are stored in an order-preserving fashion.
55- */
56- public BatchResponse(Map<Integer, T> successes, Map<Integer, APIException> errors) {
57- List<Integer> successIndexes = new ArrayList<>();
58- Iterator<Integer> successIter = successes.keySet().iterator();
59- while (successIter.hasNext()) successIndexes.add(successIter.next());
60- Collections.sort(successIndexes);
61- for (int i : successIndexes) successesByIndex.put(i, successes.get(i));
62-
63- List<Integer> errorIndexes = new ArrayList<>();
64- Iterator<Integer> errorIter = errors.keySet().iterator();
65- while (errorIter.hasNext()) errorIndexes.add(errorIter.next());
66- Collections.sort(errorIndexes);
67- for (int i : errorIndexes) errorsByIndex.put(i, errors.get(i));
68- }
69-
70- /**
71- * Returns the internal response object.
72- */
73- public Response response() {
74- return response;
75- }
7648
77- /**
78- * Returns the total number of response objects. This should equal the number
79- * of request objects in the batch.
80- */
81- public int size() {
82- return successesByIndex.size() + errorsByIndex.size();
83- }
49+ /**
50+ * Returns the total number of response objects. This should equal the number
51+ * of request objects in the batch.
52+ */
53+ public int size() {
54+ return successesByIndex.size() + errorsByIndex.size();
55+ }
8456
85- /**
86- * Returns whether the request object at the given index produced a success.
87- * @param index the index of the request object
88- */
89- public boolean isSuccess(int index) {
90- return successesByIndex.containsKey(index);
91- }
57+ /**
58+ * Returns whether the request object at the given index produced a success.
59+ *
60+ * @param index the index of the request object
61+ */
62+ public boolean isSuccess(int index) {
63+ return successesByIndex.containsKey(index);
64+ }
9265
93- /**
94- * Returns whether the request object at the given index produced an error.
95- * @param index the index of the request object
96- */
97- public boolean isError(int index) {
98- return errorsByIndex.containsKey(index);
99- }
66+ /**
67+ * Returns whether the request object at the given index produced an error.
68+ *
69+ * @param index the index of the request object
70+ */
71+ public boolean isError(int index) {
72+ return errorsByIndex.containsKey(index);
73+ }
10074
101- /**
102- * Returns a list of successful response objects in the batch. The order of
103- * the list corresponds to the order of the request objects that produced the
104- * successes.
105- */
106- public List<T> successes() {
107- List<T> res = new ArrayList<>();
108- res.addAll(successesByIndex.values());
109- return res;
110- }
75+ /**
76+ * Returns a list of successful response objects in the batch. The order of
77+ * the list corresponds to the order of the request objects that produced the
78+ * successes.
79+ */
80+ public List<T> successes() {
81+ List<T> res = new ArrayList<>();
82+ res.addAll(successesByIndex.values());
83+ return res;
84+ }
11185
112- /**
113- * Returns a list of error objects in the batch. The order of the list
114- * corresponds to the order of the request objects that produced the
115- * errors.
116- */
117- public List<APIException> errors() {
118- List<APIException> res = new ArrayList<>();
119- res.addAll(errorsByIndex.values());
120- return res;
121- }
86+ /**
87+ * Returns a list of error objects in the batch. The order of the list
88+ * corresponds to the order of the request objects that produced the
89+ * errors.
90+ */
91+ public List<BytomException> errors() {
92+ List<BytomException> res = new ArrayList<>();
93+ res.addAll(errorsByIndex.values());
94+ return res;
95+ }
12296
123- /**
124- * Returns a map of success responses, keyed by the index of the request
125- * object that produced the success. The set of this map's keys is mutually
126- * exclusive of the keys returned by errorsByIndex.
127- */
128- public Map<Integer, T> successesByIndex() {
129- return successesByIndex;
130- }
97+ /**
98+ * Returns a map of success responses, keyed by the index of the request
99+ * object that produced the success. The set of this map's keys is mutually
100+ * exclusive of the keys returned by errorsByIndex.
101+ */
102+ public Map<Integer, T> successesByIndex() {
103+ return successesByIndex;
104+ }
131105
132- /**
133- * Returns a map of error responses, keyed by the index of the request
134- * object that produced the error. The set of this map's keys is mutually
135- * exclusive of the keys returned by successByIndex.
136- */
137- public Map<Integer, APIException> errorsByIndex() {
138- return errorsByIndex;
139- }
106+ /**
107+ * Returns a map of error responses, keyed by the index of the request
108+ * object that produced the error. The set of this map's keys is mutually
109+ * exclusive of the keys returned by successByIndex.
110+ */
111+ public Map<Integer, BytomException> errorsByIndex() {
112+ return errorsByIndex;
113+ }
140114 }
--- a/src/main/java/io/bytom/http/Client.java
+++ b/src/main/java/io/bytom/http/Client.java
@@ -206,69 +206,39 @@ public class Client {
206206 * @param action The requested API action
207207 * @param body Body payload sent to the API as JSON
208208 * @param tClass Type of object to be deserialized from the response JSON
209- * @param eClass Type of error object to be deserialized from the response JSON
210209 * @return the result of the post request
211210 * @throws BytomException
212211 */
213- public <T> BatchResponse<T> batchRequest(
214- String action, Object body, final Type tClass, final Type eClass) throws BytomException {
215- ResponseCreator<BatchResponse<T>> rc =
216- new ResponseCreator<BatchResponse<T>>() {
217- public BatchResponse<T> create(Response response, Gson deserializer)
218- throws BytomException, IOException {
219- return new BatchResponse<T>(response, deserializer, tClass, eClass);
220- }
221- };
222- return post(action, body, rc);
223- }
224-
225- /**
226- * Perform a single HTTP POST request against the API for a specific action.
227- * Use this method if you want single-item semantics (creating single assets,
228- * building single transactions) but the API endpoint is implemented as a
229- * batch call.
230- * <p>
231- * Because request bodies for batch calls do not share a consistent format,
232- * this method does not perform any automatic arrayification of outgoing
233- * parameters. Remember to arrayify your request objects where appropriate.
234- *
235- * @param action The requested API action
236- * @param body Body payload sent to the API as JSON
237- * @param tClass Type of object to be deserialized from the response JSON
238- * @return the result of the post request
239- * @throws BytomException
240- */
241- public <T> T singletonBatchRequest(
242- String action, Object body, final Type tClass, final Type eClass) throws BytomException {
212+ /*
213+ public <T> T requestBatch(String action, Object body, final Type tClass) throws BytomException {
243214 ResponseCreator<T> rc =
244215 new ResponseCreator<T>() {
245- public T create(Response response, Gson deserializer) throws BytomException, IOException {
246- BatchResponse<T> batch = new BatchResponse<>(response, deserializer, tClass, eClass);
247-
248- List<APIException> errors = batch.errors();
249- if (errors.size() == 1) {
250- // This throw must occur within this lambda in order for APIClient's
251- // retry logic to take effect.
252- throw errors.get(0);
253- }
254-
255- List<T> successes = batch.successes();
256- if (successes.size() == 1) {
257- return successes.get(0);
216+ public T create(Response response, Gson deserializer) throws IOException, BytomException {
217+ JsonElement root = new JsonParser().parse(response.body().charStream());
218+ JsonElement status = root.getAsJsonObject().get("status");
219+ JsonElement data = root.getAsJsonObject().get("data");
220+ if (status != null && status.toString().contains("fail")) {
221+ throw new BytomException(root.getAsJsonObject().get("msg").toString());
222+ } else if (data != null) {
223+ return deserializer.fromJson(data, tClass);
224+ } else {
225+ return deserializer.fromJson(response.body().charStream(), tClass);
258226 }
259-
260- // We should never get here, unless there is a bug in either the SDK or
261- // API code, causing a non-singleton response.
262- /*
263- throw new BytomException(
264- "Invalid singleton response, request ID "
265- + batch.response().headers().get("Bytom-Request-ID"));
266- */
267- throw new BytomException("Invalid singleton response.");
268227 }
269228 };
229+ //把object转换为json对象数组(有点难)
230+
231+ //根据数组的大小循环调用post()方法
232+
233+ //重写create()接口方法,对成功和失败做不同的处理
234+
235+ //调用BatchResponse(Map<Integer, T> successes, Map<Integer, APIException> errors)
236+ //构造方法,最后返回BatchResponse实例对象
237+
270238 return post(action, body, rc);
271239 }
240+ */
241+
272242
273243 /**
274244 * Returns true if a client access token stored in the client.
--- a/src/main/java/io/bytom/http/SuccessMessage.java
+++ /dev/null
@@ -1,8 +0,0 @@
1-package io.bytom.http;
2-
3-/**
4- * This class represents RPC success responses whose content is not meaningful.
5- */
6-public class SuccessMessage {
7- public String message;
8-}
--- a/src/test/java/io/bytom/integration/AccountTest.java
+++ b/src/test/java/io/bytom/integration/AccountTest.java
@@ -1,8 +1,10 @@
11 package io.bytom.integration;
22
3+import com.sun.org.apache.xpath.internal.operations.Bool;
34 import io.bytom.TestUtils;
45 import io.bytom.api.Account;
56 import io.bytom.api.Receiver;
7+import io.bytom.http.BatchResponse;
68 import io.bytom.http.Client;
79 import org.junit.Test;
810
@@ -38,6 +40,48 @@ public class AccountTest {
3840 }
3941
4042 @Test
43+ public void testAccountCreateBatch() throws Exception {
44+ client = TestUtils.generateClient();
45+ String xpub = "c7c5306236d4fcc491615c6cb8bbfb80f60582f44c6757252e84d744632fc0235015459db19e42e262530bffc91ebbc6fef949b0eefda657758b3c6c0e7824a4";
46+ List<Account.Builder> builders = new ArrayList<>();
47+ builders.add(new Account.Builder()
48+ .setAlias("batch005")
49+ .setQuorum(1)
50+ .addRootXpub(xpub));
51+ builders.add(new Account.Builder()
52+ .setAlias("batch002")
53+ .setQuorum(1)
54+ .addRootXpub(xpub));
55+ builders.add(new Account.Builder()
56+ .setAlias("batch006")
57+ .setQuorum(1)
58+ .addRootXpub(xpub));
59+ builders.add(new Account.Builder()
60+ .setAlias("batch004")
61+ .setQuorum(1)
62+ .addRootXpub(xpub));
63+ BatchResponse<Account> accountBatchResponse = Account.createBatch(client, builders);
64+ System.out.println(accountBatchResponse.toJson());
65+ }
66+
67+ @Test
68+ public void testAccountDeleteBatch() throws Exception {
69+ client = TestUtils.generateClient();
70+ List<String> accountInfos = new ArrayList<>();
71+ accountInfos.add("batch001");
72+ accountInfos.add("batch002");
73+ accountInfos.add("batch007");
74+ accountInfos.add("batch004");
75+ accountInfos.add("batch005");
76+ accountInfos.add("batch006");
77+ accountInfos.add("batch006");
78+ accountInfos.add("batch003");
79+
80+ BatchResponse<Boolean> booleanBatchResponse = Account.deleteBatch(client, accountInfos);
81+ System.out.println(booleanBatchResponse.toJson());
82+ }
83+
84+ @Test
4185 public void testAccountList() throws Exception {
4286 client = TestUtils.generateClient();
4387 List<Account> accountList = Account.list(client);
@@ -47,7 +91,7 @@ public class AccountTest {
4791 public void testAccountDelete() throws Exception {
4892 client = TestUtils.generateClient();
4993 List<Account> accountList = Account.list(client);
50- String alias = accountList.get(accountList.size()-1).alias;
94+ String alias = accountList.get(accountList.size() - 1).alias;
5195 //delete the last Account Object
5296 Account.delete(client, alias);
5397 }
@@ -56,8 +100,8 @@ public class AccountTest {
56100 public void testReceiverCreate() throws Exception {
57101 client = TestUtils.generateClient();
58102 List<Account> accountList = Account.list(client);
59- String alias = accountList.get(accountList.size()-1).alias;
60- String id = accountList.get(accountList.size()-1).id;
103+ String alias = accountList.get(accountList.size() - 1).alias;
104+ String id = accountList.get(accountList.size() - 1).id;
61105
62106 Account.ReceiverBuilder receiverBuilder = new Account.ReceiverBuilder().setAccountAlias(alias).setAccountId(id);
63107 Receiver receiver = receiverBuilder.create(client);
@@ -70,8 +114,8 @@ public class AccountTest {
70114 public void testAddressList() throws Exception {
71115 client = TestUtils.generateClient();
72116 List<Account> accountList = Account.list(client);
73- String alias = accountList.get(accountList.size()-1).alias;
74- String id = accountList.get(accountList.size()-1).id;
117+ String alias = accountList.get(accountList.size() - 1).alias;
118+ String id = accountList.get(accountList.size() - 1).id;
75119
76120 Account.AddressBuilder addressBuilder = new Account.AddressBuilder().setAccountId(id).setAccountAlias(alias);
77121 List<Account.Address> addressList = addressBuilder.list(client);
@@ -84,8 +128,8 @@ public class AccountTest {
84128 client = TestUtils.generateClient();
85129
86130 List<Account> accountList = Account.list(client);
87- String alias = accountList.get(accountList.size()-1).alias;
88- String id = accountList.get(accountList.size()-1).id;
131+ String alias = accountList.get(accountList.size() - 1).alias;
132+ String id = accountList.get(accountList.size() - 1).id;
89133
90134 Account.AddressBuilder addressBuilder = new Account.AddressBuilder().setAccountId(id).setAccountAlias(alias);
91135 List<Account.Address> addressList = addressBuilder.list(client);
Afficher sur ancien navigateur de dépôt.