Esempio n. 1
0
 /// <summary>
 ///     Registers a new standard script template if it does not exist yet based on <see cref="ScriptTemplate.Type" />.
 /// </summary>
 /// <param name="scriptTemplate">The standard script template to register.</param>
 public static void RegisterStandardScriptTemplate(ScriptTemplate scriptTemplate)
 {
     if (!standardTemplates.Any(template => template.Type == scriptTemplate.Type))
     {
         standardTemplates.Add(scriptTemplate);
     }
 }
 /// <summary>
 /// Registers a new standard script template if it does not exist yet based on <see cref="ScriptTemplate.Type"/>.
 /// </summary>
 /// <param name="scriptTemplate">The standard script template to register.</param>
 public virtual void RegisterStandardScriptTemplate(ScriptTemplate scriptTemplate)
 {
     if (!this.GetScriptTemplates.Any(template => (template.Type == scriptTemplate.Type)))
     {
         this.GetScriptTemplates.Add(scriptTemplate);
     }
 }
        private static bool IsStandardScriptSig(Network network, Script scriptSig, Script scriptPubKey)
        {
            ScriptTemplate template = GetTemplateFromScriptPubKey(scriptPubKey);

            if (template == null)
            {
                return(false);
            }

            return(template.CheckScriptSig(network, scriptSig, scriptPubKey));
        }
Esempio n. 4
0
        public bool IsRelevantAndUpdate(Transaction tx)
        {
            if (tx == null)
            {
                throw new ArgumentNullException("tx");
            }
            uint256 hash   = tx.GetHash();
            bool    fFound = false;

            // Match if the filter contains the hash of tx
            //  for finding tx when they appear in a block
            if (this.isFull)
            {
                return(true);
            }
            if (this.isEmpty)
            {
                return(false);
            }
            if (Contains(hash))
            {
                fFound = true;
            }

            for (uint i = 0; i < tx.Outputs.Count; i++)
            {
                TxOut txout = tx.Outputs[(int)i];
                // Match if the filter contains any arbitrary script data element in any scriptPubKey in tx
                // If this matches, also add the specific output that was matched.
                // This means clients don't have to update the filter themselves when a new relevant tx
                // is discovered in order to find spending transactions, which avoids round-tripping and race conditions.
                foreach (Op op in txout.ScriptPubKey.ToOps())
                {
                    if (op.PushData != null && op.PushData.Length != 0 && Contains(op.PushData))
                    {
                        fFound = true;
                        if ((this.nFlags & (byte)BloomFlags.UPDATE_MASK) == (byte)BloomFlags.UPDATE_ALL)
                        {
                            Insert(new OutPoint(hash, i));
                        }
                        else if ((this.nFlags & (byte)BloomFlags.UPDATE_MASK) == (byte)BloomFlags.UPDATE_P2PUBKEY_ONLY)
                        {
                            ScriptTemplate template = StandardScripts.GetTemplateFromScriptPubKey(txout.ScriptPubKey); // this is only valid for Bitcoin.
                            if (template != null &&
                                (template.Type == TxOutType.TX_PUBKEY || template.Type == TxOutType.TX_MULTISIG))
                            {
                                Insert(new OutPoint(hash, i));
                            }
                        }
                        break;
                    }
                }
            }

            if (fFound)
            {
                return(true);
            }

            foreach (TxIn txin in tx.Inputs)
            {
                // Match if the filter contains an outpoint tx spends
                if (Contains(txin.PrevOut))
                {
                    return(true);
                }

                // Match if the filter contains any arbitrary script data element in any scriptSig in tx
                foreach (Op op in txin.ScriptSig.ToOps())
                {
                    if (op.PushData != null && op.PushData.Length != 0 && Contains(op.PushData))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
 /// <summary>
 ///     Registers a new standard script template if it does not exist yet based on <see cref="ScriptTemplate.Type" />.
 /// </summary>
 /// <param name="scriptTemplate">The standard script template to register.</param>
 public virtual void RegisterStandardScriptTemplate(ScriptTemplate scriptTemplate)
 {
     StandardScripts.RegisterStandardScriptTemplate(scriptTemplate);
 }