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);
});
}
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);
}
}
}
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"));
}
}
Aggregations