@Override public String toString() { if (data.containsKey("errors")) { return "" + code + " error: " + data.getListOrThrow("errors"); } return "" + code + ": " + data; }
@Override public <T, U extends T> T get(String keyName, U defaultValue) { if(kvStore.containsKey(keyName)) return (T) kvStore.get(keyName); return defaultValue; }
private Answer requestOrThrow(String connect, Object... params) throws IOException { // System.out.println("---> "+connect+": "+asList(params)); Answer answer = request(connect, params); if (answer.code >= 400 || answer.data.containsKey("errors")) throw new EndpointException(answer); // System.out.println("<--- "+answer); return answer; }
@Override public Object deserialize(Binder binder, BiDeserializer deserializer) { if(binder.containsKey("base58")) { return (Safe58.decode(binder.getStringOrThrow("base64"),true)); } if(binder.containsKey("safe58")) { return (Safe58.decode(binder.getStringOrThrow("base64"))); } return Base64.decodeLines(binder.getStringOrThrow("base64")); }
private boolean isOriginCondition(Object condition, HashId origin) { if (condition instanceof String) return condition.equals(REFERENCE_CONDITION_PREFIX + origin.toBase64String()); else if (((Binder) condition).containsKey("operator")) { int operator = ((Binder) condition).getIntOrThrow("operator"); if (operator == REFERENCE_CONDITION_OPERATOR) { String leftOperand = ((Binder) condition).getString("leftOperand", null); if ((leftOperand != null) && leftOperand.equals(REFERENCE_CONDITION_LEFT)) { String rightOperand = ((Binder) condition).getString("rightOperand", null); if ((rightOperand != null) && rightOperand.equals(origin.toBase64String())) return true; } } } return false; }
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; }
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 null; boolean all = conds.containsKey(all_of.name()); boolean any = conds.containsKey(any_of.name()); Binder insideBinder = new Binder(insideHashMap); parsed = assemblyConditions(insideBinder); } else if (((Binder) item).containsKey("operator")) cond = assemblyCondition((Binder) item); else
return null; if (conds.containsKey("operator")) return conds; boolean all = conds.containsKey(all_of.name()); boolean any = conds.containsKey(any_of.name());
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 { if (serializedRole.containsKey("addresses")) { List<Binder> list = serializedRole.getListOrThrow("addresses"); for (Object address : list) { keyAddresses.add(new KeyAddress((String) ((Map)address).get("uaddress"))); } else if (serializedRole.containsKey("uaddress")) { keyAddresses.add(new KeyAddress(serializedRole.getString("uaddress"))); } else { 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 {
return true; if (conditions.containsKey(all_of.name())) else if (conditions.containsKey(any_of.name())) else if (conditions.containsKey("operator")) // pre-parsed version result = checkCondition(conditions, ref, contracts, iteration); else
if (((String) condition).startsWith(REFERENCE_CONDITION_PREFIX)) o = HashId.withDigest(((String) condition).substring(REFERENCE_CONDITION_PREFIX.length())); } else if (((Binder) condition).containsKey("operator")) { int operator = ((Binder) condition).getIntOrThrow("operator");
@Override public Object deserialize(Binder binder, BiDeserializer deserializer) { if(binder.containsKey("base58")) { return new Bytes(Safe58.decode(binder.getStringOrThrow("base58"),true)); } if(binder.containsKey("safe58")) { return new Bytes(Safe58.decode(binder.getStringOrThrow("safe58"))); } return new Bytes(Base64.decodeLines(binder.getStringOrThrow("base64"))); }
/** * Get the body of active contract with the given origin (if one active contract is returned), * or list of IDs active contracts (if there are more than one). * List of IDs contracts contains contract hash digests as byte arrays. * @param origin contract origin * @param limit of list items * @return {@link Binder} containing packed transaction or limited list of IDs active contracts or null (if no active contracts found) * @throws ClientError */ public Binder getContract(HashId origin, int limit) throws ClientError { return protect(() -> { Binder result = httpClient.command("getContract", "origin", origin, "limit", limit); if (result.size() > 0) { if (result.containsKey("contractIds")) { List<byte[]> contractIds = new ArrayList<>(); for (Object id: result.getListOrThrow(("contractIds"))) contractIds.add(((Bytes)id).getData()); result.put("contractIds", contractIds); } return result; } else return null; }); }
/** * Get the body of active contract with the given origin (if one active contract is returned), * or list of IDs active contracts (if there are more than one). * List of IDs contracts contains contract hash digests as byte arrays. * @param origin contract origin * @return {@link Binder} containing packed transaction or limited list of IDs active contracts or null (if no active contracts found) * @throws ClientError */ public Binder getContract(HashId origin) throws ClientError { return protect(() -> { Binder result = httpClient.command("getContract", "origin", origin); if (result.size() > 0) { if (result.containsKey("contractIds")) { List<byte[]> contractIds = new ArrayList<>(); for (Object id: result.getListOrThrow(("contractIds"))) contractIds.add(((Bytes)id).getData()); result.put("contractIds", contractIds); } return result; } else return null; }); }
@Override public void deserialize(Binder data, BiDeserializer deserializer) { name = data.getStringOrThrow("name"); comment = data.getString("comment", null); contract = deserializer.getContext(); Binder required = data.getBinder("required"); if(required != null) { if(required.containsKey(ALL_OF.name())) { requiredAllReferences.addAll(deserializer.deserialize(required.getArray(ALL_OF.name()))); } if(required.containsKey(ANY_OF.name())) { requiredAnyReferences.addAll(deserializer.deserialize(required.getArray(ANY_OF.name()))); } } }
@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 Binder serializeWith(BiSerializer serializer) { List<Permission> pp = permissions.values(); Binder pb = new Binder(); int lastId = 0; // serialize permissions with a valid id permissions.values().forEach(perm -> { String pid = perm.getId(); if (pid == null) throw new IllegalStateException("permission without id: " + perm); if (pb.containsKey(pid)) throw new IllegalStateException("permission: duplicate permission id found: " + perm); pb.put(pid, perm); }); Collections.sort(pp); Binder of = Binder.of( "issuer", getIssuer(), "created_at", createdAt, "data", data, "permissions", pb ); if (expiresAt != null) of.set("expires_at", expiresAt); if (references != null) of.set("references", references); if (extendedType != null) of.set("extended_type", extendedType); return serializer.serialize(of); }
@Override public Binder serialize(Object object, BiSerializer serializer) { Object s = serializer.serialize(((KeyAddress) object).getPacked());; Binder serialized = (Binder) s; if(serialized.containsKey("base64")) { serialized.put("base58", Safe58.encode(Base64.decodeLines((String) serialized.remove("base64")))); } return Binder.of("uaddress", serialized); }
@SuppressWarnings("deprecation") //outdated method. will be replaced with new one soon private boolean checkIfContractContainsNetConfig(Contract contract) { if(!contract.getStateData().containsKey("net_config")) { return false;