本文整理匯總了C#中System.Script.SignatureHash方法的典型用法代碼示例。如果您正苦於以下問題:C# Script.SignatureHash方法的具體用法?C# Script.SignatureHash怎麽用?C# Script.SignatureHash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Script
的用法示例。
在下文中一共展示了Script.SignatureHash方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: sighash_from_data
public void sighash_from_data()
{
var tests = TestCase.read_json("Data/sighash.json");
foreach(var test in tests)
{
var strTest = test.ToString();
if(test.Count < 1) // Allow for extra stuff (useful for comments)
{
Assert.True(false, "Bad test: " + strTest);
continue;
}
if(test.Count == 1)
continue; // comment
string raw_tx, raw_script, sigHashHex;
int nIn, nHashType;
Transaction tx = new Transaction();
Script scriptCode = new Script();
// deserialize test data
raw_tx = (string)test[0];
raw_script = (string)test[1];
nIn = (int)(long)test[2];
nHashType = (int)(long)test[3];
sigHashHex = (string)test[4];
tx.ReadWrite(ParseHex(raw_tx));
ValidationState state = Network.Main.CreateValidationState();
Assert.True(state.CheckTransaction(tx), strTest);
Assert.True(state.IsValid);
var raw = ParseHex(raw_script);
scriptCode = new Script(raw);
var sh = scriptCode.SignatureHash(tx, nIn, (SigHash)nHashType);
Assert.True(sh.GetHex() == sigHashHex, strTest);
}
}
示例2: sign_multisig
Script sign_multisig(Script scriptPubKey, Key[] keys, Transaction transaction)
{
uint256 hash = scriptPubKey.SignatureHash(transaction, 0, SigHash.All);
List<Op> ops = new List<Op>();
//CScript result;
//
// NOTE: CHECKMULTISIG has an unfortunate bug; it requires
// one extra item on the stack, before the signatures.
// Putting OP_0 on the stack is the workaround;
// fixing the bug would mean splitting the block chain (old
// clients would not accept new CHECKMULTISIG transactions,
// and vice-versa)
//
ops.Add(OpcodeType.OP_0);
foreach(Key key in keys)
{
var vchSig = key.Sign(hash).ToDER().ToList();
vchSig.Add((byte)SigHash.All);
ops.Add(Op.GetPushOp(vchSig.ToArray()));
}
return new Script(ops.ToArray());
}