本文整理汇总了C#中Script.IsPayToScriptHash方法的典型用法代码示例。如果您正苦于以下问题:C# Script.IsPayToScriptHash方法的具体用法?C# Script.IsPayToScriptHash怎么用?C# Script.IsPayToScriptHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Script
的用法示例。
在下文中一共展示了Script.IsPayToScriptHash方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
public static bool Validate(this Transaction tx, Dictionary<TxOutId, TxOut> prevOuts)
{
for (uint i = 0; i < tx.inputs.Length; i++)
{
TxIn txin = tx.inputs[i];
Script scriptSig = new Script(txin.scriptSig);
Script scriptPubKey = new Script(prevOuts[new TxOutId(txin.prevOut, txin.prevOutIndex)].scriptPubKey);
Script s = new Script(scriptSig, scriptPubKey);
if (!s.Evaluate(tx, i))
return false;
if (scriptPubKey.IsPayToScriptHash() &&
scriptSig.elements.Count == 2)
{
Script serializedScript = new Script(scriptSig.elements[1].data);
scriptSig.elements.RemoveAt(1);
s = new Script(scriptSig, serializedScript);
if (!s.Evaluate(tx, i))
return false;
}
}
return true;
}
示例2: Sign
public static void Sign(this TxIn txin, Transaction tx, TxOut prevOut, PrivateKey key, HashType hashType = HashType.SIGHASH_ALL, Script redeemScript = null)
{
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);
//// Still don't fully handle codeseperator, but we remove them all as in the spec.
//// Might be all we need to do, scriptSig will never contain OP_CODESEPERATOR since we are creating it.
////subScript.elements.RemoveAll(x => x.opCode == OpCode.OP_CODESEPARATOR);
// Actually, those would be nonstandard anyway
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));
Script s = new Script();
if (subScript.IsPayToScriptHash())
{
if (redeemScript == null)
throw new ArgumentNullException("P2SH transaction requires serialied script");
s.elements.Add(new ScriptElement(redeemScript.ToBytes()));
subScript = redeemScript;
}
if (subScript.IsPayToPubKeyHash())
{
Byte[] sig = key.Sign(txHash).Concat(new Byte[] { (Byte)hashType }).ToArray();
s.elements.Insert(0, new ScriptElement(sig));
s.elements.Insert(1, new ScriptElement(key.pubKey.ToBytes()));
}
else if (subScript.IsPayToPublicKey())
{
Byte[] sig = key.Sign(txHash).Concat(new Byte[] { (Byte)hashType }).ToArray();
s.elements.Insert(0, new ScriptElement(sig));
}
else if (subScript.IsPayToMultiSig())
{
Script scriptSig = new Script(txin.scriptSig);
if (scriptSig.elements.Count == 0)
scriptSig.elements.Add(new ScriptElement(OpCode.OP_0));
Byte[] sig = key.Sign(txHash).Concat(new Byte[] { (Byte)hashType }).ToArray();
s.elements.Insert(0, new ScriptElement(sig));
}
else
{
throw new ArgumentException("Unrecognized TxOut Script");
}
txin.scriptSig = s.ToBytes();
}
示例3: 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;
}