本文整理汇总了C#中NBitcoin.Transaction.ToHex方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.ToHex方法的具体用法?C# Transaction.ToHex怎么用?C# Transaction.ToHex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBitcoin.Transaction
的用法示例。
在下文中一共展示了Transaction.ToHex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHexSignedTransaction
public static string GetHexSignedTransaction(TransactionToSign txToSign)
{
var walletPrivateKey = ConfigurationManager.AppSettings[METACO_ENV_WALLET_PRIVATE_KEY_HEX_NAME];
var key = new Key(Encoders.Hex.DecodeData(walletPrivateKey));
var scriptPubKey = PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(key.PubKey);
var tx = new Transaction(Encoders.Hex.DecodeData(txToSign.Raw));
foreach(var inputsToSign in txToSign.InputsToSign)
{
var sigHash = tx.GetSignatureHash(scriptPubKey, inputsToSign.Index);
var sig = key.Sign(sigHash);
var txSign = new TransactionSignature(sig, SigHash.All);
var inputScript = PayToPubkeyHashTemplate.Instance.GenerateScriptSig(txSign, key.PubKey);
tx.Inputs[inputsToSign.Index].ScriptSig = inputScript;
Assert.True(Script.VerifyScript(scriptPubKey, tx, inputsToSign.Index));
}
return tx.ToHex();
}
示例2: Submit
public static String Submit(Transaction tx)
{
//Info.Blockchain.API.PushTx.PushTx bcInfo = new Info.Blockchain.API.PushTx.PushTx();
//http://btc.blockr.io/api/v1/tx/push
var cli = new WebClient();
cli.Headers[HttpRequestHeader.ContentType] = "application/json";
RawTx t = new RawTx();
t.hex = tx.ToHex();
String json = Newtonsoft.Json.JsonConvert.SerializeObject(t);
String response = cli.UploadString("http://tbtc.blockr.io/api/v1/tx/push", json);
//IList<String> nodes = new List<String>(3);
//nodes.Add("54.149.133.4:18333");
////SOME TEST NET NODES
////54.149.133.4:18333
////52.69.206.155:18333
////93.114.160.222:18333
//string url = "93.114.160.222:18333"; //nic
////url = "52.4.156.236:18333";
////string url = "54.149.133.4:18333";
//using (var node = NBitcoin.Protocol.Node.ConnectToLocal(NBitcoin.Network.TestNet))
//{
// node.VersionHandshake();
// NBitcoin.Transaction[] transactions = new Transaction[1];
// transactions[0] = tx;
// node.SendMessage(new NBitcoin.Protocol.InvPayload(transactions));
// node.SendMessage(new NBitcoin.Protocol.TxPayload(tx));
//}
//using(var node = NBitcoin.Protocol.Node.Connect(NBitcoin.Network.TestNet, url))
//{
// node.VersionHandshake();
// System.Threading.Thread.Sleep(100);
// NBitcoin.Transaction[] transactions = new Transaction[1];
// transactions[0] = tx;
// node.SendMessage(new NBitcoin.Protocol.InvPayload(transactions));
// node.SendMessage(new NBitcoin.Protocol.TxPayload(tx));
//}
var r = Newtonsoft.Json.JsonConvert.DeserializeObject<Response>(response);
return r.data;
}