use of io.nuls.consensus.poc.protocol.tx.StopAgentTransaction in project nuls by nuls-io.
the class PocConsensusResource method createStopMutilAgent.
@POST
@Path("/multiAccount/agent/stopMultiAgent")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "多签账户注销共识节点", notes = "返回注销成功交易hash")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = String.class) })
public RpcClientResult createStopMutilAgent(@ApiParam(name = "form", value = "多签账户注销共识节点表单数据", required = true) CreateStopMultiAgentForm form) throws Exception {
if (NulsContext.MAIN_NET_VERSION <= 1) {
return Result.getFailed(KernelErrorCode.VERSION_TOO_LOW).toRpcClientResult();
}
AssertUtil.canNotEmpty(form);
AssertUtil.canNotEmpty(form.getAddress());
AssertUtil.canNotEmpty(form.getSignAddress());
if (!AddressTool.validAddress(form.getAddress()) || !AddressTool.validAddress(form.getSignAddress())) {
throw new NulsRuntimeException(KernelErrorCode.PARAMETER_ERROR);
}
Account account = accountService.getAccount(form.getSignAddress()).getData();
if (null == account) {
return Result.getFailed(AccountErrorCode.ACCOUNT_NOT_EXIST).toRpcClientResult();
}
if (account.isEncrypted() && account.isLocked()) {
AssertUtil.canNotEmpty(form.getPassword(), "password is wrong");
if (!account.validatePassword(form.getPassword())) {
return Result.getFailed(AccountErrorCode.PASSWORD_IS_WRONG).toRpcClientResult();
}
}
List<Agent> agentList = PocConsensusContext.getChainManager().getMasterChain().getChain().getAgentList();
Agent agent = null;
for (Agent p : agentList) {
if (p.getDelHeight() > 0) {
continue;
}
if (Arrays.equals(p.getAgentAddress(), AddressTool.getAddress(form.getAddress()))) {
agent = p;
break;
}
}
if (agent == null || agent.getDelHeight() > 0) {
return Result.getFailed(PocConsensusErrorCode.AGENT_NOT_EXIST).toRpcClientResult();
}
Result<MultiSigAccount> sigAccountResult = accountService.getMultiSigAccount(form.getAddress());
MultiSigAccount multiSigAccount = sigAccountResult.getData();
// 验证签名账户是否属于多签账户,如果不是多签账户下的地址则提示错误
if (!AddressTool.validSignAddress(multiSigAccount.getPubKeyList(), account.getPubKey())) {
return Result.getFailed(AccountErrorCode.SIGN_ADDRESS_NOT_MATCH).toRpcClientResult();
}
Script redeemScript = accountLedgerService.getRedeemScript(multiSigAccount);
if (redeemScript == null) {
return Result.getFailed(AccountErrorCode.ACCOUNT_NOT_EXIST).toRpcClientResult();
}
// 如果为交易发起人,则需要填写组装交易需要的信息
StopAgentTransaction tx = new StopAgentTransaction();
TransactionSignature transactionSignature = new TransactionSignature();
List<Script> scripts = new ArrayList<>();
StopAgent stopAgent = new StopAgent();
stopAgent.setAddress(agent.getAgentAddress());
stopAgent.setCreateTxHash(agent.getTxHash());
tx.setTime(TimeService.currentTimeMillis());
tx.setTxData(stopAgent);
CoinData coinData = ConsensusTool.getStopAgentCoinData(agent, TimeService.currentTimeMillis() + PocConsensusConstant.STOP_AGENT_LOCK_TIME, null);
tx.setCoinData(coinData);
Na fee = TransactionFeeCalculator.getMaxFee(108 + tx.size());
coinData.getTo().get(0).setNa(coinData.getTo().get(0).getNa().subtract(fee));
tx.setHash(NulsDigestData.calcDigestData(tx.serializeForHash()));
// 将赎回脚本先存储在签名脚本中
scripts.add(redeemScript);
transactionSignature.setScripts(scripts);
// 使用签名账户对交易进行签名
Result resultData = accountLedgerService.txMultiProcess(tx, transactionSignature, account, form.getPassword());
if (resultData.isSuccess()) {
Map<String, String> valueMap = new HashMap<>();
valueMap.put("txData", (String) resultData.getData());
return Result.getSuccess().setData(valueMap).toRpcClientResult();
}
return resultData.toRpcClientResult();
}
use of io.nuls.consensus.poc.protocol.tx.StopAgentTransaction in project nuls by nuls-io.
the class CancelDepositTxProcessor method conflictDetect.
@Override
public ValidateResult conflictDetect(List<Transaction> txList) {
if (txList == null || txList.size() <= 1) {
return ValidateResult.getSuccessResult();
}
Set<NulsDigestData> hashSet = new HashSet<>();
Set<NulsDigestData> agentHashSet = new HashSet<>();
Set<String> addressSet = new HashSet<>();
for (Transaction tx : txList) {
if (tx.getType() == ConsensusConstant.TX_TYPE_RED_PUNISH) {
RedPunishTransaction transaction = (RedPunishTransaction) tx;
addressSet.add(AddressTool.getStringAddressByBytes(transaction.getTxData().getAddress()));
} else if (tx.getType() == ConsensusConstant.TX_TYPE_STOP_AGENT) {
StopAgentTransaction transaction = (StopAgentTransaction) tx;
agentHashSet.add(transaction.getTxData().getCreateTxHash());
}
}
for (Transaction tx : txList) {
if (tx.getType() == ConsensusConstant.TX_TYPE_CANCEL_DEPOSIT) {
CancelDepositTransaction transaction = (CancelDepositTransaction) tx;
if (!hashSet.add(transaction.getTxData().getJoinTxHash())) {
return ValidateResult.getFailedResult(this.getClass().getName(), TransactionErrorCode.TRANSACTION_REPEATED);
}
if (agentHashSet.contains(transaction.getTxData().getJoinTxHash())) {
return ValidateResult.getFailedResult(this.getClass().getName(), PocConsensusErrorCode.AGENT_STOPPED);
}
DepositPo depositPo = depositStorageService.get(transaction.getTxData().getJoinTxHash());
if (depositPo.getDelHeight() > 0) {
return ValidateResult.getFailedResult(this.getClass().getName(), TransactionErrorCode.TRANSACTION_REPEATED);
}
AgentPo agentPo = agentStorageService.get(depositPo.getAgentHash());
if (null == agentPo || agentPo.getDelHeight() > 0) {
return ValidateResult.getFailedResult(this.getClass().getName(), PocConsensusErrorCode.AGENT_NOT_EXIST);
}
if (addressSet.contains(AddressTool.getStringAddressByBytes(agentPo.getAgentAddress()))) {
return ValidateResult.getFailedResult(this.getClass().getName(), PocConsensusErrorCode.AGENT_PUNISHED);
}
}
}
return ValidateResult.getSuccessResult();
}
Aggregations