@Override public Transaction pollTx() { byte[] bytes = queue.poll(); if (null == bytes) { return null; } try { return TransactionManager.getInstance(new NulsByteBuffer(bytes)); } catch (Exception e) { Log.error(e); } return null; } }
public abstract void parse(NulsByteBuffer byteBuffer) throws NulsException;
@Override public Transaction pollTx() { byte[] startIndexBytes = Util.intToBytes(startIndex.get()); byte[] hashBytes = dbService.get(TRANSACTION_CACHE_KEY_NAME, startIndexBytes); if (hashBytes == null) { return null; } byte[] txBytes = dbService.get(TRANSACTION_CACHE_KEY_NAME, hashBytes); Transaction tx = null; if (null != txBytes) { try { tx = TransactionManager.getInstance(new NulsByteBuffer(txBytes, 0)); } catch (Exception e) { Log.error(e); return null; } } startIndex.incrementAndGet(); // dbService.put(TRANSACTION_CACHE_KEY_NAME, START_KEY, Util.intToBytes(startIndex)); return tx; }
@POST @Path("/transaction/broadcast") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "广播交易", notes = "result.data: resultJson 返回交易对象") @ApiResponses(value = { @ApiResponse(code = 200, message = "success") }) public RpcClientResult broadcast(@ApiParam(name = "form", value = "交易信息", required = true) BroadHexTxForm form) { if (StringUtils.isBlank(form.getTxHex())) { return Result.getFailed(AccountErrorCode.PARAMETER_ERROR).toRpcClientResult(); } try { byte[] data = Hex.decode(form.getTxHex()); Transaction tx = TransactionManager.getInstance(new NulsByteBuffer(data)); Result result = accountLedgerService.broadcast(tx); if (result.isSuccess()) { Map<String, Object> map = new HashMap<>(); map.put("value", tx.getHash().getDigestHex()); result.setData(map); } return result.toRpcClientResult(); } catch (Exception e) { Log.error(e); return Result.getFailed(LedgerErrorCode.DATA_PARSE_ERROR).toRpcClientResult(); } }
UnconfirmedTxPo tmpTx = new UnconfirmedTxPo(txEntry.getValue()); if (tmpTx != null) { NulsByteBuffer buffer = new NulsByteBuffer(txEntry.getKey(), 0); tmpTx.getTx().setHash(buffer.readHash()); tmpList.add(tmpTx);
public static boolean validNormalAddress(byte[] bytes) { if (null == bytes || bytes.length != Address.ADDRESS_LENGTH) { 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.DEFAULT_ADDRESS_TYPE != type) { return false; } return true; }
public InputDto(Coin input) { NulsByteBuffer byteBuffer = new NulsByteBuffer(input.getOwner()); try { this.fromHash = byteBuffer.readHash().getDigestHex(); this.fromIndex = (int) byteBuffer.readVarInt(); } catch (Exception e) { throw new NulsRuntimeException(e); } this.value = input.getNa().getValue(); }
private List<BaseMessage> analysisMessage(ByteBuf buffer) throws NulsException { List<BaseMessage> messageList; try { messageList = new ArrayList<>(); byte[] bytes = new byte[buffer.readableBytes()]; buffer.readBytes(bytes); NulsByteBuffer byteBuffer = new NulsByteBuffer(bytes); while (!byteBuffer.isFinished()) { MessageHeader header = byteBuffer.readNulsData(new MessageHeader()); byteBuffer.setCursor(byteBuffer.getCursor() - header.size()); BaseMessage message = getMessageBusService().getMessageInstance(header.getModuleId(), header.getMsgType()).getData(); message = byteBuffer.readNulsData(message); messageList.add(message); } } catch (Exception e) { throw new NulsException(KernelErrorCode.DATA_ERROR, e); } finally { buffer.clear(); } return messageList; }
public static boolean validContractAddress(byte[] addressBytes) { if (addressBytes == null) { return false; } if (addressBytes.length != Address.ADDRESS_LENGTH) { return false; } NulsByteBuffer byteBuffer = new NulsByteBuffer(addressBytes); 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.CONTRACT_ADDRESS_TYPE != type) { return false; } return true; }
@POST @Path("/transaction/validate") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "验证交易是否正确", notes = "result.data: resultJson 返回验证结果") @ApiResponses(value = { @ApiResponse(code = 200, message = "success") }) public RpcClientResult validate(@ApiParam(name = "form", value = "验证交易是否正确", required = true) BroadHexTxForm form) { if (StringUtils.isBlank(form.getTxHex())) { return Result.getFailed(AccountErrorCode.PARAMETER_ERROR).toRpcClientResult(); } try { byte[] data = Hex.decode(form.getTxHex()); Transaction tx = TransactionManager.getInstance(new NulsByteBuffer(data)); ValidateResult validateResult = tx.verify(); if (validateResult.isFailed()) { return Result.getFailed(validateResult.getErrorCode()).toRpcClientResult(); } validateResult = this.ledgerService.verifyCoinData(tx, new HashMap<>(), new HashSet<>()); if (validateResult.isFailed()) { return Result.getFailed(validateResult.getErrorCode()).toRpcClientResult(); } Result result = Result.getSuccess(); return result.toRpcClientResult(); } catch (Exception e) { Log.error(e); return Result.getFailed(LedgerErrorCode.DATA_PARSE_ERROR).toRpcClientResult(); } }
@Override public Transaction getTx(NulsDigestData hash) { if (hash == null) { return null; } byte[] hashBytes = null; try { hashBytes = hash.serialize(); } catch (IOException e) { Log.error(e); throw new NulsRuntimeException(e); } byte[] txBytes = dbService.get(TRANSACTION_CACHE_KEY_NAME, hashBytes); Transaction tx = null; if (null != txBytes) { try { tx = TransactionManager.getInstance(new NulsByteBuffer(txBytes, 0)); } catch (Exception e) { Log.error(e); return null; } } return tx; }
@POST @Path("/transaction/valiTransaction") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "验证交易是否正确", notes = "result.data: resultJson 返回验证结果") @ApiResponses(value = { @ApiResponse(code = 200, message = "success") }) public RpcClientResult valiTransaction(@ApiParam(name = "form", value = "验证交易是否正确", required = true) BroadHexTxForm form) { if (StringUtils.isBlank(form.getTxHex())) { return Result.getFailed(AccountErrorCode.PARAMETER_ERROR).toRpcClientResult(); } try { byte[] data = Hex.decode(form.getTxHex()); Transaction tx = TransactionManager.getInstance(new NulsByteBuffer(data)); ValidateResult validateResult = tx.verify(); if (validateResult.isFailed()) { return Result.getFailed(validateResult.getErrorCode()).toRpcClientResult(); } validateResult = this.ledgerService.verifyCoinData(tx, new HashMap<>(), new HashSet<>()); if (validateResult.isFailed() && !validateResult.getErrorCode().equals(TransactionErrorCode.ORPHAN_TX)) { return Result.getFailed(validateResult.getErrorCode()).toRpcClientResult(); } Result result = Result.getSuccess(); return result.toRpcClientResult(); } catch (Exception e) { Log.error(e); return Result.getFailed(LedgerErrorCode.DATA_PARSE_ERROR).toRpcClientResult(); } }
MultiSigAccount account = new MultiSigAccount(); try { account.parse(new NulsByteBuffer(bytes, 0)); } catch (NulsException e) { Log.error(e);
return false; NulsByteBuffer byteBuffer = new NulsByteBuffer(bytes); short chainId; byte type;
return false; NulsByteBuffer byteBuffer = new NulsByteBuffer(bytes); short chainId; byte type;
Transaction tx = TransactionManager.getInstance(new NulsByteBuffer(txByte)); TransactionSignature transactionSignature = new TransactionSignature(); transactionSignature.parse(new NulsByteBuffer(tx.getTransactionSignature()));
/** * 根据地址获取本地存储的多签账户的详细信息 * Get the details of the locally stored multi-sign account based on the address * * @param address 多签地址 * @return 多签账户的详细信息 */ @Override public Result<MultiSigAccount> getMultiSigAccount(String address) throws Exception { byte[] bytes = this.multiSigAccountStorageService.getAccount(Address.fromHashs(address)).getData(); if (null == bytes) { return Result.getFailed(KernelErrorCode.DATA_NOT_FOUND); } MultiSigAccount account = new MultiSigAccount(); account.parse(new NulsByteBuffer(bytes, 0)); List<AliasPo> list = aliasStorageService.getAliasList().getData(); for (AliasPo aliasPo : list) { if (aliasPo.getAddress()[2] != NulsContext.P2SH_ADDRESS_TYPE) { continue; } if (Arrays.equals(aliasPo.getAddress(), account.getAddress().getAddressBytes())) { account.setAlias(aliasPo.getAlias()); break; } } return Result.getSuccess().setData(account); }
TransactionSignature transactionSignature = new TransactionSignature(); byte[] txByte = Hex.decode(txdata); tx.parse(new NulsByteBuffer(txByte)); transactionSignature.parse(new NulsByteBuffer(tx.getTransactionSignature())); return accountLedgerService.txMultiProcess(tx,transactionSignature,account,password); }catch (NulsException e) {
} else { for (Coin coin : o1.getCoinData().getFrom()) { NulsByteBuffer buffer = new NulsByteBuffer(coin.getOwner()); NulsDigestData hash = null; try { NulsByteBuffer buffer = new NulsByteBuffer(coin.getOwner()); NulsDigestData hash = null; try {
for (Coin from : froms) { try { NulsByteBuffer byteBuffer = new NulsByteBuffer(from.getOwner());