コード例 #1
0
        public StealthPayment(BitcoinStealthAddress address, Key ephemKey, StealthMetadata metadata)
        {
            Metadata     = metadata;
            ScriptPubKey = CreatePaymentScript(address.SignatureCount, address.SpendPubKeys, ephemKey, address.ScanPubKey);

            if (address.SignatureCount > 1)
            {
                Redeem       = ScriptPubKey;
                ScriptPubKey = ScriptPubKey.Hash.ScriptPubKey;
            }
            SetStealthKeys();
        }
コード例 #2
0
        public static StealthPayment[] GetPayments(Transaction transaction, BitcoinStealthAddress address, Key scan)
        {
            List <StealthPayment> result = new List <StealthPayment>();

            for (int i = 0; i < transaction.Outputs.Count - 1; i++)
            {
                var metadata = StealthMetadata.TryParse(transaction.Outputs[i].ScriptPubKey);
                if (metadata != null && (address == null || address.Prefix.Match(metadata.BitField)))
                {
                    var    scriptPubKey         = transaction.Outputs[i + 1].ScriptPubKey;
                    var    scriptId             = PayToScriptHashTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey);
                    Script expectedScriptPubKey = address == null ? scriptPubKey : null;
                    Script redeem = null;

                    if (scriptId != null)
                    {
                        if (address == null)
                        {
                            throw new ArgumentNullException("address");
                        }
                        redeem = CreatePaymentScript(address, metadata.EphemKey, scan);
                        expectedScriptPubKey = redeem.Hash.ScriptPubKey;
                        if (expectedScriptPubKey != scriptPubKey)
                        {
                            continue;
                        }
                    }

                    var payment = new StealthPayment(scriptPubKey, redeem, metadata);
                    if (scan != null)
                    {
                        if (address != null && payment.StealthKeys.Length != address.SpendPubKeys.Length)
                        {
                            continue;
                        }

                        if (expectedScriptPubKey == null)
                        {
                            expectedScriptPubKey = CreatePaymentScript(address, metadata.EphemKey, scan);
                        }

                        if (expectedScriptPubKey != scriptPubKey)
                        {
                            continue;
                        }
                    }
                    result.Add(payment);
                }
            }
            return(result.ToArray());
        }
コード例 #3
0
 public static Script CreatePaymentScript(BitcoinStealthAddress address, PubKey ephemKey, Key scan)
 {
     return(CreatePaymentScript(address.SignatureCount, address.SpendPubKeys.Select(p => p.UncoverReceiver(scan, ephemKey)).ToArray()));
 }