use of io.nuls.ledger.entity.Balance in project nuls by nuls-io.
the class PocConsensusServiceImpl method getConsensusInfo.
@Override
public Map<String, Object> getConsensusInfo(String address) {
if (StringUtils.isNotBlank(address)) {
return getConsensusInfoByAddress(address);
}
List<Account> accountList = this.accountService.getAccountList();
if (accountList == null || accountList.isEmpty()) {
return null;
}
long lastDayTime = TimeService.currentTimeMillis() - DateUtil.DATE_TIME;
int agentCount = 0;
long totalDeposit = 0;
long reward = 0;
long rewardOfDay = 0;
long usableBalance = 0;
Set<String> joinedAgent = new HashSet<>();
for (Account account : accountList) {
Consensus<Agent> agent = this.consensusCacheManager.getCachedAgentByAddress(account.getAddress().toString());
List<Consensus<Deposit>> depositList = this.consensusCacheManager.getCachedDepositListByAddress(account.getAddress().toString());
for (Consensus<Deposit> cd : depositList) {
totalDeposit += cd.getExtend().getDeposit().getValue();
joinedAgent.add(cd.getExtend().getAgentHash());
}
if (null != agent) {
agentCount++;
totalDeposit += agent.getExtend().getDeposit().getValue();
}
reward += ledgerService.getAccountReward(account.getAddress().getBase58(), 0);
rewardOfDay += ledgerService.getAccountReward(account.getAddress().getBase58(), lastDayTime);
Balance balance = ledgerService.getBalance(account.getAddress().getBase58());
if (balance != null) {
usableBalance += balance.getUsable().getValue();
}
}
Map<String, Object> map = new HashMap<>();
map.put("agentCount", agentCount);
map.put("totalDeposit", totalDeposit);
map.put("joinAccountCount", joinedAgent.size());
map.put("usableBalance", usableBalance);
map.put("reward", reward);
map.put("rewardOfDay", rewardOfDay);
return map;
}
use of io.nuls.ledger.entity.Balance in project nuls by nuls-io.
the class PocConsensusServiceImpl method getConsensusInfoByAddress.
private Map<String, Object> getConsensusInfoByAddress(String address) {
if (!Address.validAddress(address)) {
return null;
}
Consensus<Agent> agent = this.consensusCacheManager.getCachedAgentByAddress(address);
List<Consensus<Deposit>> depositList = this.consensusCacheManager.getCachedDepositListByAddress(address);
long totalDeposit = 0;
Set<String> joinedAgent = new HashSet<>();
for (Consensus<Deposit> cd : depositList) {
totalDeposit += cd.getExtend().getDeposit().getValue();
joinedAgent.add(cd.getExtend().getAgentHash());
}
Map<String, Object> map = new HashMap<>();
if (null != agent) {
map.put("agentCount", 1);
// totalDeposit += agent.getExtend().getDeposit().getValue();
} else {
map.put("agentCount", 0);
}
map.put("totalDeposit", totalDeposit);
long lastDayTime = TimeService.currentTimeMillis() - DateUtil.DATE_TIME;
long reward = ledgerService.getAccountReward(address, 0);
long rewardOfDay = ledgerService.getAccountReward(address, lastDayTime);
Balance balance = ledgerService.getBalance(address);
map.put("reward", reward);
map.put("joinAccountCount", joinedAgent.size());
if (null == balance || balance.getUsable() == null) {
map.put("usableBalance", 0);
} else {
map.put("usableBalance", balance.getUsable().getValue());
}
map.put("rewardOfDay", rewardOfDay);
return map;
}
use of io.nuls.ledger.entity.Balance in project nuls by nuls-io.
the class AccountResource method getBalance.
@GET
@Path("/balance/{address}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBalance(@PathParam("address") String address) {
if (!Address.validAddress(address)) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
Balance balance = ledgerService.getBalance(address);
RpcResult result = RpcResult.getSuccess();
result.setData(new BalanceDto(balance));
return result;
}
use of io.nuls.ledger.entity.Balance in project nuls by nuls-io.
the class AccountResource method getAssets.
@GET
@Path("/assets/{address}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getAssets(@PathParam("address") String address) {
if (!Address.validAddress(address)) {
return RpcResult.getFailed(ErrorCode.PARAMETER_ERROR);
}
Balance balance = ledgerService.getBalance(address);
RpcResult result = RpcResult.getSuccess();
List<AssetDto> dtoList = new ArrayList<>();
dtoList.add(new AssetDto("Nuls", balance));
result.setData(dtoList);
return result;
}
use of io.nuls.ledger.entity.Balance in project nuls by nuls-io.
the class AccountResource method getBalance.
@GET
@Path("/balances")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult getBalance() {
Balance balance = ledgerService.getBalance(null);
RpcResult result = RpcResult.getSuccess();
result.setData(new BalanceDto(balance));
return result;
}
Aggregations