Ejemplo n.º 1
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 ; 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();
        }
Ejemplo n.º 2
0
 public static StealthMetadata CreateMetadata(Key ephemKey, BitField bitField = null)
 {
     for(uint nonce = 0 ; nonce < uint.MaxValue ; nonce++)
     {
         var metadata = new StealthMetadata(ephemKey, nonce);
         if(bitField == null || bitField.Match(metadata.BitField))
             return metadata;
     }
     throw new ArgumentException("No nonce can satisfy the given bitfield, use another ephemKey");
 }
Ejemplo n.º 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());
        }