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());
        }
Example #2
0
        /// <summary>
        /// Builds the extended filter for a given block.
        ///
        /// The extended filter contains extra data that is meant to enable applications with more advanced smart contracts.
        /// An extended filter MUST contain exactly the following items for each transaction in a block except the coinbase:
        ///  * Each item within the witness stack of each input (if the input has a witness)
        ///  * Each data push in the scriptSig of each input
        /// </summary>
        /// <param name="block">The block used for building the filter.</param>
        /// <returns>The extended filter for the block.</returns>
        public static GolombRiceFilter BuildExtendedFilter(Block block)
        {
            var builder = new GolombRiceFilterBuilder()
                          .SetKey(block.GetHash());

            foreach (var tx in block.Transactions)
            {
                if (!tx.IsCoinBase)                // except the coinbase
                {
                    foreach (var txin in tx.Inputs)
                    {
                        if (txin.ScriptSig != Script.Empty)
                        {
                            // Each data push in the scriptSig of each input
                            builder.AddScriptSig(txin.ScriptSig);
                        }

                        if (txin.WitScript != WitScript.Empty)
                        {
                            // Each item within the witness stack of each input (if the input has a witness)
                            builder.AddWitness(txin.WitScript);
                        }
                    }
                }
            }

            return(builder.Build());
        }