當前位置: 首頁>>代碼示例>>C#>>正文


C# Transaction.Sign方法代碼示例

本文整理匯總了C#中NBitcoin.Transaction.Sign方法的典型用法代碼示例。如果您正苦於以下問題:C# Transaction.Sign方法的具體用法?C# Transaction.Sign怎麽用?C# Transaction.Sign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NBitcoin.Transaction的用法示例。


在下文中一共展示了Transaction.Sign方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Pay

        public static void Pay(BitcoinSecret secret, BitcoinAddress toAddress, Money amount, Transaction fundingTransaction)
        {
            var fee = Money.Coins(0.0001m);

            Transaction payment = new Transaction();
            payment.Inputs.Add(new TxIn()
                {
                    PrevOut = new OutPoint(fundingTransaction.GetHash(), 1)
                });

            payment.Outputs.Add(new TxOut()
                {
                    Value = amount,
                    ScriptPubKey = toAddress.ScriptPubKey
                });

            var output = fundingTransaction.Outputs[0];
            var change = output.Value - amount - fee;
            if (change < 0)
            {
                Console.WriteLine("There is not enough BTC in the funding transaction ({0}) to make this payment ({1})", output.Value, amount);
                Console.WriteLine("No payment being sent");
                return;
            }

            payment.Outputs.Add(new TxOut()
                {
                    Value = output.Value - amount - fee,
                    ScriptPubKey = output.ScriptPubKey
                });

            //Feedback !
            var message = "Thanks ! :)";
            var bytes = Encoding.UTF8.GetBytes(message);
            payment.Outputs.Add(new TxOut()
                {
                    Value = Money.Zero,
                    ScriptPubKey = TxNullDataTemplate.Instance.GenerateScriptPubKey(bytes)
                });

            Console.WriteLine(payment);

            payment.Inputs[0].ScriptSig = fundingTransaction.Outputs[1].ScriptPubKey;
            payment.Sign(secret, false);

            using (var node = Node.Connect(Network.Main))
            {
                Console.WriteLine("Doing version handshake");
                node.VersionHandshake();
                Console.WriteLine("Sending message");
                node.SendMessage(new InvPayload(InventoryType.MSG_TX, payment.GetHash()));
                node.SendMessage(new TxPayload(payment));
                Thread.Sleep(500);
            }
        }
開發者ID:daveremy,項目名稱:ProgrammingBlockchain,代碼行數:55,代碼來源:Program.cs


注:本文中的NBitcoin.Transaction.Sign方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。