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());
}
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());
}
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;
}
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);
}
}
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);
}
Aggregations