| | 1 | | using Microsoft.Extensions.Options; |
| | 2 | | using NBitcoin; |
| | 3 | |
|
| | 4 | | namespace NLightning.Infrastructure.Bitcoin.Factories; |
| | 5 | |
|
| | 6 | | using Domain.Bitcoin.Services; |
| | 7 | | using Domain.Money; |
| | 8 | | using Domain.Node.Options; |
| | 9 | | using Domain.Protocol.Factories; |
| | 10 | | using Transactions; |
| | 11 | | using Network = Domain.ValueObjects.Network; |
| | 12 | |
|
| | 13 | | public class FundingTransactionFactory : IFundingTransactionFactory |
| | 14 | | { |
| | 15 | | private readonly IFeeService _feeService; |
| | 16 | | private readonly NodeOptions _nodeOptions; |
| | 17 | | private readonly Network _network; |
| | 18 | |
|
| 4 | 19 | | public FundingTransactionFactory(IFeeService feeService, IOptions<NodeOptions> nodeOptions) |
| | 20 | | { |
| 4 | 21 | | _feeService = feeService; |
| 4 | 22 | | _nodeOptions = nodeOptions.Value; |
| 4 | 23 | | _network = _nodeOptions.Network; |
| 4 | 24 | | } |
| | 25 | |
|
| | 26 | | public FundingTransaction CreateFundingTransaction(PubKey localFundingPubKey, PubKey remoteFundingPubKey, |
| | 27 | | LightningMoney fundingSatoshis, Script changeScript, |
| | 28 | | Coin[] coins, params BitcoinSecret[] secrets) |
| | 29 | | { |
| 0 | 30 | | var fundingTx = new FundingTransaction(_nodeOptions.DustLimitAmount, _nodeOptions.HasAnchorOutputs, |
| 0 | 31 | | _network, localFundingPubKey, remoteFundingPubKey, |
| 0 | 32 | | fundingSatoshis, changeScript, coins); |
| | 33 | |
|
| 0 | 34 | | fundingTx.ConstructTransaction(_feeService.GetCachedFeeRatePerKw()); |
| | 35 | |
|
| 0 | 36 | | fundingTx.SignTransaction(secrets); |
| | 37 | |
|
| 0 | 38 | | return fundingTx; |
| | 39 | | } |
| | 40 | |
|
| | 41 | | public FundingTransaction CreateFundingTransaction(PubKey localFundingPubKey, PubKey remoteFundingPubKey, |
| | 42 | | LightningMoney fundingSatoshis, Script redeemScript, |
| | 43 | | Script changeScript, Coin[] coins, |
| | 44 | | params BitcoinSecret[] secrets) |
| | 45 | | { |
| 4 | 46 | | var fundingTx = new FundingTransaction(_nodeOptions.DustLimitAmount, _nodeOptions.HasAnchorOutputs, |
| 4 | 47 | | _network, localFundingPubKey, remoteFundingPubKey, |
| 4 | 48 | | fundingSatoshis, redeemScript, changeScript, coins); |
| | 49 | |
|
| 4 | 50 | | fundingTx.ConstructTransaction(_feeService.GetCachedFeeRatePerKw()); |
| | 51 | |
|
| 4 | 52 | | fundingTx.SignTransaction(secrets); |
| | 53 | |
|
| 4 | 54 | | return fundingTx; |
| | 55 | | } |
| | 56 | | } |