Example #1
0
        /// <summary>
        /// Builds the basic filter for a given block.
        ///
        /// The basic filter is designed to contain everything that a light client needs to sync a regular Bitcoin wallet.
        /// A basic filter MUST contain exactly the following items for each transaction in a block:
        ///  * The outpoint of each input, except for the coinbase transaction
        ///  * The scriptPubKey of each output
        ///  * The txid of the transaction itself
        /// </summary>
        /// <param name="block">The block used for building the filter.</param>
        /// <returns>The basic filter for the block.</returns>
        public static GolombRiceFilter BuildBasicFilter(Block block)
        {
            var builder = new GolombRiceFilterBuilder()
                          .SetKey(block.GetHash());

            foreach (var tx in block.Transactions)
            {
                if (!tx.IsCoinBase)                // except for the coinbase transaction
                {
                    foreach (var txin in tx.Inputs)
                    {
                        // The outpoint of each input
                        builder.AddOutPoint(txin.PrevOut);
                    }
                }

                foreach (var txout in tx.Outputs)
                {
                    // The scriptPubKey of each output
                    builder.AddScriptPubkey(txout.ScriptPubKey);
                }
            }

            return(builder.Build());
        }