コード例 #1
0
ファイル: StealthPayment.cs プロジェクト: nikropht/NBitcoin
        public static StealthPayment[] GetPayments(Transaction transaction, PubKey[] spendKeys, BitField bitField, Key scan)
        {
            List<StealthPayment> result = new List<StealthPayment>();
            for(int i = 0 ; i < transaction.Outputs.Count ; i++)
            {
                var metadata = StealthMetadata.TryParse(transaction.Outputs[i].ScriptPubKey);
                if(metadata != null && bitField.Match(metadata.BitField))
                {
                    var payment = new StealthPayment(transaction.Outputs[i + 1].ScriptPubKey, metadata);
                    if(scan != null && spendKeys != null)
                    {
                        if(payment.StealthKeys.Length != spendKeys.Length)
                            continue;

                        var expectedStealth = spendKeys.Select(s => s.UncoverReceiver(scan, metadata.EphemKey)).ToList();
                        foreach(var stealth in payment.StealthKeys)
                        {
                            var match = expectedStealth.FirstOrDefault(expected => expected.ID == stealth.ID);
                            if(match != null)
                                expectedStealth.Remove(match);
                        }
                        if(expectedStealth.Count != 0)
                            continue;
                    }
                    result.Add(payment);
                }
            }
            return result.ToArray();
        }
コード例 #2
0
        /// <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 static StealthCoin Find(Transaction tx, BitcoinStealthAddress address, Key scan)
        {
            StealthPayment payment = address.GetPayments(tx, scan).FirstOrDefault();

            if (payment == null)
            {
                return(null);
            }
            uint256 txId  = tx.GetHash();
            TxOut   txout = tx.Outputs.First(o => o.ScriptPubKey == payment.ScriptPubKey);

            return(new StealthCoin(new OutPoint(txId, tx.Outputs.IndexOf(txout)), txout, payment.Redeem, payment.Metadata, address));
        }
コード例 #3
0
        public static StealthPayment[] GetPayments(Transaction transaction, PubKey[] spendKeys, BitField bitField, 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 && bitField.Match(metadata.BitField))
                {
                    var payment = new StealthPayment(transaction.Outputs[i + 1].ScriptPubKey, metadata);
                    if (scan != null && spendKeys != null)
                    {
                        if (payment.StealthKeys.Length != spendKeys.Length)
                        {
                            continue;
                        }

                        var expectedStealth = spendKeys.Select(s => s.UncoverReceiver(scan, metadata.EphemKey)).ToList();
                        foreach (var stealth in payment.StealthKeys)
                        {
                            var match = expectedStealth.FirstOrDefault(expected => expected.ID == stealth.ID);
                            if (match != null)
                            {
                                expectedStealth.Remove(match);
                            }
                        }
                        if (expectedStealth.Count != 0)
                        {
                            continue;
                        }
                    }
                    result.Add(payment);
                }
            }
            return(result.ToArray());
        }
コード例 #4
0
 public StealthSpendKey(KeyId id, StealthPayment payment)
 {
     _ID      = id;
     _Payment = payment;
 }
コード例 #5
0
ファイル: StealthPayment.cs プロジェクト: nikropht/NBitcoin
 public StealthSpendKey(KeyId id, StealthPayment payment)
 {
     _ID = id;
     _Payment = payment;
 }
コード例 #6
0
 public StealthPayment[] GetPayments(Transaction transaction, Key scanKey)
 {
     return(StealthPayment.GetPayments(transaction, SpendPubKeys, Prefix, scanKey));
 }
コード例 #7
0
 public StealthPayment[] GetPayments(Transaction transaction)
 {
     return(StealthPayment.GetPayments(transaction, null, this, null));
 }