Beispiel #1
0
        public override bool Equals(object other)
        {
            if (other == null)
            {
                return(false);
            }

            if (!(other is StoredBlock))
            {
                return(false);
            }

            StoredBlock otherStronglyTyped = (StoredBlock)other;

            return(ReferenceEquals(this, other) || (otherStronglyTyped.Header.Equals(Header) && otherStronglyTyped.ChainWork.Equals(ChainWork) && otherStronglyTyped.Height == Height));
        }
Beispiel #2
0
 public override void Put(StoredBlock block)
 {
     using (locker.AcquireWriterLock())
     { store[block.Header.Hash.ToString()] = block; }
 }
Beispiel #3
0
 /// <summary>
 /// Returns true if this objects chainWork is higher than the others.
 /// </summary>
 public bool MoreWorkThan(StoredBlock other)
 {
     return(ChainWork.CompareTo(other.ChainWork) > 0);
 }
Beispiel #4
0
		///**
		// * Calculates the sum of the outputs that are sending coins to a key in the wallet. The flag controls whether to
		// * include spent outputs or not.
		// */
		//BigInteger getValueSentToMe(Wallet wallet,bool includeSpent)
		//{
		//	EnsureParsed();
		//	// This is tested in WalletTest.
		//	BigInteger v = BigInteger.ZERO;
		//	for (TransactionOutput o : outputs) {
		//		if (!o.isMine(wallet)) continue;
		//		if (!includeSpent && !o.isAvailableForSpending()) continue;
		//		v = v.add(o.getValue());
		//	}
		//	return v;
		//}
    
		///*
		// * If isSpent - check that all my outputs spent, otherwise check that there at least
		// * one unspent.
		// */
		//boolean isConsistent(Wallet wallet, boolean isSpent) {
		//	boolean isActuallySpent = true;
		//	for (TransactionOutput o : outputs) {
		//		if (o.isAvailableForSpending()) {
		//			if (o.isMine(wallet)) isActuallySpent = false;
		//			if (o.getSpentBy() != null) {
		//				log.error("isAvailableForSpending != spentBy");
		//				return false;
		//			}
		//		} else {
		//			if (o.getSpentBy() == null) {
		//				log.error("isAvailableForSpending != spentBy");
		//				return false;
		//			}
		//		}
		//	}
		//	return isActuallySpent == isSpent;
		//}

		///**
		// * Calculates the sum of the outputs that are sending coins to a key in the wallet.
		// */
		//public BigInteger getValueSentToMe(Wallet wallet) {
		//	return getValueSentToMe(wallet, true);
		//}

		///**
		// * Returns a set of blocks which contain the transaction, or null if this transaction doesn't have that data
		// * because it's not stored in the wallet or because it has never appeared in a block.
		// */
		//public Collection<Sha256Hash> getAppearsInHashes() {
		//	return appearsInHashes;
		//}

		/**
		 * <p>Puts the given block in the internal serializable 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)
		 */
		public void setBlockAppearance(StoredBlock block,bool bestChain)
		{
			long blockTime=block.GetHeader().TimeSeconds;
			if (bestChain && (updatedAt == null || updatedAt.getTime() == 0 || updatedAt.getTime() > blockTime)) {
				updatedAt = new Date(blockTime);
			}

			addBlockAppearance(block.GetHeader().getHash());

			if(bestChain)
			{
				// This can cause event listeners on TransactionConfidence to run. After these lines complete, the wallets
				// state may have changed!
				TransactionConfidence transactionConfidence = getConfidence();
				transactionConfidence.setAppearedAtChainHeight(block.getHeight());

				// Reset the confidence block depth.
				transactionConfidence.setDepthInBlocks(1);

				// Reset the work done.
				transactionConfidence.setWorkDone(block.getHeader().getWork());

				// The transaction is now on the best chain.
				transactionConfidence.setConfidenceType(ConfidenceType.BUILDING);
			}
		}
Beispiel #5
0
 /// <summary>
 /// Returns true if this objects chainWork is higher than the others.
 /// </summary>
 public bool MoreWorkThan(StoredBlock other)
 {
     return ChainWork.CompareTo(other.ChainWork)>0;
 }
 public override void Put(StoredBlock block)
 {
     using(locker.AcquireWriterLock())
     { store[block.Header.Hash.ToString()]=block; }
 }