当前位置: 首页>>代码示例>>C#>>正文


C# Script.SignatureHash方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:40,代码来源:sighash_tests.cs

示例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());
		}
开发者ID:vebin,项目名称:NBitcoin,代码行数:23,代码来源:script_tests.cs


注:本文中的System.Script.SignatureHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。