Пример #1
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(nameof(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());
        }
Пример #2
0
 public StealthSpendKey(KeyId id, StealthPayment payment)
 {
     _ID      = id;
     _Payment = payment;
 }
 /// <summary>
 /// Scan the Transaction for StealthCoin given address and scan key
 /// </summary>
 /// <param name="tx">The transaction to scan</param>
 /// <param name="address">The stealth address</param>
 /// <param name="scan">The scan private key</param>
 /// <returns></returns>
 public StealthPayment[] GetPayments(Transaction transaction, Key scanKey)
 {
     return(StealthPayment.GetPayments(transaction, this, scanKey));
 }
 public StealthPayment[] GetPayments(Transaction transaction)
 {
     return(StealthPayment.GetPayments(transaction, null, null).Where(p => this.Match(p.Metadata)).ToArray());
 }