Search in sources :

Example 61 with Binder

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;
}
Also used : Binder(net.sergeych.tools.Binder)

Example 62 with Binder

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));
}
Also used : Binder(net.sergeych.tools.Binder) HttpURLConnection(java.net.HttpURLConnection) IOException(java.io.IOException) URL(java.net.URL)

Example 63 with Binder

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"));
    });
}
Also used : Binder(net.sergeych.tools.Binder)

Example 64 with Binder

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();
}
Also used : Binder(net.sergeych.tools.Binder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IOException(java.io.IOException)

Example 65 with 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;
}
Also used : Binder(net.sergeych.tools.Binder)

Aggregations

Binder (net.sergeych.tools.Binder)136 Test (org.junit.Test)67 PrivateKey (com.icodici.crypto.PrivateKey)21 Contract (com.icodici.universa.contract.Contract)14 PublicKey (com.icodici.crypto.PublicKey)13 IOException (java.io.IOException)11 KeyRecord (com.icodici.universa.contract.KeyRecord)10 SimpleRole (com.icodici.universa.contract.roles.SimpleRole)10 Yaml (org.yaml.snakeyaml.Yaml)9 Bytes (net.sergeych.utils.Bytes)8 Decimal (com.icodici.universa.Decimal)7 ListRole (com.icodici.universa.contract.roles.ListRole)6 NonNull (org.checkerframework.checker.nullness.qual.NonNull)5 Gson (com.google.gson.Gson)4 GsonBuilder (com.google.gson.GsonBuilder)4 XStream (com.thoughtworks.xstream.XStream)4 DomDriver (com.thoughtworks.xstream.io.xml.DomDriver)4 List (java.util.List)4 RoleLink (com.icodici.universa.contract.roles.RoleLink)3 ItemResult (com.icodici.universa.node.ItemResult)3