Search in sources :

Example 71 with NulsException

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

the class CreateP2shTransactionForm method validAddress.

public static boolean validAddress(String address) {
    if (StringUtils.isBlank(address)) {
        return false;
    }
    byte[] bytes;
    try {
        bytes = Base58.decode(address);
        if (bytes.length != Address.ADDRESS_LENGTH + 1) {
            return false;
        }
    } catch (NulsException e) {
        return false;
    } catch (Exception e) {
        return false;
    }
    NulsByteBuffer byteBuffer = new NulsByteBuffer(bytes);
    short chainId;
    byte type;
    try {
        chainId = byteBuffer.readShort();
        type = byteBuffer.readByte();
    } catch (NulsException e) {
        Log.error(e);
        return false;
    }
    if (NulsContext.getInstance().getDefaultChainId() != chainId) {
        return false;
    }
    if (NulsContext.MAIN_NET_VERSION <= 1 || NulsContext.CONTRACT_ADDRESS_TYPE == type) {
        return false;
    }
    if (NulsContext.DEFAULT_ADDRESS_TYPE != type && NulsContext.P2SH_ADDRESS_TYPE != type) {
        return false;
    }
    try {
        AddressTool.checkXOR(bytes);
    } catch (Exception e) {
        return false;
    }
    return true;
}
Also used : NulsException(io.nuls.kernel.exception.NulsException) NulsException(io.nuls.kernel.exception.NulsException) NulsByteBuffer(io.nuls.kernel.utils.NulsByteBuffer)

Example 72 with NulsException

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

the class BalanceManager method initAccountBalance.

/**
 * 初始化缓存本地所有账户的余额信息
 */
public void initAccountBalance() {
    balanceMap.clear();
    Collection<Account> accounts = accountService.getAccountList().getData();
    if (accounts == null) {
        return;
    }
    for (Account account : accounts) {
        try {
            calBalanceByAddress(account.getAddress().getAddressBytes());
        } catch (NulsException e) {
            Log.info("getbalance of address[" + account.getAddress().getBase58() + "] error");
        }
    }
}
Also used : Account(io.nuls.account.model.Account) NulsException(io.nuls.kernel.exception.NulsException)

Example 73 with NulsException

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

the class SpringLiteContext method checkBeanClass.

/**
 * 检查一个类型,如果这个类型上被注释了我们关心的注解,如:Service/Component/Interceptor,就对这个对象进行加载,并放入bean管理器中
 * Check a type, if this is commented on the type annotation, we care about, such as: (Service/Component/Interceptor), is to load the object, and in the bean manager
 *
 * @param clazz class type
 */
private static void checkBeanClass(Class clazz) {
    Annotation[] anns = clazz.getDeclaredAnnotations();
    if (anns == null || anns.length == 0) {
        return;
    }
    Annotation ann = getFromArray(anns, Service.class);
    String beanName = null;
    boolean aopProxy = false;
    if (null == ann) {
        ann = getFromArray(anns, Component.class);
        if (null != ann) {
            beanName = ((Component) ann).value();
        }
    } else {
        beanName = ((Service) ann).value();
    }
    if (ann != null) {
        if (beanName == null || beanName.trim().length() == 0) {
            beanName = getBeanName(clazz);
        }
        try {
            loadBean(beanName, clazz, aopProxy);
        } catch (NulsException e) {
            Log.error(e);
            return;
        }
    }
    Annotation interceptorAnn = getFromArray(anns, Interceptor.class);
    if (null != interceptorAnn) {
        BeanMethodInterceptor interceptor = null;
        try {
            Constructor constructor = clazz.getDeclaredConstructor();
            interceptor = (BeanMethodInterceptor) constructor.newInstance();
        } catch (Exception e) {
            Log.error(e);
            return;
        }
        BeanMethodInterceptorManager.addBeanMethodInterceptor(((Interceptor) interceptorAnn).value(), interceptor);
    }
}
Also used : NulsException(io.nuls.kernel.exception.NulsException) Constructor(java.lang.reflect.Constructor) BeanMethodInterceptor(io.nuls.kernel.lite.core.interceptor.BeanMethodInterceptor) Component(io.nuls.kernel.lite.annotation.Component) Annotation(java.lang.annotation.Annotation) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) NulsException(io.nuls.kernel.exception.NulsException)

Example 74 with NulsException

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

the class NulsByteBuffer method readUint16.

public int readUint16() throws NulsException {
    try {
        int val = SerializeUtils.readUint16LE(payload, cursor);
        cursor += 2;
        return val;
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new NulsException(KernelErrorCode.DATA_PARSE_ERROR, e);
    }
}
Also used : NulsException(io.nuls.kernel.exception.NulsException)

Example 75 with NulsException

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

the class NulsByteBuffer method readInt64.

public long readInt64() throws NulsException {
    try {
        long u = SerializeUtils.readInt64LE(payload, cursor);
        cursor += 8;
        return u;
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new NulsException(KernelErrorCode.DATA_PARSE_ERROR, e);
    }
}
Also used : NulsException(io.nuls.kernel.exception.NulsException)

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