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(); }
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()); }
public static Script CreatePaymentScript(BitcoinStealthAddress address, PubKey ephemKey, Key scan) { return(CreatePaymentScript(address.SignatureCount, address.SpendPubKeys.Select(p => p.UncoverReceiver(scan, ephemKey)).ToArray())); }