Search in sources :

Example 26 with Transaction

use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.

the class PocConsensusResource method stopAgent.

@POST
@Path("/agent/stop")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult stopAgent(StopAgentForm form) throws NulsException, IOException {
    AssertUtil.canNotEmpty(form);
    AssertUtil.canNotEmpty(form.getAddress());
    AssertUtil.canNotEmpty(form.getPassword());
    Transaction tx = consensusService.stopConsensus(form.getAddress(), form.getPassword(), null);
    return RpcResult.getSuccess().setData(tx.getHash().getDigestHex());
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction)

Example 27 with Transaction

use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.

the class PocConsensusResource method depositToAgent.

@POST
@Path("/deposit")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("deposit nuls to a bank!")
public RpcResult depositToAgent(DepositForm form) throws NulsException {
    AssertUtil.canNotEmpty(form);
    AssertUtil.canNotEmpty(form.getAddress());
    AssertUtil.canNotEmpty(form.getAgentId());
    AssertUtil.canNotEmpty(form.getDeposit());
    AssertUtil.canNotEmpty(form.getPassword());
    Map<String, Object> paramsMap = new HashMap<>();
    paramsMap.put("deposit", form.getDeposit());
    paramsMap.put("agentHash", form.getAgentId());
    Transaction tx = consensusService.startConsensus(form.getAddress(), form.getPassword(), paramsMap);
    return RpcResult.getSuccess().setData(tx.getHash().getDigestHex());
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) HashMap(java.util.HashMap) ApiOperation(io.swagger.annotations.ApiOperation)

Example 28 with Transaction

use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.

the class TransactionResource method load.

@GET
@Path("/hash/{hash}")
@Produces(MediaType.APPLICATION_JSON)
public RpcResult load(@PathParam("hash") String hash) {
    RpcResult result = null;
    if (StringUtils.isBlank(hash)) {
        return RpcResult.getFailed(ErrorCode.NULL_PARAMETER);
    }
    try {
        Transaction tx = ledgerService.getTx(NulsDigestData.fromDigestHex(hash));
        if (tx == null) {
            result = RpcResult.getFailed("not found");
        } else {
            result = RpcResult.getSuccess();
            result.setData(new TransactionDto(tx));
        }
    } catch (NulsRuntimeException re) {
        Log.error(re);
        result = new RpcResult(false, re.getCode(), re.getMessage());
    } catch (Exception e) {
        Log.error(e);
        result = RpcResult.getFailed(ErrorCode.SYS_UNKOWN_EXCEPTION);
    }
    return result;
}
Also used : TransactionDto(io.nuls.rpc.entity.TransactionDto) Transaction(io.nuls.core.chain.entity.Transaction) RpcResult(io.nuls.rpc.entity.RpcResult) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException)

Example 29 with Transaction

use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.

the class NewTxEventHandler method onEvent.

@Override
public void onEvent(TransactionEvent event, String fromId) {
    Transaction tx = event.getEventBody();
    if (null == tx) {
        return;
    }
    boolean isMine = false;
    try {
        isMine = ledgerService.checkTxIsMine(tx);
    } catch (NulsException e) {
        Log.error(e);
    }
    ValidateResult result = tx.verify();
    if (result.isFailed()) {
        if (result.getErrorCode() == ErrorCode.ORPHAN_TX) {
            orphanTxCacheManager.putTx(tx);
            eventBroadcaster.broadcastHashAndCacheAysn(event, false, fromId);
            return;
        }
        if (result.getLevel() == SeverityLevelEnum.NORMAL_FOUL) {
            Log.info("-----------------------------------------------newTxHandler remove node:" + fromId);
            networkService.removeNode(fromId);
        } else if (result.getLevel() == SeverityLevelEnum.FLAGRANT_FOUL) {
            networkService.blackNode(fromId, NodePo.BLACK);
        }
        return;
    }
    try {
        if (isMine) {
            ledgerService.approvalTx(tx);
        }
        cacheManager.putTx(tx);
        eventBroadcaster.broadcastHashAndCacheAysn(event, false, fromId);
    } catch (Exception e) {
        Log.error(e);
    }
}
Also used : Transaction(io.nuls.core.chain.entity.Transaction) NulsException(io.nuls.core.exception.NulsException) ValidateResult(io.nuls.core.validate.ValidateResult) NulsException(io.nuls.core.exception.NulsException)

Example 30 with Transaction

use of io.nuls.core.chain.entity.Transaction in project nuls by nuls-io.

the class GetTxGroupHandler method onEvent.

@Override
public void onEvent(GetTxGroupRequest event, String fromId) {
    GetTxGroupParam eventBody = event.getEventBody();
    Block block = blockService.getBlock(eventBody.getBlockHash().getDigestHex());
    if (null == block) {
        return;
    }
    TxGroupEvent txGroupEvent = new TxGroupEvent();
    TxGroup txGroup = new TxGroup();
    txGroup.setBlockHash(block.getHeader().getHash());
    List<Transaction> txList = getTxList(block, eventBody.getTxHashList());
    txGroup.setTxList(txList);
    txGroupEvent.setEventBody(txGroup);
    eventBroadcaster.sendToNode(txGroupEvent, fromId);
}
Also used : TxGroup(io.nuls.consensus.entity.TxGroup) Transaction(io.nuls.core.chain.entity.Transaction) GetTxGroupParam(io.nuls.consensus.entity.GetTxGroupParam) Block(io.nuls.core.chain.entity.Block) TxGroupEvent(io.nuls.consensus.event.TxGroupEvent)

Aggregations

Transaction (io.nuls.core.chain.entity.Transaction)34 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)13 NulsException (io.nuls.core.exception.NulsException)12 Block (io.nuls.core.chain.entity.Block)8 HashMap (java.util.HashMap)7 NulsDigestData (io.nuls.core.chain.entity.NulsDigestData)6 ValidateResult (io.nuls.core.validate.ValidateResult)6 BlockHeader (io.nuls.core.chain.entity.BlockHeader)5 IOException (java.io.IOException)5 Deposit (io.nuls.consensus.entity.member.Deposit)4 PocExitConsensusTransaction (io.nuls.consensus.entity.tx.PocExitConsensusTransaction)4 PocJoinConsensusTransaction (io.nuls.consensus.entity.tx.PocJoinConsensusTransaction)4 RegisterAgentTransaction (io.nuls.consensus.entity.tx.RegisterAgentTransaction)4 ArrayList (java.util.ArrayList)4 RedPunishTransaction (io.nuls.consensus.entity.tx.RedPunishTransaction)3 YellowPunishTransaction (io.nuls.consensus.entity.tx.YellowPunishTransaction)3 NulsByteBuffer (io.nuls.core.utils.io.NulsByteBuffer)3 AbstractCoinTransaction (io.nuls.ledger.entity.tx.AbstractCoinTransaction)3 CoinBaseTransaction (io.nuls.ledger.entity.tx.CoinBaseTransaction)3 Account (io.nuls.account.entity.Account)2