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;
}
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");
}
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations