本文整理汇总了C#中Script.IsPayToAddress方法的典型用法代码示例。如果您正苦于以下问题:C# Script.IsPayToAddress方法的具体用法?C# Script.IsPayToAddress怎么用?C# Script.IsPayToAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Script
的用法示例。
在下文中一共展示了Script.IsPayToAddress方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Sign
public static void Sign(this TxIn txin, Transaction tx, TxOut prevOut, PrivateKey key, HashType hashType = HashType.SIGHASH_ALL)
{
SHA256 sha256 = new SHA256Managed();
UInt32 txInIndex;
for (txInIndex = 0; txInIndex < tx.inputs.Length; txInIndex++)
{
if (TxIn.ReferenceEquals(txin, tx.inputs[txInIndex]))
break;
}
if (txInIndex == tx.inputs.Length)
throw new ArgumentException("Input not part of transaction.");
// Only know how to sign if output does not contain OP_CODESEPERATOR for now.
Script subScript = new Script(prevOut.scriptPubKey);
Transaction txCopy = tx.CopyForSigning(txInIndex, subScript, hashType);
Byte[] txHash = txCopy.ToBytes().Concat(new Byte[] { (Byte)hashType, 0x00, 0x00, 0x00 }).ToArray();
txHash = sha256.ComputeHash(sha256.ComputeHash(txHash));
Byte[] sig = key.Sign(txHash);
sig = sig.Concat(new Byte[] { (Byte)hashType }).ToArray();
Script s = new Script();
if (subScript.IsPayToAddress())
{
s.elements.Add(new ScriptElement(sig));
s.elements.Add(new ScriptElement(key.pubKey.ToBytes()));
}
else if (subScript.IsPayToPublicKey())
{
s.elements.Add(new ScriptElement(sig));
}
else
{
throw new ArgumentException("Unrecognized TxOut Script");
}
txin.scriptSig = s.ToBytes();
}
示例2: FromScript
public static Address FromScript(Byte[] b)
{
Script s = new Script(b);
if (s.IsPayToAddress())
return new Address(s.elements[s.elements.Count - 3].data, PUBKEYHASH);
if (s.IsPayToScriptHash())
return new Address(s.elements[s.elements.Count - 2].data, SCRIPTHASH);
if (s.IsPayToPublicKey())
return new Address(s.elements[s.elements.Count - 2].data, PUBKEY);
return null;
}