Esempio n. 1
0
		public MerkleBlock(Block block, uint256[] txIds)
		{
			header = block.Header;

			List<bool> vMatch = new List<bool>();
			List<uint256> vHashes = new List<uint256>();
			for(int i = 0 ; i < block.Transactions.Count ; i++)
			{
				var hash = block.Transactions[i].GetHash();
				vHashes.Add(hash);
				vMatch.Add(txIds.Contains(hash));
			}
			_PartialMerkleTree = new PartialMerkleTree(vHashes.ToArray(), vMatch.ToArray());
		}
Esempio n. 2
0
		// Create from a CBlock, filtering transactions according to filter
		// Note that this will call IsRelevantAndUpdate on the filter for each transaction,
		// thus the filter will likely be modified.
		public MerkleBlock(Block block, BloomFilter filter)
		{
			header = block.Header;

			List<bool> vMatch = new List<bool>();
			List<uint256> vHashes = new List<uint256>();


			for(uint i = 0 ; i < block.Transactions.Count ; i++)
			{
				uint256 hash = block.Transactions[(int)i].GetHash();
				vMatch.Add(filter.IsRelevantAndUpdate(block.Transactions[(int)i]));
				vHashes.Add(hash);
			}

			_PartialMerkleTree = new PartialMerkleTree(vHashes.ToArray(), vMatch.ToArray());
		}
Esempio n. 3
0
        // Create from a CBlock, filtering transactions according to filter
        // Note that this will call IsRelevantAndUpdate on the filter for each transaction,
        // thus the filter will likely be modified.
        public MerkleBlock(Block block, BloomFilter filter)
        {
            this.header = block.Header;

            var vMatch  = new List <bool>();
            var vHashes = new List <uint256>();


            for (uint i = 0; i < block.Transactions.Count; i++)
            {
                var hash = block.Transactions[(int)i].GetHash();
                vMatch.Add(filter.IsRelevantAndUpdate(block.Transactions[(int)i]));
                vHashes.Add(hash);
            }

            this._PartialMerkleTree = new PartialMerkleTree(vHashes.ToArray(), vMatch.ToArray());
        }
Esempio n. 4
0
        public ProvenBlockHeader(PosBlock block)
        {
            if (block == null)
            {
                throw new ArgumentNullException(nameof(block));
            }

            // Copy block header properties.
            this.HashPrevBlock  = block.Header.HashPrevBlock;
            this.HashMerkleRoot = block.Header.HashMerkleRoot;
            this.Time           = block.Header.Time;
            this.Bits           = block.Header.Bits;
            this.Nonce          = block.Header.Nonce;
            this.Version        = block.Header.Version;

            this.signature   = block.BlockSignature;
            this.coinstake   = block.Transactions[1];
            this.merkleProof = new MerkleBlock(block, new[] { this.coinstake.GetHash() }).PartialMerkleTree;
        }
Esempio n. 5
0
        /// <summary>
        /// Remove superflous branches
        /// </summary>
        /// <param name="transaction"></param>
        /// <returns></returns>
        public PartialMerkleTree Trim(params uint256[] matchedTransactions)
        {
            var trimmed = new PartialMerkleTree();

            trimmed.TransactionCount = this.TransactionCount;
            MerkleNode root = GetMerkleRoot();

            foreach (MerkleNode leaf in root.GetLeafs())
            {
                MarkToTop(leaf, false);
            }
            var flags = new BitWriter();

            foreach (MerkleNode leaf in root.GetLeafs().Where(l => matchedTransactions.Contains(l.Hash)))
            {
                MarkToTop(leaf, true);
            }
            trimmed.BuildCore(root, flags);
            trimmed.Flags = flags.ToBitArray();
            return(trimmed);
        }
Esempio n. 6
0
        // Create from a CBlock, filtering transactions according to filter
        // Note that this will call IsRelevantAndUpdate on the filter for each transaction,
        // thus the filter will likely be modified.
        public MerkleBlock(Block block, BloomFilter filter)
        {
            header = block.Header;

            List<bool> vMatch = new List<bool>();
            List<uint256> vHashes = new List<uint256>();

            for(uint i = 0 ; i < block.Transactions.Length ; i++)
            {
                uint256 hash = block.Transactions[i].GetHash();
                if(filter.IsRelevantAndUpdate(block.Transactions[i]))
                {
                    vMatch.Add(true);
                    vMatchedTxn.Add(Tuple.Create(i, hash));
                }
                else
                    vMatch.Add(false);
                vHashes.Add(hash);
            }

            txn = new PartialMerkleTree(vHashes.ToArray(), vMatch.ToArray());
        }
Esempio n. 7
0
		/// <summary>
		/// Remove superflous branches
		/// </summary>
		/// <param name="transaction"></param>
		/// <returns></returns>
		public PartialMerkleTree Trim(params uint256[] matchedTransactions)
		{
			PartialMerkleTree trimmed = new PartialMerkleTree();
			trimmed.TransactionCount = TransactionCount;
			var root = GetMerkleRoot();
			foreach(var leaf in root.GetLeafs())
			{
				MarkToTop(leaf, false);
			}
			BitWriter flags = new BitWriter();
			foreach(var leaf in root.GetLeafs().Where(l => matchedTransactions.Contains(l.Hash)))
			{
				MarkToTop(leaf, true);
			}
			trimmed.BuildCore(root, flags);
			trimmed.Flags = flags.ToBitArray();
			return trimmed;
		}