use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class BasicHttpServer method onPing.
private Binder onPing(Binder params) {
Binder result = Binder.fromKeysValues("ping", "pong");
result.putAll(params);
return result;
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class Client method loadNetworkFrom.
private void loadNetworkFrom(String someNodeUrl) throws IOException {
URL url = new URL(someNodeUrl + "/network");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("User-Agent", "Universa JAVA API Client");
connection.setRequestMethod("GET");
if (connection.getResponseCode() != 200)
throw new IOException("failed to access " + url + ", reponseCode " + connection.getResponseCode());
Binder bres = Boss.unpack((Do.read(connection.getInputStream()))).getBinderOrThrow("response");
nodes.clear();
this.version = bres.getStringOrThrow("version");
for (Binder b : bres.getBinders("nodes")) nodes.add(new NodeRecord(b));
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class Client method getParcelProcessingState.
public Node.ParcelProcessingState getParcelProcessingState(HashId parcelId) throws ClientError {
return protect(() -> {
Binder result = httpClient.command("getParcelProcessingState", "parcelId", parcelId);
Object ps = result.getOrThrow("processingState");
if (ps instanceof Node.ParcelProcessingState)
return (Node.ParcelProcessingState) ps;
return Node.ParcelProcessingState.valueOf(result.getBinder("processingState").getStringOrThrow("state"));
});
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class ClientHTTPServer method startApproval.
private Binder startApproval(final Binder params, Session session) throws IOException, Quantiser.QuantiserException {
if (config == null || !config.getKeysWhiteList().contains(session.getPublicKey())) {
System.out.println("startApproval ERROR: session key shoild be in the white list");
return Binder.of("itemResult", itemResultOfError(Errors.BAD_CLIENT_KEY, "startApproval", "command needs client key from whitelist"));
}
int n = asyncStarts.incrementAndGet();
AtomicInteger k = new AtomicInteger();
params.getListOrThrow("packedItems").forEach((item) -> es.execute(() -> {
try {
checkNode(session);
System.out.println("Request to start registration #" + n + ":" + k.incrementAndGet());
node.registerItem(Contract.fromPackedTransaction(((Bytes) item).toArray()));
} catch (Exception e) {
e.printStackTrace();
}
}));
// TODO: return ItemResult
return new Binder();
}
use of net.sergeych.tools.Binder in project universa by UniversaBlockchain.
the class Role method fromDslBinder.
public static Role fromDslBinder(String name, Binder serializedRole) {
if (name == null)
name = serializedRole.getStringOrThrow("name");
Role result;
String type = serializedRole.getString("type", null);
if (type == null || type.equalsIgnoreCase("simple")) {
result = new SimpleRole(name);
} else if (type.equalsIgnoreCase("link")) {
result = new RoleLink(name);
} else if (type.equalsIgnoreCase("list")) {
result = new ListRole(name);
} else {
throw new IllegalArgumentException("Unknown role type: " + type);
}
result.initWithDsl(serializedRole);
if (serializedRole.containsKey("requires")) {
Binder requires = serializedRole.getBinderOrThrow("requires");
if (requires.containsKey("all_of")) {
result.requiredAllReferences.addAll(requires.getListOrThrow("all_of"));
}
if (requires.containsKey("any_of")) {
result.requiredAnyReferences.addAll(requires.getListOrThrow("any_of"));
}
}
return result;
}
Aggregations