Search in sources :

Example 1 with NullReturnRpcException

use of org.aion.api.server.rpc2.autogen.errors.NullReturnRpcException in project aion by aionnetwork.

the class RpcImpl method submitsignature.

@Override
public boolean submitsignature(byte[] signature, byte[] sealhash) throws NullReturnRpcException {
    if (!ac.getAionHub().getBlockchain().isUnityForkEnabledAtNextBlock()) {
        throw new NullReturnRpcException("unity fork is not enabled");
    }
    if (signature == null) {
        throw new NullReturnRpcException("the giving signature is null");
    }
    if (sealhash == null) {
        throw new NullReturnRpcException("the giving sealhash is null");
    }
    if (signature.length != StakingBlockHeader.SIG_LENGTH) {
        throw new NullReturnRpcException("the giving signature length is incorrect");
    }
    if (sealhash.length != StakingBlockHeader.HASH_BYTE_SIZE) {
        throw new NullReturnRpcException("the giving sealhash length is incorrect");
    }
    StakingBlock block = (StakingBlock) ac.getBlockchain().getCachingStakingBlockTemplate(sealhash);
    if (block == null) {
        return false;
    }
    // Cannot submit a future block to the kernel
    if (block.getTimestamp() > TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()) + 1) {
        return false;
    }
    block.seal(signature, block.getHeader().getSigningPublicKey());
    ImportResult result = ac.addNewBlock(block);
    boolean sealed = (result == ImportResult.IMPORTED_BEST || result == ImportResult.IMPORTED_NOT_BEST);
    if (sealed) {
        AionLoggerFactory.getLogger(LogEnum.CONS.toString()).info("Staking block sealed <num={}, hash={}, diff={}, tx={}>", block.getNumber(), block.getShortHash(), block.getDifficultyBI(), block.getTransactionsList().size());
    }
    return sealed;
}
Also used : ImportResult(org.aion.zero.impl.core.ImportResult) NullReturnRpcException(org.aion.api.server.rpc2.autogen.errors.NullReturnRpcException) StakingBlock(org.aion.zero.impl.types.StakingBlock)

Aggregations

NullReturnRpcException (org.aion.api.server.rpc2.autogen.errors.NullReturnRpcException)1 ImportResult (org.aion.zero.impl.core.ImportResult)1 StakingBlock (org.aion.zero.impl.types.StakingBlock)1