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(); }
public StealthPayment(int sigCount, PubKey[] spendPubKeys, Key privateKey, PubKey publicKey, StealthMetadata metadata) { Metadata = metadata; if(sigCount == 1 && spendPubKeys.Length == 1) { var template = new PayToPubkeyHashTemplate(); SpendableScript = template.GenerateScriptPubKey(spendPubKeys[0].Uncover(privateKey, publicKey).ID); } else { var template = new PayToMultiSigTemplate(); SpendableScript = template.GenerateScriptPubKey(sigCount, spendPubKeys.Select(p => p.Uncover(privateKey, publicKey)).ToArray()); } ParseSpendable(); }