本文整理匯總了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;
}