use of io.nuls.core.validate.ValidateResult in project nuls by nuls-io.
the class HeaderFieldValidator method validate.
@Override
public ValidateResult validate(BlockHeader data) {
ValidateResult result = ValidateResult.getSuccessResult();
boolean failed = false;
do {
if (data.getHash() == null) {
failed = true;
break;
}
if (data.getHeight() < 0) {
failed = true;
break;
}
if (data.getMerkleHash() == null) {
failed = true;
break;
}
if (StringUtils.isBlank(data.getPackingAddress())) {
failed = true;
break;
}
} while (false);
if (failed) {
result = ValidateResult.getFailedResult(ERROR_MESSAGE);
}
return result;
}
use of io.nuls.core.validate.ValidateResult in project nuls by nuls-io.
the class AgentCountValidator method validate.
@Override
public ValidateResult validate(RegisterAgentTransaction tx) {
ValidateResult result = ValidateResult.getSuccessResult();
Agent agent = tx.getTxData().getExtend();
String agentName = agent.getAgentName();
List<Consensus<Agent>> caList = consensusCacheManager.getCachedAgentList();
if (caList != null) {
for (Consensus<Agent> ca : caList) {
if (ca.getHexHash().equals(tx.getTxData().getHexHash())) {
continue;
}
if (ca.getAddress().equals(tx.getTxData().getAddress())) {
return ValidateResult.getFailedResult("An address can only create one agent");
}
if (ca.getAddress().equals(agent.getPackingAddress())) {
return ValidateResult.getFailedResult("The address can only create one agent");
}
if (agent.getPackingAddress().equals(ca.getAddress())) {
return ValidateResult.getFailedResult("The packingAddress is an agentAddress");
}
if (agent.getPackingAddress().equals(ca.getExtend().getPackingAddress())) {
return ValidateResult.getFailedResult("The packingAddress is busy!");
}
if (agentName.equals(ca.getExtend().getAgentName())) {
return ValidateResult.getFailedResult("AgentName repetition!");
}
}
}
return result;
}
use of io.nuls.core.validate.ValidateResult in project nuls by nuls-io.
the class UtxoLedgerServiceImpl method transfer.
private Result transfer(CoinTransferData coinData, String password, String remark) {
TransferTransaction tx = null;
try {
tx = UtxoTransactionTool.getInstance().createTransferTx(coinData, password, remark);
ValidateResult result = tx.verify();
if (result.isFailed()) {
throw new NulsException(result.getErrorCode());
}
byte[] txbytes = tx.serialize();
TransferTransaction new_tx = new NulsByteBuffer(txbytes).readNulsData(new TransferTransaction());
result = new_tx.verify();
if (result.isFailed()) {
throw new NulsException(result.getErrorCode());
}
TransactionEvent event = new TransactionEvent();
event.setEventBody(tx);
eventBroadcaster.broadcastAndCacheAysn(event, true);
} catch (Exception e) {
Log.error(e);
return new Result(false, e.getMessage());
}
return new Result(true, "OK", tx.getHash().getDigestHex());
}
Aggregations