public void Sign(Key privateKey, ITxOutput spentOutput) { var output = (BitcoinBasedTxOutput)spentOutput; var currency = (BitcoinBasedCurrency)Currency; Tx.Sign(new BitcoinSecret(privateKey, currency.Network), output.Coin); }
public void Sign( Key privateKey, ITxOutput spentOutput) { var output = (BitcoinBasedTxOutput)spentOutput; Tx.Sign(privateKey, output.Coin); }
public void Sign( Key privateKey, ITxOutput spentOutput, BitcoinBasedConfig bitcoinBasedConfig) { var output = (BitcoinBasedTxOutput)spentOutput; Tx.Sign(new BitcoinSecret(privateKey, bitcoinBasedConfig.Network), output.Coin); }
public KeyTx(SpendTx spend, ExtKey spendKey, ExtKey changeKey, Money minerFee) { Spend = spend; MinerFee = minerFee; PaymentAddress = spendKey.PrivateKey.GetWif(Spend.Api.Network).GetAddress(ScriptPubKeyType.Legacy).ToString(); Tx = Transaction.Create(Spend.Api.Network); var ReceiverAddress = BitcoinAddress.Create(Spend.ToAddress, Spend.Api.Network); Tx.Outputs.Add(SpendAmount, ReceiverAddress.ScriptPubKey); Tx.Outputs.Add(ChangeAmount, changeKey.PrivateKey.GetWif(Spend.Api.Network).GetAddress(ScriptPubKeyType.Legacy).ScriptPubKey); if (Spend.TxMessage.Length > 0) { Tx.Outputs.Add(Money.Zero, TxNullDataTemplate.Instance.GenerateScriptPubKey(Encoding.UTF8.GetBytes(Spend.TxMessage))); } GetTransactions(spendKey); List <TxId> inputs = new List <TxId>(); foreach (var txId in TxIds) { if (!AddTransaction(spendKey, txId)) { continue; } else { inputs.Add(txId); } var totalSpend = Spend.SpendAmount + TxInAmount - MinerFee; var remainingAmount = Spend.TargetAmount - totalSpend; SpendAmount = remainingAmount > Money.Zero ? TxInAmount - MinerFee : TxInAmount - MinerFee + remainingAmount; ChangeAmount = TxInAmount - SpendAmount - MinerFee; if (Spend.TargetAmount <= (Spend.TxInAmount + TxInAmount - Spend.MinerFee - MinerFee)) { break; } } List <TxId> unusedTx = TxIds.Where(tx => !inputs.Contains(tx)).ToList(); foreach (var tx in unusedTx) { TxIds.Remove(tx); } Tx.Outputs.Clear(); Tx.Outputs.Add(SpendAmount, ReceiverAddress.ScriptPubKey); if (ChangeAmount > Money.Zero) { Tx.Outputs.Add(ChangeAmount, changeKey.PrivateKey.GetWif(Spend.Api.Network).GetAddress(ScriptPubKeyType.Legacy).ScriptPubKey); } if (Spend.TxMessage.Length > 0) { Tx.Outputs.Add(Money.Zero, TxNullDataTemplate.Instance.GenerateScriptPubKey(Encoding.UTF8.GetBytes(Spend.TxMessage))); } Tx.Sign(spendKey.PrivateKey.GetBitcoinSecret(Spend.Api.Network), coins.ToArray()); }