Search in sources :

Example 1 with AnonymousId

use of com.icodici.universa.contract.AnonymousId in project universa by UniversaBlockchain.

the class SimpleRole method initWithRecords.

private void initWithRecords(@NonNull Collection records) {
    records.forEach(x -> {
        KeyRecord kr = null;
        AnonymousId anonId = null;
        if (x instanceof KeyRecord)
            kr = (KeyRecord) x;
        else if (x instanceof PublicKey)
            kr = new KeyRecord((PublicKey) x);
        else if (x instanceof AnonymousId)
            anonId = (AnonymousId) x;
        else if (x instanceof PrivateKey)
            kr = new KeyRecord(((PrivateKey) x).getPublicKey());
        else if (x instanceof KeyAddress)
            keyAddresses.add((KeyAddress) x);
        else
            throw new IllegalArgumentException("Cant create KeyRecord from " + x);
        if (anonId != null)
            anonymousIds.add(anonId);
        else if (kr != null)
            keyRecords.put(kr.getPublicKey(), kr);
    });
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) PrivateKey(com.icodici.crypto.PrivateKey) PublicKey(com.icodici.crypto.PublicKey) KeyAddress(com.icodici.crypto.KeyAddress) AnonymousId(com.icodici.universa.contract.AnonymousId)

Example 2 with AnonymousId

use of com.icodici.universa.contract.AnonymousId in project universa by UniversaBlockchain.

the class SimpleRole method deserialize.

@Override
public void deserialize(Binder data, BiDeserializer deserializer) {
    super.deserialize(data, deserializer);
    // role can have keys - this should actually be refactored to let role
    // hold other roles and so on.
    List keyList = data.getList("keys", null);
    keyRecords.clear();
    if (keyList != null) {
        keyList.forEach(kr -> {
            addKeyRecord(deserializer.deserialize(kr));
        });
    }
    List anonIdList = data.getList("anonIds", null);
    anonymousIds.clear();
    if (anonIdList != null) {
        for (Object aid : anonIdList) {
            AnonymousId anonymousId = deserializer.deserialize(aid);
            anonymousIds.add(anonymousId);
        }
    }
    List keyAddrList = data.getList("addresses", null);
    keyAddresses.clear();
    if (keyAddrList != null) {
        for (Object keyAddr : keyAddrList) {
            KeyAddress ka = deserializer.deserialize(keyAddr);
            keyAddresses.add(ka);
        }
    }
}
Also used : KeyAddress(com.icodici.crypto.KeyAddress) AnonymousId(com.icodici.universa.contract.AnonymousId)

Example 3 with AnonymousId

use of com.icodici.universa.contract.AnonymousId in project universa by UniversaBlockchain.

the class SimpleRole method initWithDsl.

@Override
public void initWithDsl(Binder serializedRole) {
    boolean keysFound = true;
    boolean addressesFound = true;
    boolean anonIdsFound = true;
    if (serializedRole.containsKey("keys")) {
        List<Binder> list = serializedRole.getListOrThrow("keys");
        for (Object keyRecord : list) {
            addKeyRecord(new KeyRecord(Binder.of(keyRecord)));
        }
    } else if (serializedRole.containsKey("key")) {
        addKeyRecord(new KeyRecord(serializedRole));
    } else {
        keysFound = false;
    }
    if (serializedRole.containsKey("addresses")) {
        List<Binder> list = serializedRole.getListOrThrow("addresses");
        for (Object address : list) {
            keyAddresses.add(new KeyAddress(Binder.of(address)));
        }
    } else if (serializedRole.containsKey("uaddress")) {
        keyAddresses.add(new KeyAddress(serializedRole));
    } else {
        addressesFound = false;
    }
    if (serializedRole.containsKey("anonIds")) {
        List<Binder> list = serializedRole.getListOrThrow("anonIds");
        for (Object anonId : list) {
            anonymousIds.add(new AnonymousId(Binder.of(anonId)));
        }
    } else if (serializedRole.containsKey("anonymousId")) {
        anonymousIds.add(new AnonymousId(serializedRole));
    } else {
        anonIdsFound = false;
    }
    if (!addressesFound && !anonIdsFound && !keysFound) {
        // TODO: ?????? "binders" were in old code
        initWithRecords(serializedRole.getListOrThrow("binders"));
    }
}
Also used : KeyRecord(com.icodici.universa.contract.KeyRecord) Binder(net.sergeych.tools.Binder) KeyAddress(com.icodici.crypto.KeyAddress) AnonymousId(com.icodici.universa.contract.AnonymousId)

Aggregations

KeyAddress (com.icodici.crypto.KeyAddress)3 AnonymousId (com.icodici.universa.contract.AnonymousId)3 KeyRecord (com.icodici.universa.contract.KeyRecord)2 PrivateKey (com.icodici.crypto.PrivateKey)1 PublicKey (com.icodici.crypto.PublicKey)1 Binder (net.sergeych.tools.Binder)1