/** * Get extended statistics of the node including by-day payments in "U". Accessible to node owners (with node {@link PrivateKey} as session key) and network admins * @return dictionary containing uptime, ledger size, and number of contracts approved for a minute, hour and since restart. it also contains by-day payments information * @param showPaymentsDays the number of days to provide payments volume for * @throws ClientError */ public Binder getStats(Integer showPaymentsDays) throws ClientError { return protect(() -> httpClient.command("getStats","showDays",showPaymentsDays)); }
/** * Look for the name assosiated with a given address * @param address to look for * @return {@link Binder} containing name, description and url associated with address or null * @throws ClientError */ public Binder queryNameRecord(String address) throws ClientError { return protect(() -> { Binder result = httpClient.command("queryNameRecord", "address", address); return result; }); }
/** * Get current network rate for operating FOLLOWER1 contracts * @return {@link Binder} containing origins-days per U rate and callback price in U * @throws ClientError */ public Binder followerGetRate() throws ClientError { return protect(() -> { Binder result = httpClient.command("followerGetRate"); return result; }); }
public ItemResult getExtendedState(HashId itemId, int nodeNumber) throws ClientError { return protect(() -> { // for (int i = 0; i < nodes.size(); i++) { // System.out.println("checking node " + i); // ItemResult r = getClient(i).command("getState", // "itemId", itemId).getOrThrow("itemResult"); // System.out.println(">> " + r); // } return (ItemResult) httpClient.command("getState", "itemId", itemId).getOrThrow("itemResult"); }); }
/** * Look for the name assosiated with a given origin * @param origin to look for * @return {@link Binder} containing name, description and url associated with origin or null * @throws ClientError */ public Binder queryNameRecord(HashId origin) throws ClientError { return protect(() -> { Binder result = httpClient.command("queryNameRecord", "origin", origin.getDigest()); return result; }); }
/** * Force synchronization with the rest of the network of given item by its id. May require special client key / network configuration * @param itemId to synchronize * @return known {@link ItemState} before synchronization. Query the state later to get it synchronized * @throws ClientError */ public ItemResult resyncItem(HashId itemId) throws ClientError { return protect(() -> { Binder result = httpClient.command("resyncItem", "itemId", itemId); Object ir = result.getOrThrow("itemResult"); if (ir instanceof ItemResult) return (ItemResult) ir; if (ir instanceof String) System.out.println(">> " + ir); return ItemResult.UNDEFINED; }); }
/** * Look for known state of item by given id * @param itemId to find state of * @return known {@link ItemState} if exist or ItemState.UNDEFINED * @throws ClientError */ public ItemResult getState(HashId itemId) throws ClientError { return protect(() -> { // for (int i = 0; i < nodes.size(); i++) { // System.out.println("checking node " + i); // ItemResult r = getClient(i).command("getState", // "itemId", itemId).getOrThrow("itemResult"); // System.out.println(">> " + r); // } Binder result = httpClient.command("getState", "itemId", itemId); Object ir = result.getOrThrow("itemResult"); if (ir instanceof ItemResult) return (ItemResult) ir; if (ir instanceof String) System.out.println(">> " + ir); return ItemResult.UNDEFINED; }); }
/** * Get current network rate for operating SLOT1 contracts * @return kilobyte-days per U rate * @throws ClientError */ public Decimal storageGetRate() throws ClientError { return protect(() -> { Binder result = httpClient.command("storageGetRate"); String U = result.getStringOrThrow("U"); return new Decimal(U); }); }
/** * Get current network rate for operating UNS1 contracts * @return name-days per U rate * @throws ClientError */ public Decimal unsRate() throws ClientError { return protect(() -> { Binder result = httpClient.command("unsRate"); String U = result.getStringOrThrow("U"); return new Decimal(U); }); }
/** * Look for state data of slot contract * @param slotId slot contract id * @return {@link Binder} containing state data of slot contract * @throws ClientError */ public Binder querySlotInfo(HashId slotId) throws ClientError { return protect(() -> { Binder result = httpClient.command("querySlotInfo", "slot_id", slotId.getDigest()); Binder binder = result.getBinder("slot_state", null); return binder; }); }
/** * Look for state data of follower contract * @param followerId follower contract id * @return {@link Binder} containing state data of follower contract * @throws ClientError */ public Binder queryFollowerInfo(HashId followerId) throws ClientError { return protect(() -> { Binder result = httpClient.command("queryFollowerInfo", "follower_id", followerId.getDigest()); Binder binder = result.getBinder("follower_state", null); return binder; }); } }
/** * Get the contract with the given contract id. * @param itemId contract hash * @return contract with the given contract id * @throws ClientError */ public byte[] getBody(HashId itemId) throws ClientError { return protect(() -> { Binder result = httpClient.command("getBody", "itemId", itemId); try { Bytes bytes = result.getBytesOrThrow("packedContract"); return bytes.getData(); } catch (IllegalArgumentException e) { return null; } }); }
/** * Look for {@link com.icodici.universa.contract.services.UnsContract} that registers the name given * @param name to look for * @return packed {@link com.icodici.universa.contract.services.UnsContract} if found. Otherwise null * @throws ClientError */ public byte[] queryNameContract(String name) throws ClientError { return protect(() -> { Binder result = httpClient.command("queryNameContract", "name", name); try { Bytes bytes = result.getBytesOrThrow("packedContract"); return bytes.getData(); } catch (IllegalArgumentException e) { return null; } }); }
public ItemResult setVerboseLevel(int node, int network, int udp) throws ClientError { return protect(() -> { Binder result = httpClient.command("setVerbose", "node", DatagramAdapter.VerboseLevel.intToString(node), "network", DatagramAdapter.VerboseLevel.intToString(network), "udp", DatagramAdapter.VerboseLevel.intToString(udp)); Object ir = result.getOrThrow("itemResult"); if (ir instanceof ItemResult) return (ItemResult) ir; if (ir instanceof String) System.out.println(">> " + ir); return ItemResult.UNDEFINED; }); }
Object binderResult = protect(() -> httpClient.command("approve", "packedItem", packed) .get("itemResult")); if(binderResult instanceof ItemResult) {
/** * 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; }); }
/** * 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 processing state of given parcel * @param parcelId id of the parcel to get state of * @return processing state of the parcel * @throws ClientError */ 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")); }); }
Object result = protect(() -> httpClient.command("approveParcel", "packedItem", packed) .get("result")); if(result instanceof String) {
/** * Look for contract stored by given slot contract id. Contract is specified by either id or origin * @param slotId id of slot contract storing queried contract * @param originId queried contract origin * @param contractId queried contract id * @return {@link com.icodici.universa.contract.TransactionPack} of stored contract or null * @throws ClientError */ public byte[] queryContract(HashId slotId, HashId originId, HashId contractId) throws ClientError { return protect(() -> { Binder result = httpClient.command("queryContract", "slot_id", slotId.getDigest(), "origin_id", originId==null?null:originId.getDigest(), "contract_id", contractId==null?null:contractId.getDigest() ); try { Bytes bytes = result.getBytesOrThrow("contract"); return bytes.getData(); } catch (IllegalArgumentException e) { return null; } }); }