Search in sources :

Example 1 with Balance

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;
}
Also used : Account(io.nuls.account.entity.Account) Agent(io.nuls.consensus.entity.member.Agent) Deposit(io.nuls.consensus.entity.member.Deposit) Consensus(io.nuls.consensus.entity.Consensus) Balance(io.nuls.ledger.entity.Balance)

Example 2 with Balance

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;
}
Also used : Agent(io.nuls.consensus.entity.member.Agent) Deposit(io.nuls.consensus.entity.member.Deposit) Consensus(io.nuls.consensus.entity.Consensus) Balance(io.nuls.ledger.entity.Balance)

Example 3 with Balance

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;
}
Also used : Balance(io.nuls.ledger.entity.Balance) UtxoBalance(io.nuls.ledger.entity.UtxoBalance)

Example 4 with Balance

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;
}
Also used : ArrayList(java.util.ArrayList) Balance(io.nuls.ledger.entity.Balance) UtxoBalance(io.nuls.ledger.entity.UtxoBalance)

Example 5 with Balance

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;
}
Also used : Balance(io.nuls.ledger.entity.Balance) UtxoBalance(io.nuls.ledger.entity.UtxoBalance)

Aggregations

Balance (io.nuls.ledger.entity.Balance)6 UtxoBalance (io.nuls.ledger.entity.UtxoBalance)3 Consensus (io.nuls.consensus.entity.Consensus)2 Agent (io.nuls.consensus.entity.member.Agent)2 Deposit (io.nuls.consensus.entity.member.Deposit)2 Account (io.nuls.account.entity.Account)1 ArrayList (java.util.ArrayList)1