Commit 1425e56c authored by Sergei Zubov's avatar Sergei Zubov

Modify fee calculations for tx building

parent a4623f5a
...@@ -110,5 +110,14 @@ namespace Stratis.Bitcoin.Features.Wallet ...@@ -110,5 +110,14 @@ namespace Stratis.Bitcoin.Features.Wallet
return newAddress; return newAddress;
} }
public IEnumerable<string> GetOwnAddresses(WalletAccountReference accountReference)
{
return GetAccounts(accountReference.WalletName)
.Single(q => q.Name == accountReference.AccountName).ExternalAddresses
.Select(q => q.Address).Concat(GetAccounts(accountReference.WalletName)
.Single(q => q.Name == accountReference.AccountName).InternalAddresses
.Select(q => q.Address));
}
} }
} }
\ No newline at end of file
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security; using System.Security;
...@@ -33,7 +33,10 @@ namespace Stratis.Bitcoin.Features.Wallet ...@@ -33,7 +33,10 @@ namespace Stratis.Bitcoin.Features.Wallet
/// <inheritdoc /> /// <inheritdoc />
protected override void AddFee(TransactionBuildContext context) protected override void AddFee(TransactionBuildContext context)
{ {
long fee = Convert.ToInt64(context.Recipients.Sum(p => p.Amount) * this.DeStreamNetwork.FeeRate); var fundTransfers = context.Recipients.Where(p => !(this.walletManager as IDeStreamWalletManager).GetOwnAddresses(context.AccountReference)
.Contains(p.ScriptPubKey.GetDestinationAddress(this.network).ToString()));
long fee = Convert.ToInt64(fundTransfers.Sum(p => p.Amount) * this.DeStreamNetwork.FeeRate);
context.TransactionFee = fee; context.TransactionFee = fee;
context.TransactionBuilder.SendFees(fee); context.TransactionBuilder.SendFees(fee);
} }
......
namespace Stratis.Bitcoin.Features.Wallet.Interfaces using System.Collections.Generic;
namespace Stratis.Bitcoin.Features.Wallet.Interfaces
{ {
public interface IDeStreamWalletManager : IWalletManager public interface IDeStreamWalletManager : IWalletManager
{ {
...@@ -8,5 +10,7 @@ ...@@ -8,5 +10,7 @@
void ProcessGenesisBlock(); void ProcessGenesisBlock();
HdAddress CreateAddress(WalletAccountReference accountReference); HdAddress CreateAddress(WalletAccountReference accountReference);
IEnumerable<string> GetOwnAddresses(WalletAccountReference accountReference);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment