@Override public V get(K key) { return stateStore.get(key); }
private boolean isBranchExist(String branchId) { return state.get(branchId) != null; }
@Override public JsonObject get(String key) { if (tempStore.get(key) != null) { return tempStore.get(key); } else { return stateStore.get(key); } }
private StemContractStateValue getStateValue(String branchId) { JsonObject json = state.get(branchId); if (json == null) { return null; } else { return new StemContractStateValue(json); } }
private BigDecimal getBalance(String key) { JsonObject storeValue = store.get(key); if (storeValue != null && storeValue.has("balance")) { return storeValue.get("balance").getAsBigDecimal(); } else { return BigDecimal.ZERO; } }
/** * Returns a list contains all branch id * * @return list of all branch id * // TODO REMOVE getAllBranchId */ @ContractQuery public Set<String> getallbranchid() { JsonObject branchList = state.get(branchIdListKey); if (branchList == null) { return Collections.emptySet(); } JsonArray branchIds = branchList.getAsJsonArray("branchIds"); Set<String> branchIdSet = new HashSet<>(); for (JsonElement branchId : branchIds) { branchIdSet.add(branchId.getAsString()); } return branchIdSet; }
/** * Function to check the amount of coin that an owner allowed to a spender * params owner The address which owns the funds. * params spender The address which will spend the funds * * @return A BigDecimal specifying the amount of coin still available for the spender */ @ContractQuery @ParamValidation @Override public BigDecimal allowance(JsonObject params) { log.info("\nallowance :: params => " + params); String owner = params.get("owner").getAsString().toLowerCase(); String spender = params.get("spender").getAsString().toLowerCase(); String approveKey = approveKey(owner, spender); if (store.get(owner) != null && store.get(approveKey) != null) { return getBalance(approveKey); } return BigDecimal.ZERO; }
/** * Gets the balance of the specified address * params owner The address to query the balance of * * @return A BigDecimal representing the amount owned by the passed address */ @ContractQuery @ParamValidation @Override public BigDecimal balanceOf(JsonObject params) { log.info("\nbalanceof :: params => " + params); String address = params.get("address").getAsString().toLowerCase(); if (store.get(address) != null) { return getBalance(address); } return BigDecimal.ZERO; }