@Override public void setAppearedAtChainHeight(int appearedAtChainHeight) { tx.getConfidence().setAppearedAtChainHeight(appearedAtChainHeight); }
@Override public void setAppearedAtChainHeight(int appearedAtChainHeight) { tx.getConfidence().setAppearedAtChainHeight(appearedAtChainHeight); }
/** * <p>Puts the given block in the internal set of blocks in which this transaction appears. This is * used by the wallet to ensure transactions that appear on side chains are recorded properly even though the * block stores do not save the transaction data at all.</p> * * <p>If there is a re-org this will be called once for each block that was previously seen, to update which block * is the best chain. The best chain block is guaranteed to be called last. So this must be idempotent.</p> * * <p>Sets updatedAt to be the earliest valid block time where this tx was seen.</p> * * @param block The {@link StoredBlock} in which the transaction has appeared. * @param bestChain whether to set the updatedAt timestamp from the block header (only if not already set) * @param relativityOffset A number that disambiguates the order of transactions within a block. */ public void setBlockAppearance(StoredBlock block, boolean bestChain, int relativityOffset) { long blockTime = block.getHeader().getTimeSeconds() * 1000; if (bestChain && (updatedAt == null || updatedAt.getTime() == 0 || updatedAt.getTime() > blockTime)) { updatedAt = new Date(blockTime); } addBlockAppearance(block.getHeader().getHash(), relativityOffset); if (bestChain) { TransactionConfidence transactionConfidence = getConfidence(); // This sets type to BUILDING and depth to one. transactionConfidence.setAppearedAtChainHeight(block.getHeight()); } }
/** * <p>Puts the given block in the internal set of blocks in which this transaction appears. This is * used by the wallet to ensure transactions that appear on side chains are recorded properly even though the * block stores do not save the transaction data at all.</p> * * <p>If there is a re-org this will be called once for each block that was previously seen, to update which block * is the best chain. The best chain block is guaranteed to be called last. So this must be idempotent.</p> * * <p>Sets updatedAt to be the earliest valid block time where this tx was seen.</p> * * @param block The {@link StoredBlock} in which the transaction has appeared. * @param bestChain whether to set the updatedAt timestamp from the block header (only if not already set) * @param relativityOffset A number that disambiguates the order of transactions within a block. */ public void setBlockAppearance(StoredBlock block, boolean bestChain, int relativityOffset) { long blockTime = block.getHeader().getTimeSeconds() * 1000; if (bestChain && (updatedAt == null || updatedAt.getTime() == 0 || updatedAt.getTime() > blockTime)) { updatedAt = new Date(blockTime); } addBlockAppearance(block.getHeader().getHash(), relativityOffset); if (bestChain) { TransactionConfidence transactionConfidence = getConfidence(); // This sets type to BUILDING and depth to one. transactionConfidence.setAppearedAtChainHeight(block.getHeight()); } }
/** * <p>Puts the given block in the internal set of blocks in which this transaction appears. This is * used by the wallet to ensure transactions that appear on side chains are recorded properly even though the * block stores do not save the transaction data at all.</p> * * <p>If there is a re-org this will be called once for each block that was previously seen, to update which block * is the best chain. The best chain block is guaranteed to be called last. So this must be idempotent.</p> * * <p>Sets updatedAt to be the earliest valid block time where this tx was seen.</p> * * @param block The {@link StoredBlock} in which the transaction has appeared. * @param bestChain whether to set the updatedAt timestamp from the block header (only if not already set) * @param relativityOffset A number that disambiguates the order of transactions within a block. */ public void setBlockAppearance(StoredBlock block, boolean bestChain, int relativityOffset) { long blockTime = block.getHeader().getTimeSeconds() * 1000; if (bestChain && (updatedAt == null || updatedAt.getTime() == 0 || updatedAt.getTime() > blockTime)) { updatedAt = new Date(blockTime); } addBlockAppearance(block.getHeader().getHash(), relativityOffset); if (bestChain) { TransactionConfidence transactionConfidence = getConfidence(); // This sets type to BUILDING and depth to one. transactionConfidence.setAppearedAtChainHeight(block.getHeight()); } }
/** * <p>Puts the given block in the internal set of blocks in which this transaction appears. This is * used by the wallet to ensure transactions that appear on side chains are recorded properly even though the * block stores do not save the transaction data at all.</p> * * <p>If there is a re-org this will be called once for each block that was previously seen, to update which block * is the best chain. The best chain block is guaranteed to be called last. So this must be idempotent.</p> * * <p>Sets updatedAt to be the earliest valid block time where this tx was seen.</p> * * @param block The {@link StoredBlock} in which the transaction has appeared. * @param bestChain whether to set the updatedAt timestamp from the block header (only if not already set) * @param relativityOffset A number that disambiguates the order of transactions within a block. */ public void setBlockAppearance(StoredBlock block, boolean bestChain, int relativityOffset) { long blockTime = block.getHeader().getTimeSeconds() * 1000; if (bestChain && (updatedAt == null || updatedAt.getTime() == 0 || updatedAt.getTime() > blockTime)) { updatedAt = new Date(blockTime); } addBlockAppearance(block.getHeader().getHash(), relativityOffset); if (bestChain) { TransactionConfidence transactionConfidence = getConfidence(); // This sets type to BUILDING and depth to one. transactionConfidence.setAppearedAtChainHeight(block.getHeight()); } }
@Test public void testTheTXByHeightComparator() { Transaction tx1 = FakeTxBuilder.createFakeTx(PARAMS); tx1.getConfidence().setAppearedAtChainHeight(1); Transaction tx2 = FakeTxBuilder.createFakeTx(PARAMS); tx2.getConfidence().setAppearedAtChainHeight(2); Transaction tx3 = FakeTxBuilder.createFakeTx(PARAMS); tx3.getConfidence().setAppearedAtChainHeight(3); SortedSet<Transaction> set = new TreeSet<>(Transaction.SORT_TX_BY_HEIGHT); set.add(tx2); set.add(tx1); set.add(tx3); Iterator<Transaction> iterator = set.iterator(); assertEquals(tx1.equals(tx2), false); assertEquals(tx1.equals(tx3), false); assertEquals(tx1.equals(tx1), true); assertEquals(iterator.next().equals(tx3), true); assertEquals(iterator.next().equals(tx2), true); assertEquals(iterator.next().equals(tx1), true); assertEquals(iterator.hasNext(), false); }
return; confidence.setAppearedAtChainHeight(confidenceProto.getAppearedAtHeight());
return; confidence.setAppearedAtChainHeight(confidenceProto.getAppearedAtHeight());
return; confidence.setAppearedAtChainHeight(confidenceProto.getAppearedAtHeight());
return; confidence.setAppearedAtChainHeight(confidenceProto.getAppearedAtHeight());
return; confidence.setAppearedAtChainHeight(confidenceProto.getAppearedAtHeight());
txConf.setConfidenceType(fullTxConf.getConfidenceType()); if (txConf.getConfidenceType() == BUILDING) { txConf.setAppearedAtChainHeight(fullTxConf.getAppearedAtChainHeight()); txConf.setDepthInBlocks(fullTxConf.getDepthInBlocks());
txConf.setConfidenceType(fullTxConf.getConfidenceType()); if (txConf.getConfidenceType() == BUILDING) { txConf.setAppearedAtChainHeight(fullTxConf.getAppearedAtChainHeight()); txConf.setDepthInBlocks(fullTxConf.getDepthInBlocks());
return; confidence.setAppearedAtChainHeight(confidenceProto.getAppearedAtHeight());