本文整理了Java中io.nuls.kernel.model.Transaction.getHash()
方法的一些代码示例,展示了Transaction.getHash()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.getHash()
方法的具体详情如下:
包路径:io.nuls.kernel.model.Transaction
类名称:Transaction
方法名:getHash
暂无
代码示例来源:origin: nuls-io/nuls
public List<NulsDigestData> getTxHashList() {
List<NulsDigestData> list = new ArrayList<>();
for (Transaction tx : txs) {
if (null == tx) {
continue;
}
list.add(tx.getHash());
}
return list;
}
代码示例来源:origin: nuls-io/nuls
/**
* 交易整理到hashmap中
* The transaction is sorted into a hashmap.
*/
private synchronized void initTxMap() {
if (null != txMap) {
return;
}
this.txMap = new HashMap<>();
for (Transaction tx : txList) {
txMap.put(tx.getHash(), tx);
}
}
代码示例来源:origin: nuls-io/nuls
/**
* 缓存一个交易,缓存的标识就是交易的hash对象,该交易在内存中存在,直到内存大小达到限制或者存活时间超过1000秒
* Cache a transaction where the identity of the cache is the hash object of the transaction,
* which exists in memory until the memory size is limited or survived for more than 1000 seconds.
*
* @param tx transaction
*/
public boolean cacheTx(Transaction tx) {
return txCacheMap.put(tx.getHash(), tx);
}
代码示例来源:origin: nuls-io/nuls
public boolean add(Transaction tx, boolean isOrphan) {
try {
if (tx == null) {
return false;
}
//check Repeatability
if (isOrphan) {
NulsDigestData hash = tx.getHash();
orphanContainer.put(hash, tx);
} else {
txQueue.offer(tx);
}
return true;
} finally {
}
}
代码示例来源:origin: nuls-io/nuls
/**
* The transaction is confirmed and the transaction in the memory pool is removed
* <p>
* 交易被确认,移除内存池里面存在的交易
*
* @return boolean
*/
public boolean removeTxFromMemoryPool(Block block) {
boolean success = true;
for (Transaction tx : block.getTxs()) {
transactionCacheStorageService.removeTx(tx.getHash());
}
return success;
}
代码示例来源:origin: nuls-io/nuls
public TransactionInfoPo(Transaction tx) {
if (tx == null) {
return;
}
this.txHash = tx.getHash();
this.blockHeight = tx.getBlockHeight();
this.time = tx.getTime();
List<byte[]> addressList = tx.getAllRelativeAddress();
byte[] addresses = new byte[addressList.size() * Address.ADDRESS_LENGTH];
for (int i = 0; i < addressList.size(); i++) {
System.arraycopy(addressList.get(i), 0, addresses, Address.ADDRESS_LENGTH* i, Address.ADDRESS_LENGTH);
}
this.addresses = addresses;
this.txType = tx.getType();
}
代码示例来源:origin: nuls-io/nuls
public TransactionInfoPo(Transaction tx) {
if (tx == null) {
return;
}
this.txHash = tx.getHash();
this.blockHeight = tx.getBlockHeight();
this.time = tx.getTime();
List<byte[]> addressList = tx.getAllRelativeAddress();
byte[] addresses = new byte[addressList.size() * Address.ADDRESS_LENGTH];
for (int i = 0; i < addressList.size(); i++) {
System.arraycopy(addressList.get(i), 0, addresses, Address.ADDRESS_LENGTH * i, Address.ADDRESS_LENGTH);
}
this.addresses = addresses;
this.txType = tx.getType();
}
代码示例来源:origin: nuls-io/nuls
public boolean addInFirst(Transaction tx, boolean isOrphan) {
try {
if (tx == null) {
return false;
}
//check Repeatability
if (isOrphan) {
NulsDigestData hash = tx.getHash();
orphanContainer.put(hash, tx);
} else {
((LinkedBlockingDeque) txQueue).addFirst(tx);
}
return true;
} finally {
}
}
代码示例来源:origin: nuls-io/nuls
/**
* 转发交易给连接的其他对等节点,允许一个列外(不转发给它)
* Forward Transaction to other peers of the connection, allowing one column (not forward to it)
*
* @param tx 完整交易/the whole transaction
* @param excludeNode 需要排除的节点,一般是因为从该节点处接收的本交易/The nodes that need to be excluded are generally due to the transaction received from the node.
* @return 转发结果/forward results
*/
@Override
public Result forwardTx(Transaction tx, Node excludeNode) {
ForwardTxMessage message = new ForwardTxMessage();
message.setMsgBody(tx.getHash());
return messageBusService.broadcast(message, excludeNode, true, 50);
}
代码示例来源:origin: nuls-io/nuls
@Override
public void onMessage(TransactionMessage message, Node fromNode) {
Transaction tx = message.getMsgBody();
if (null == tx) {
return;
}
if (tx.isSystemTx()) {
return;
}
NulsDigestData hash = tx.getHash();
TransactionDuplicateRemoval.insert(hash);
transactionService.newTx(tx);
}
代码示例来源:origin: nuls-io/nuls
public static SmallBlock getSmallBlock(Block block) {
SmallBlock smallBlock = new SmallBlock();
smallBlock.setHeader(block.getHeader());
List<NulsDigestData> txHashList = new ArrayList<>();
for (Transaction tx : block.getTxs()) {
txHashList.add(tx.getHash());
if (tx.isSystemTx()) {
smallBlock.addBaseTx(tx);
}
}
smallBlock.setTxHashList(txHashList);
return smallBlock;
}
代码示例来源:origin: nuls-io/nuls
private void contractExchange(Transaction tx, ContractResult contractResult, long time, Map<String, Coin> toMaps, Map<String, Coin> contractUsedCoinMap, Long blockHeight, List<ContractTransfer> transfers, Map<String, ContractTransferTransaction> successContractTransferTxs) {
if (contractResult.isSuccess()) {
Set<String> exchangeSet = transfers.stream().filter(t -> ContractUtil.isLegalContractAddress(t.getTo())
&& ArraysTool.arrayEquals(t.getTo(), t.getFrom()))
.map(t -> AddressTool.getStringAddressByBytes(t.getTo())).collect(Collectors.toSet());
byte[] contractAddress = contractResult.getContractAddress();
// NULS转入当前交易的调用合约
if(contractResult.getValue() > 0 && !exchangeSet.contains(AddressTool.getStringAddressByBytes(contractAddress))) {
this.doContractExchange(tx.getHash(), contractAddress, contractResult.getValue(), time, toMaps, contractUsedCoinMap, blockHeight, transfers, successContractTransferTxs);
}
// NULS转入其他合约(合约内部转账,从调用的合约转出到其他合约)
List<ContractTransfer> collect = transfers.stream().filter(t -> ContractUtil.isLegalContractAddress(t.getTo())
&& !exchangeSet.contains(AddressTool.getStringAddressByBytes(t.getTo()))
&& !ArraysTool.arrayEquals(t.getTo(), contractAddress)
&& !ArraysTool.arrayEquals(t.getTo(), t.getFrom()))
.collect(Collectors.toList());
collect.stream().forEach(t -> this.doContractExchange(tx.getHash(), t.getTo(), t.getValue().getValue(), time, toMaps, contractUsedCoinMap, blockHeight, transfers, successContractTransferTxs));
}
}
代码示例来源:origin: nuls-io/nuls
private void deleteUnconfirmedTransaction(Transaction tx) {
accountLedgerService.resetUsedTxSets();
unconfirmedTransactionStorageService.deleteUnconfirmedTx(tx.getHash());
TransactionInfoPo txInfoPo = new TransactionInfoPo(tx);
transactionInfoService.deleteTransactionInfo(txInfoPo);
rollbackUtxo(tx);
}
代码示例来源:origin: nuls-io/nuls
@Override
public Result saveTx(Transaction tx) {
if (tx == null) {
return Result.getFailed(KernelErrorCode.NULL_PARAMETER);
}
byte[] txHashBytes = new byte[0];
try {
txHashBytes = tx.getHash().serialize();
} catch (IOException e) {
Log.error(e);
return Result.getFailed(KernelErrorCode.IO_ERROR);
}
// 保存交易
Result result = dbService.putModel(LedgerStorageConstant.DB_NAME_LEDGER_TX, txHashBytes, tx);
return result;
}
代码示例来源:origin: nuls-io/nuls
public UtxoDto(Coin coin, Transaction tx) {
this.txHash = tx.getHash().getDigestHex();
this.createTime = tx.getTime();
this.txType = tx.getType();
this.lockTime = coin.getLockTime();
this.value = coin.getNa().getValue();
}
代码示例来源:origin: nuls-io/nuls
@Override
public Result deleteTx(Transaction tx) {
if (tx == null) {
return Result.getFailed(KernelErrorCode.NULL_PARAMETER);
}
byte[] txHashBytes = new byte[0];
try {
txHashBytes = tx.getHash().serialize();
} catch (IOException e) {
Log.error(e);
return Result.getFailed(KernelErrorCode.IO_ERROR);
}
// 删除交易
Result result = dbService.delete(LedgerStorageConstant.DB_NAME_LEDGER_TX, txHashBytes);
return result;
}
代码示例来源:origin: nuls-io/nuls
/**
* 生成交易的签名传统
*
* @param tx 交易
* @param ecKey 秘钥
*/
public static P2PHKSignature createSignatureByEckey(Transaction tx, ECKey ecKey) {
P2PHKSignature p2PHKSignature = new P2PHKSignature();
p2PHKSignature.setPublicKey(ecKey.getPubKey());
//用当前交易的hash和账户的私钥账户
p2PHKSignature.setSignData(signDigest(tx.getHash().getDigestBytes(), ecKey));
return p2PHKSignature;
}
代码示例来源:origin: nuls-io/nuls
public void clearIncompatibleTx() {
TransactionQueueStorageService tqs = NulsContext.getServiceBean(TransactionQueueStorageService.class);
while (tqs.pollTx() != null) {
}
TransactionCacheStorageService tcs = NulsContext.getServiceBean(TransactionCacheStorageService.class);
Transaction tx = null;
while ((tx = tcs.pollTx()) != null) {
tcs.removeTx(tx.getHash());
}
TxMemoryPool.getInstance().clear();
}
代码示例来源:origin: nuls-io/nuls
private Result<Integer> rollbackTransaction(Transaction tx) {
if (!AccountLegerUtils.isLocalTransaction(tx)) {
return Result.getSuccess().setData(new Integer(0));
}
List<byte[]> addresses = AccountLegerUtils.getRelatedAddresses(tx);
if (addresses == null || addresses.size() == 0) {
return Result.getSuccess().setData(new Integer(0));
}
if (tx.isSystemTx()) {
return deleteTransaction(tx);
}
TransactionInfoPo txInfoPo = new TransactionInfoPo(tx);
Result result = transactionInfoService.saveTransactionInfo(txInfoPo, addresses);
if (result.isFailed()) {
return result;
}
result = unconfirmedTransactionStorageService.saveUnconfirmedTx(tx.getHash(), tx);
return result;
}
代码示例来源:origin: nuls-io/nuls
public boolean verifyCoinBaseTx(Block block, MeetingRound currentRound, MeetingMember member) {
Transaction tx = block.getTxs().get(0);
CoinBaseTransaction coinBaseTransaction = ConsensusTool.createCoinBaseTx(member, block.getTxs(), currentRound, block.getHeader().getHeight() + PocConsensusConstant.COINBASE_UNLOCK_HEIGHT);
if (null == coinBaseTransaction || !tx.getHash().equals(coinBaseTransaction.getHash())) {
BlockLog.debug("the coin base tx is wrong! height: " + block.getHeader().getHeight() + " , hash : " + block.getHeader().getHash());
Log.error("the coin base tx is wrong! height: " + block.getHeader().getHeight() + " , hash : " + block.getHeader().getHash());
return false;
}
return true;
}
内容来源于网络,如有侵权,请联系作者删除!