public List getListOrThrow(String key) { List list = getList(key, null); if (list == null) throw new IllegalArgumentException("missing list parameter: " + key); return list; }
@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); } } }
@Override public void deserialize(Binder data, BiDeserializer deserializer) { this.unsAddresses = deserializer.deserialize(data.getList("addresses", new ArrayList<>())); Object originObj = data.get("origin"); if (originObj != null) this.unsOrigin = deserializer.deserialize(originObj); }
@Override public Object deserialize(Binder binder, BiDeserializer deserializer) { return new ItemInfo( binder.getOrThrow("item_result"), binder.getOrThrow("item_id"), binder.getList("errors", null) ); } });
protected void initFromParams() { fieldName = params.getStringOrThrow("field_name"); minValue = new Decimal(params.getString("min_value", "0")); minUnit = new Decimal(params.getString("min_unit", "1e-9")); mergeFields = params.getList("join_match_fields", asList("state.origin")); }
@Override public void deserialize(Binder data, BiDeserializer deserializer) { super.deserialize(data, deserializer); this.quorumSize = data.getInt("quorumSize", 0); Object mode = data.getOrDefault("mode", null); if (mode != null) { this.mode = Mode.valueOf((String) mode); } List<Binder> roles = data.getList("roles", null); if (roles != null) { this.roles.clear(); roles.forEach(role -> addRole(deserializer.deserialize(role))); } }
private void deserializeForUns(BiDeserializer deserializer) { storedNames = deserializer.deserialize(getStateData().getList(NAMES_FIELD_NAME, null)); paidU = getStateData().getInt(PAID_U_FIELD_NAME, 0); prepaidNamesForDays = getStateData().getDouble(PREPAID_ND_FIELD_NAME); long prepaidFromSeconds = getStateData().getLong(PREPAID_ND_FROM_TIME_FIELD_NAME, 0); prepaidFrom = ZonedDateTime.ofInstant(Instant.ofEpochSecond(prepaidFromSeconds), ZoneId.systemDefault()); }
this.origin = deserializer.deserialize(data.get("origin")); this.signed_by = deserializer.deserializeCollection(data.getList("signed_by", new ArrayList<>())); List<String> roles = data.getList("roles", null); if (roles != null) { this.roles.clear(); List<String> fields = data.getList("fields", null); if (fields != null) { this.fields.clear();
private boolean isInherited(Binder conditions, Reference ref, Contract refContract, Collection<Contract> contracts, int iteration) { if ((conditions == null) || (conditions.size() == 0)) return false; List<Object> condList = null; if (conditions.containsKey(all_of.name())) { condList = conditions.getList(all_of.name(), null); if (condList == null) throw new IllegalArgumentException("Expected all_of conditions"); } else if (conditions.containsKey(any_of.name())) { condList = conditions.getList(any_of.name(), null); if (condList == null) throw new IllegalArgumentException("Expected any_of conditions"); } else if (conditions.containsKey("operator")) return isInheritedParsed(conditions, ref, refContract, contracts, iteration); else throw new IllegalArgumentException("Expected all_of or any_of"); if (condList != null) for (Object item: condList) if (item.getClass().getName().endsWith("String")) { if (isInherited((String) item, ref, refContract, contracts, iteration)) return true; } else if (isInherited((Binder) item, ref, refContract, contracts, iteration)) return true; return false; }
public void deserializeWith(Binder data, BiDeserializer d) { if(data != null) { id = data.getString("id", null); List refs = data.getList("references", null); if(refs != null) { references = d.deserializeCollection(refs); } try { validUntil = data.getLongOrThrow("valid_until"); } catch (IllegalArgumentException e) { validUntil = null; } this.data = data.getBinder("data", null); } }
String keyName = all ? all_of.name() : any_of.name(); List<Object> parsedList = new ArrayList<>(); List<Object> condList = conds.getList(keyName, null); if (condList == null) throw new IllegalArgumentException("Expected all_of or any_of conditions");
String keyName = all ? all_of.name() : any_of.name(); List<Object> assembledList = new ArrayList<>(); List<Object> condList = conds.getList(keyName, null); if (condList == null) throw new IllegalArgumentException("Expected all_of or any_of conditions");
/** * Construct from serialized parameters, presented in the binder instance * * @param fields binder with named parameters (case sensitive field names, like haveCopy or createdAt) */ public ItemResult(Binder fields) { state = ItemState.valueOf(fields.getStringOrThrow("state")); haveCopy = fields.getBooleanOrThrow("haveCopy"); createdAt = fields.getZonedDateTime("createdAt", null); expiresAt = fields.getZonedDateTime("expiresAt", null); errors = new ArrayList<>(); fields.getList("errors", Collections.EMPTY_LIST).forEach(x -> { errors.add( x instanceof Binder ? new ErrorRecord((Binder)x) : (ErrorRecord) x); }); isTestnet = fields.getBoolean("isTestnet",false); lockedById = (HashId) fields.get("lockedById"); extraDataBinder = fields.getBinder("extra", new Binder()); }
@Override public void deserialize(Binder data, BiDeserializer deserializer) { this.unsReducedName = data.containsKey(NAME_REDUCED_FIELD_NAME) ? data.getString(NAME_REDUCED_FIELD_NAME) : null; this.unsName = data.getString(NAME_FIELD_NAME); this.unsDescription = data.getString(DESCRIPTION_FIELD_NAME); this.unsURL = data.getString(URL_FIELD_NAME); this.unsRecords = deserializer.deserialize(data.getList(ENTRIES_FIELD_NAME, null)); }
public ContractDependencies(byte[] sealed) throws IOException { this.id = HashId.of(sealed); Binder data = Boss.unpack(sealed); byte[] contractBytes = data.getBinaryOrThrow("data"); // This must be explained. By default, Boss.load will apply contract transformation in place // as it is registered BiSerializable type, and we want to avoid it. Therefore, we decode boss // data without BiSerializer and then do it by hand calling deserialize: Binder payload = Boss.load(contractBytes, null); // contract can be extended type - we need know about it before extendedType = payload.getBinder("contract").getBinder("definition").getString("extended_type", null); int apiLevel = data.getIntOrThrow("version"); if (apiLevel < 3) { // no need to build tree - subitems will be reconstructed from binary, not from subItems } else { // new format: only subItems are included for (Binder b : (List<Binder>) payload.getList("revoking", Collections.EMPTY_LIST)) { HashId hid = HashId.withDigest(b.getBinaryOrThrow("composite3")); dependencies.add(hid); } for (Binder b : (List<Binder>) payload.getList("new", Collections.EMPTY_LIST)) { HashId hid = HashId.withDigest(b.getBinaryOrThrow("composite3")); dependencies.add(hid); } } } }
public void deserealizeWith(Binder data, BiDeserializer d) { createdAt = data.getZonedDateTimeOrThrow("created_at"); expiresAt = data.getZonedDateTime("expires_at", null); revision = data.getIntOrThrow("revision"); this.references = d.deserialize(data.getList("references", null)); if (revision <= 0) throw new IllegalArgumentException("illegal revision number: " + revision); Role r = registerRole(d.deserialize(data.getBinderOrThrow("owner"))); if (!r.getName().equals("owner")) throw new IllegalArgumentException("bad owner role name"); r = registerRole(d.deserialize(data.getBinderOrThrow("created_by"))); if (!r.getName().equals("creator")) throw new IllegalArgumentException("bad creator role name"); this.data = data.getBinder("data", Binder.EMPTY); branchId = data.getString("branch_id", null); parent = d.deserialize(data.get("parent")); origin = d.deserialize(data.get("origin")); }
private State initializeWithDsl(Binder state) { this.state = state; createdAt = state.getZonedDateTime("created_at", null); expiresAt = state.getZonedDateTime("expires_at", null); revision = state.getIntOrThrow("revision"); data = state.getOrCreateBinder("data"); if (createdAt == null) { if (revision != 1) throw new IllegalArgumentException("state.created_at must be set for revisions > 1"); createdAt = definition.createdAt; } createRole("owner", state.get("owner")); createRole("creator", state.getOrThrow("created_by")); List<LinkedHashMap<String, Binder>> refList = state.getList("references", null); if (refList != null) { for (LinkedHashMap<String, Binder> refItem : refList) { Binder item = new Binder(refItem); Binder ref = item.getBinder("reference"); if (ref != null) references.add(Reference.fromDslBinder(ref, getContract())); else throw new IllegalArgumentException("Expected reference section"); } } return this; }
private Definition initializeWithDsl(Binder definition) { this.definition = definition; Role issuer = createRole("issuer", definition.getOrThrow("issuer")); createdAt = definition.getZonedDateTimeOrThrow("created_at"); Object t = definition.getOrDefault("expires_at", null); if (t != null) expiresAt = decodeDslTime(t); registerRole(issuer); data = definition.getBinder("data"); extendedType = definition.getString("extended_type", null); List<LinkedHashMap<String, Binder>> refList = definition.getList("references", null); if (refList != null) { for (LinkedHashMap<String, Binder> refItem : refList) { Binder item = new Binder(refItem); Binder ref = item.getBinder("reference"); if (ref != null) references.add(Reference.fromDslBinder(ref, getContract())); else throw new IllegalArgumentException("Expected reference section"); } } return this; }
static public Reference fromDslBinder(Binder ref, Contract contract) { String name = ref.getString("name"); String comment = ref.getString("comment", null); Binder where = null; try { where = ref.getBinderOrThrow("where"); } catch (Exception e) { // Insert simple condition to binder with key all_of List<String> simpleConditions = ref.getList("where", null); if (simpleConditions != null) where = new Binder(all_of.name(), simpleConditions); } Reference reference = new Reference(contract); if (name == null) throw new IllegalArgumentException("Expected reference name"); reference.setName(name); reference.setComment(comment); if (where != null) reference.setConditions(where); return reference; }
public void deserializeWith(Binder data, BiDeserializer d) { registerRole(d.deserialize(data.getBinderOrThrow("issuer"))); createdAt = data.getZonedDateTimeOrThrow("created_at"); expiresAt = data.getZonedDateTime("expires_at", null); extendedType = data.getString("extended_type", null); this.data = d.deserialize(data.getBinder("data", Binder.EMPTY)); references = d.deserialize(data.getList("references", null)); Map<String, Permission> perms = d.deserialize(data.getOrThrow("permissions")); perms.forEach((id, perm) -> { perm.setId(id); addPermission(perm); }); }