MCPcopy Index your code
hub / github.com/chain/Core / singletonBatchRequest

Method singletonBatchRequest

sdk/java/src/main/java/com/chain/http/Client.java:209–236  ·  view source on GitHub ↗

Perform a single HTTP POST request against the API for a specific action. Use this method if you want single-item semantics (creating single assets, building single transactions) but the API endpoint is implemented as a batch call. Because request bodies for batch calls do not share a consistent fo

(
      String action, Object body, final Type tClass, final Type eClass)

Source from the content-addressed store, hash-verified

207 * @throws ChainException
208 */
209 public <T> T singletonBatchRequest(
210 String action, Object body, final Type tClass, final Type eClass) throws ChainException {
211 ResponseCreator<T> rc =
212 new ResponseCreator<T>() {
213 public T create(Response response, Gson deserializer) throws ChainException, IOException {
214 BatchResponse<T> batch = new BatchResponse<>(response, deserializer, tClass, eClass);
215
216 List<APIException> errors = batch.errors();
217 if (errors.size() == 1) {
218 // This throw must occur within this lambda in order for APIClient's
219 // retry logic to take effect.
220 throw errors.get(0);
221 }
222
223 List<T> successes = batch.successes();
224 if (successes.size() == 1) {
225 return successes.get(0);
226 }
227
228 // We should never get here, unless there is a bug in either the SDK or
229 // API code, causing a non-singleton response.
230 throw new ChainException(
231 "Invalid singleton response, request ID "
232 + batch.response().headers().get("Chain-Request-ID"));
233 }
234 };
235 return post(action, body, rc);
236 }
237
238 /**
239 * Returns the preferred base URL stored in the client.

Callers 10

signMethod · 0.95
createMethod · 0.80
updateMethod · 0.80
submitMethod · 0.80
buildMethod · 0.80
createMethod · 0.80
updateMethod · 0.80
createMethod · 0.80
accountsAPIFunction · 0.80
assetsAPIFunction · 0.80

Calls 1

postMethod · 0.95

Tested by

no test coverage detected