Search in sources :

Example 41 with NulsException

use of io.nuls.kernel.exception.NulsException in project nuls by nuls-io.

the class SpringLiteContext method loadBean.

// /**
// * 初始化该类型的实例,由参数决定是否使用动态代理的方式进行实例化,将实例化后的对象加入对象池
// * Instantiate an instance of this type by instantiating the instantiated object
// * into the object pool by determining whether the dynamic proxy is used.
// *
// * @param beanName 对象名称
// * @param clazz    对象类型
// * @param proxy    是否返回动态代理的对象
// */
private static Object loadBean(String beanName, Class clazz, boolean proxy) throws NulsException {
    if (BEAN_OK_MAP.containsKey(beanName)) {
        Log.error("bean name repetition (" + beanName + "):" + clazz.getName());
        return BEAN_OK_MAP.get(beanName);
    }
    if (BEAN_TEMP_MAP.containsKey(beanName)) {
        Log.error("bean name repetition (" + beanName + "):" + clazz.getName());
        return BEAN_TEMP_MAP.get(beanName);
    }
    Object bean = null;
    if (proxy) {
        bean = createProxy(clazz, interceptor);
    } else {
        try {
            bean = clazz.newInstance();
        } catch (InstantiationException e) {
            Log.error(e);
            throw new NulsException(e);
        } catch (IllegalAccessException e) {
            Log.error(e);
            throw new NulsException(e);
        }
    }
    BEAN_TEMP_MAP.put(beanName, bean);
    BEAN_TYPE_MAP.put(beanName, clazz);
    addClassNameMap(clazz, beanName);
    return bean;
}
Also used : NulsException(io.nuls.kernel.exception.NulsException)

Example 42 with NulsException

use of io.nuls.kernel.exception.NulsException in project nuls by nuls-io.

the class AccountBaseServiceTest method setPassword.

@Test
public void setPassword() {
    List<Account> accounts = this.accountService.createAccount(1, "").getData();
    Account account = accounts.get(0);
    accountBaseService.setPassword(account.getAddress().toString(), "nuls123456");
    Account acc = accountService.getAccount(account.getAddress()).getData();
    try {
        assertTrue(acc.unlock("nuls123456"));
        assertArrayEquals(acc.getPriKey(), account.getPriKey());
    } catch (NulsException e) {
        e.printStackTrace();
    }
}
Also used : Account(io.nuls.account.model.Account) NulsException(io.nuls.kernel.exception.NulsException) Test(org.junit.Test)

Example 43 with NulsException

use of io.nuls.kernel.exception.NulsException in project nuls by nuls-io.

the class CommandHandler method main.

