我需要使用C#NBitcoin中的库在一个简单的事务中添加由一个/两个其他密钥进行的一个或两个签名,以便将已经确认的交易和立即可消耗的交易联网。 我正在使用尚未发布的AltCoin。 我尝试使用指南,但没有成功。 我正在附加代码,以便有人可以帮助我了解如何获得双重签名。
class Examples
{
public static void ConnTest()
{
Network network = NewAltCoin.Instance.Testnet;
using (var node = Node.Connect(network, "127.0.0.1:19999"))
{
node.VersionHandshake();
}
}
public static SendToAddressResp SendToAddress()
{
SendToAddressResp resp = new SendToAddressResp();
Network network = NBitcoin.Altcoins.NewAltCoin.Instance.Testnet;
Transaction tx = new Transaction();
var secret = new BitcoinSecret("cNvAs12345678912345678912345678912345678912349uoECz5");
var pubKey = secret.PubKey.GetAddress(network);
BitcoinSecret Garante = new BitcoinSecret("cNvAs12345678912345678912345678912345678912349JXqiLS");
var pubkeyGarante = Garante.PubKey.GetAddress(network);
var input = new TxIn();
input.PrevOut = new OutPoint(new uint256("e23221afaac8c1285fc8ada3fdbdd9b51810c038c671a0ce9e392514bf2913dd"), 3); //txid e Vout 22.52983203 NewAltCoin
input.ScriptSig = secret.GetAddress().ScriptPubKey;
input.PrevOut = new OutPoint(new uint256("0d772e6a7b1540ad5662aa97dfa4918994182fcdb44e8d8a6d9095cff128e956"), 1); //txid e Vout 100 NewAltCoin del garante
input.ScriptSig = Garante.GetAddress().ScriptPubKey;
tx.AddInput(input);
decimal totaleUTXOs = (decimal)22.52983203;
decimal destCoin = (decimal)1;
decimal fee_ = (decimal)0.0001;
var destination = BitcoinAddress.Create("1234567891234btrKU967htBEMYhRLbAWJ"); //receve address
var refoundSenderAddress = BitcoinAddress.Create(pubKey.ToString());//return extra UTXO address
Money fee = Money.Coins(fee_);
Money dest = Money.Coins(destCoin);
Money refoundUTXO = Money.Coins(totaleUTXOs) - dest - fee;
TxOut dest_ = new TxOut();
dest_.Value = dest;
dest_.ScriptPubKey = destination.ScriptPubKey;
TxOut refoundUTXO_ = new TxOut();
refoundUTXO_.Value = refoundUTXO;
refoundUTXO_.ScriptPubKey = refoundSenderAddress.ScriptPubKey;
tx.AddOutput(dest_);//indirizzo di ricezione soldi
tx.AddOutput(refoundUTXO_);//indirizzo di recupero resti UTXO
var message = "Message";
var bytes = Encoding.UTF8.GetBytes(message);
tx.AddOutput(new TxOut()
{
Value = Money.Zero,
ScriptPubKey = TxNullDataTemplate.Instance.GenerateScriptPubKey(bytes)
});
//*** INSERT HERE MULTISIGN????? HELP ***
tx.Sign(secret, false);
using (var node = Node.Connect(network, "127.0.0.1:19999"))
{
try
{
node.VersionHandshake();
node.SendMessage(new InvPayload(tx));
node.SendMessage(new TxPayload(tx));
string txstr = tx.ToString();
resp = JsonConvert.DeserializeObject<SendToAddressResp>(txstr);
}
catch (Exception Ex)
{
Ex.Message.ToString();
}
}
return;
}
}