Search in sources :

Example 26 with Account

use of io.nuls.account.entity.Account in project nuls by nuls-io.

the class AccountResource method accountList.

@GET
@Path("/list")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult accountList() {
    RpcResult<List<AccountDto>> result = RpcResult.getSuccess();
    List<Account> list = accountService.getAccountList();
    List<AccountDto> dtoList = new ArrayList<>();
    for (Account account : list) {
        dtoList.add(new AccountDto(account));
    }
    result.setData(dtoList);
    return result;
}
Also used : Account(io.nuls.account.entity.Account) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 27 with Account

use of io.nuls.account.entity.Account in project nuls by nuls-io.

the class GenesisBlock method initGengsisTxs.

private void initGengsisTxs(Map<String, Object> jsonMap) {
    List<Map<String, Object>> list = (List<Map<String, Object>>) jsonMap.get(CONFIG_FILED_TXS);
    if (null == list || list.isEmpty()) {
        throw new NulsRuntimeException(ErrorCode.CONFIG_ERROR);
    }
    CoinTransferData data = new CoinTransferData(OperationType.COIN_BASE, Na.ZERO);
    data.setPriKey(Hex.decode(priKey));
    Na total = Na.ZERO;
    for (Map<String, Object> map : list) {
        String address = (String) map.get(CONFIG_FILED_ADDRESS);
        AssertUtil.canNotEmpty(address, ErrorCode.NULL_PARAMETER);
        Integer nuls = (Integer) map.get(CONFIG_FILED_NULS);
        AssertUtil.canNotEmpty(nuls, ErrorCode.NULL_PARAMETER);
        Integer height = (Integer) map.get(CONFIG_FILED_UNLOCK_HEIGHT);
        Coin coin = new Coin();
        coin.setNa(Na.parseNuls(nuls));
        coin.setUnlockTime(0);
        if (height == null) {
            coin.setUnlockTime(0);
        } else {
            coin.setUnlockHeight(height.longValue());
        }
        data.addTo(address, coin);
        total = total.add(coin.getNa());
    }
    data.setTotalNa(total);
    CoinBaseTransaction tx = null;
    try {
        tx = new CoinBaseTransaction(data, null);
    } catch (NulsException e) {
        Log.error(e);
        throw new NulsRuntimeException(e);
    }
    tx.setTime(this.blockTime);
    tx.setFee(Na.ZERO);
    try {
        tx.setHash(NulsDigestData.calcDigestData(tx.serialize()));
    } catch (IOException e) {
        Log.error(e);
        throw new NulsRuntimeException(e);
    }
    P2PKHScriptSig p2PKHScriptSig = new P2PKHScriptSig();
    Account account = null;
    try {
        account = AccountTool.createAccount(priKey);
    } catch (NulsException e) {
        e.printStackTrace();
    }
    AccountService accountService = NulsContext.getServiceBean(AccountService.class);
    P2PKHScriptSig scriptSig = null;
    try {
        scriptSig = accountService.createP2PKHScriptSigFromDigest(tx.getHash(), account, "");
    } catch (NulsException e) {
        e.printStackTrace();
    }
    try {
        tx.setScriptSig(scriptSig.serialize());
    } catch (IOException e) {
        e.printStackTrace();
    }
    List<Transaction> txlist = new ArrayList<>();
    // tx.setStatus(TxStatusEnum.AGREED);
    txlist.add(tx);
    setTxs(txlist);
}
Also used : Account(io.nuls.account.entity.Account) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) IOException(java.io.IOException) BigInteger(java.math.BigInteger) Coin(io.nuls.ledger.entity.params.Coin) P2PKHScriptSig(io.nuls.core.script.P2PKHScriptSig) CoinTransferData(io.nuls.ledger.entity.params.CoinTransferData) CoinBaseTransaction(io.nuls.ledger.entity.tx.CoinBaseTransaction) CoinBaseTransaction(io.nuls.ledger.entity.tx.CoinBaseTransaction) NulsException(io.nuls.core.exception.NulsException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) AccountService(io.nuls.account.service.intf.AccountService)

Example 28 with Account

use of io.nuls.account.entity.Account in project nuls by nuls-io.

the class ConsensusCacheManager method init.

public void init() {
    Account self = accountService.getDefaultAccount();
    List<DepositPo> depositPoList = this.depositDao.getList();
    List<AgentPo> agentPoList = this.agentDao.getList();
    Consensus mine = null;
    for (AgentPo po : agentPoList) {
        Consensus<Agent> ca = ConsensusTool.fromPojo(po);
        this.cacheAgent(ca);
        if (null != self && ca.getAddress().equals(self.getAddress().toString())) {
            mine = ca;
        }
    }
    for (DepositPo dpo : depositPoList) {
        Consensus<Deposit> cd = ConsensusTool.fromPojo(dpo);
        this.cacheDeposit(cd);
        if (null != self && null == mine && cd.getAddress().equals(self.getAddress().toString())) {
            mine = cd;
        }
    }
    if (null == self) {
        return;
    }
    ConsensusStatusInfo info = new ConsensusStatusInfo();
    info.setAccount(self);
    if (null == mine) {
        info.setStatus(ConsensusStatusEnum.NOT_IN.getCode());
    } else if (mine.getExtend() instanceof Agent) {
        info.setSeed(((Agent) mine.getExtend()).getSeed());
        info.setStatus(((Agent) mine.getExtend()).getStatus());
    }
    this.updateConsensusStatusInfo(info);
}
Also used : Account(io.nuls.account.entity.Account) Agent(io.nuls.consensus.entity.member.Agent) Deposit(io.nuls.consensus.entity.member.Deposit) DepositPo(io.nuls.db.entity.DepositPo) Consensus(io.nuls.consensus.entity.Consensus) AgentPo(io.nuls.db.entity.AgentPo) ConsensusStatusInfo(io.nuls.consensus.entity.ConsensusStatusInfo)

Aggregations

Account (io.nuls.account.entity.Account)28 NulsException (io.nuls.core.exception.NulsException)14 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)11 Result (io.nuls.core.chain.entity.Result)9 ValidateResult (io.nuls.core.validate.ValidateResult)9 AccountPo (io.nuls.db.entity.AccountPo)7 IOException (java.io.IOException)7 DbSession (io.nuls.db.transactional.annotation.DbSession)4 AccountService (io.nuls.account.service.intf.AccountService)3 Agent (io.nuls.consensus.entity.member.Agent)3 CoinTransferData (io.nuls.ledger.entity.params.CoinTransferData)3 Address (io.nuls.account.entity.Address)2 Alias (io.nuls.account.entity.Alias)2 AliasTransaction (io.nuls.account.entity.tx.AliasTransaction)2 Consensus (io.nuls.consensus.entity.Consensus)2 Deposit (io.nuls.consensus.entity.member.Deposit)2 Transaction (io.nuls.core.chain.entity.Transaction)2 AliasPo (io.nuls.db.entity.AliasPo)2 Coin (io.nuls.ledger.entity.params.Coin)2 LockNulsTransaction (io.nuls.ledger.entity.tx.LockNulsTransaction)2