public static void main(String[] args) {
    /**
     * 如果操作系统是windows, 可能会使控制台读取部分处于死循环,可以设置为false,绕过本地Windows API,直接使用Java IO流输出
     * If the operating system is windows, it may cause the console to read part of the loop, can be set to false,
     * bypass the native Windows API, use the Java IO stream output directly
     */
    if (System.getProperties().getProperty("os.name").toUpperCase().indexOf("WINDOWS") != -1) {
        System.setProperty("jline.WindowsTerminal.directConsole", "false");
    }
    NULSParams.BOOTSTRAP.init(args);
    CommandHandler instance = new CommandHandler();
    instance.init();
    try {
        I18nUtils.setLanguage("en");
    } catch (NulsException e) {
        e.printStackTrace();
    }
    try {
        CONSOLE_READER = new ConsoleReader();
        List<Completer> completers = new ArrayList<Completer>();
        completers.add(new StringsCompleter(PROCESSOR_MAP.keySet()));
        CONSOLE_READER.addCompleter(new ArgumentCompleter(completers));
        String line;
        do {
            line = CONSOLE_READER.readLine(CommandConstant.COMMAND_PS1);
            if (StringUtils.isBlank(line)) {
                continue;
            }
            String[] cmdArgs = parseArgs(line);
            System.out.print(instance.processCommand(cmdArgs) + "\n");
        } while (line != null);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (!CONSOLE_READER.delete()) {
                CONSOLE_READER.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : ConsoleReader(jline.console.ConsoleReader) StringsCompleter(jline.console.completer.StringsCompleter) NulsException(io.nuls.kernel.exception.NulsException) ArgumentCompleter(jline.console.completer.ArgumentCompleter) ArrayList(java.util.ArrayList) Completer(jline.console.completer.Completer) StringsCompleter(jline.console.completer.StringsCompleter) ArgumentCompleter(jline.console.completer.ArgumentCompleter) IOException(java.io.IOException)

Example 44 with NulsException

use of io.nuls.kernel.exception.NulsException in project nuls by nuls-io.

the class PocConsensusResource method withdraw.

@POST
@Path("/withdraw")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "退出共识 [3.6.11]", notes = "返回退出成功的交易hash")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = String.class) })
public RpcClientResult withdraw(@ApiParam(name = "form", value = "退出共识表单数据", required = true) WithdrawForm form) throws NulsException, IOException {
    AssertUtil.canNotEmpty(form);
    AssertUtil.canNotEmpty(form.getTxHash());
    if (!NulsDigestData.validHash(form.getTxHash())) {
        return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
    }
    AssertUtil.canNotEmpty(form.getAddress());
    if (!AddressTool.validAddress(form.getAddress())) {
        return Result.getFailed(AccountErrorCode.ADDRESS_ERROR).toRpcClientResult();
    }
    Account account = accountService.getAccount(form.getAddress()).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();
        }
    }
    CancelDepositTransaction tx = new CancelDepositTransaction();
    CancelDeposit cancelDeposit = new CancelDeposit();
    NulsDigestData hash = NulsDigestData.fromDigestHex(form.getTxHash());
    DepositTransaction depositTransaction = null;
    try {
        depositTransaction = (DepositTransaction) ledgerService.getTx(hash);
    } catch (Exception e) {
        return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
    }
    if (null == depositTransaction) {
        return Result.getFailed(TransactionErrorCode.TX_NOT_EXIST).toRpcClientResult();
    }
    cancelDeposit.setAddress(AddressTool.getAddress(form.getAddress()));
    cancelDeposit.setJoinTxHash(hash);
    tx.setTxData(cancelDeposit);
    CoinData coinData = new CoinData();
    List<Coin> toList = new ArrayList<>();
    toList.add(new Coin(cancelDeposit.getAddress(), depositTransaction.getTxData().getDeposit(), 0));
    coinData.setTo(toList);
    List<Coin> fromList = new ArrayList<>();
    for (int index = 0; index < depositTransaction.getCoinData().getTo().size(); index++) {
        Coin coin = depositTransaction.getCoinData().getTo().get(index);
        if (coin.getLockTime() == -1L && coin.getNa().equals(depositTransaction.getTxData().getDeposit())) {
            coin.setOwner(ArraysTool.concatenate(hash.serialize(), new VarInt(index).encode()));
            fromList.add(coin);
            break;
        }
    }
    if (fromList.isEmpty()) {
        return Result.getFailed(KernelErrorCode.DATA_ERROR).toRpcClientResult();
    }
    coinData.setFrom(fromList);
    tx.setCoinData(coinData);
    Na fee = TransactionFeeCalculator.getMaxFee(108 + tx.size());
    coinData.getTo().get(0).setNa(coinData.getTo().get(0).getNa().subtract(fee));
    RpcClientResult result1 = this.txProcessing(tx, null, account, form.getPassword());
    if (!result1.isSuccess()) {
        return result1;
    }
    Map<String, String> valueMap = new HashMap<>();
    valueMap.put("value", tx.getHash().getDigestHex());
    return Result.getSuccess().setData(valueMap).toRpcClientResult();
}
Also used : CancelDeposit(io.nuls.consensus.poc.protocol.entity.CancelDeposit) Account(io.nuls.account.model.Account) MultiSigAccount(io.nuls.account.model.MultiSigAccount) CancelDepositTransaction(io.nuls.consensus.poc.protocol.tx.CancelDepositTransaction) DepositTransaction(io.nuls.consensus.poc.protocol.tx.DepositTransaction) VarInt(io.nuls.kernel.utils.VarInt) NulsException(io.nuls.kernel.exception.NulsException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) IOException(java.io.IOException) CancelDepositTransaction(io.nuls.consensus.poc.protocol.tx.CancelDepositTransaction)

Example 45 with NulsException

use of io.nuls.kernel.exception.NulsException in project nuls by nuls-io.

the class AgentStorageServiceImpl method getList.

@Override
public List<AgentPo> getList() {
    List<Entry<byte[], byte[]>> list = dbService.entryList(ConsensusStorageConstant.DB_NAME_CONSENSUS_AGENT);
    List<AgentPo> resultList = new ArrayList<>();
    if (list == null) {
        return resultList;
    }
    for (Entry<byte[], byte[]> entry : list) {
        AgentPo agentPo = new AgentPo();
        try {
            agentPo.parse(entry.getValue(), 0);
        } catch (NulsException e) {
            Log.error(e);
            throw new NulsRuntimeException(e);
        }
        NulsDigestData hash = new NulsDigestData();
        try {
            hash.parse(entry.getKey(), 0);
        } catch (NulsException e) {
            Log.error(e);
        }
        agentPo.setHash(hash);
        resultList.add(agentPo);
    }
    return resultList;
}
Also used : Entry(io.nuls.db.model.Entry) NulsException(io.nuls.kernel.exception.NulsException) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) NulsDigestData(io.nuls.kernel.model.NulsDigestData) AgentPo(io.nuls.consensus.poc.storage.po.AgentPo)

Aggregations

NulsException (io.nuls.kernel.exception.NulsException)109 IOException (java.io.IOException)35 Account (io.nuls.account.model.Account)25 ValidateResult (io.nuls.kernel.validate.ValidateResult)23 ECKey (io.nuls.core.tools.crypto.ECKey)20 CoinDataResult (io.nuls.account.ledger.model.CoinDataResult)18 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)16 UnsupportedEncodingException (java.io.UnsupportedEncodingException)14 TransferTransaction (io.nuls.protocol.model.tx.TransferTransaction)13 Coin (io.nuls.kernel.model.Coin)12 MultiSigAccount (io.nuls.account.model.MultiSigAccount)11 ContractResult (io.nuls.contract.dto.ContractResult)9 NulsByteBuffer (io.nuls.kernel.utils.NulsByteBuffer)9 ArrayList (java.util.ArrayList)9 TransactionSignature (io.nuls.kernel.script.TransactionSignature)8 BigInteger (java.math.BigInteger)8 TransactionDataResult (io.nuls.account.ledger.model.TransactionDataResult)7 AccountPo (io.nuls.account.storage.po.AccountPo)7 AliasPo (io.nuls.account.storage.po.AliasPo)7 CryptoException (io.nuls.core.tools.crypto.Exception.CryptoException)7