Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into merge692
Browse files Browse the repository at this point in the history
  • Loading branch information
fassadlr committed Sep 2, 2021
2 parents 70a38fd + 139daf1 commit 393eec8
Show file tree
Hide file tree
Showing 63 changed files with 397 additions and 111 deletions.
2 changes: 1 addition & 1 deletion src/FederationSetup/FederationSetup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/FodyNlogAdapter/FodyNlogAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>FodyNlogAdapter</AssemblyName>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
<PackageId>Stratis.Utils.FodyNlogAdapter</PackageId>
Expand Down
6 changes: 5 additions & 1 deletion src/NBitcoin/ChainStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace NBitcoin
{
public interface IChainStore
public interface IChainStore : IDisposable
{
BlockHeader GetHeader(ChainedHeader chainedHeader, uint256 hash);

Expand Down Expand Up @@ -90,5 +90,9 @@ public void PutChainData(IEnumerable<ChainDataItem> items)
foreach (ChainDataItem item in items)
this.chainData.TryAdd(item.Height, item.Data);
}

public void Dispose()
{
}
}
}
2 changes: 1 addition & 1 deletion src/NBitcoin/NBitcoin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>4.0.0.82</Version>
<Version>4.0.0.83</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
18 changes: 13 additions & 5 deletions src/Stratis.Bitcoin.Api.Tests/ApiSettingsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ namespace Stratis.Bitcoin.Api.Tests
/// <summary>
/// Tests the settings for the API features.
/// </summary>
public class ApiSettingsTest : TestBase
public class ApiSettingsTest : TestBase, IDisposable
{
private IFullNode fullNode;

public ApiSettingsTest() : base(KnownNetworks.Main)
{
}
Expand Down Expand Up @@ -266,14 +268,20 @@ public void GivenUseHttpsAndNoCertificateFilePath_ThenShouldThrowConfigurationEx
settingsAction.Should().Throw<ConfigurationException>();
}

private static ApiSettings FullNodeSetup(NodeSettings nodeSettings)
private ApiSettings FullNodeSetup(NodeSettings nodeSettings)
{
return new FullNodeBuilder()
this.fullNode = new FullNodeBuilder()
.UseNodeSettings(nodeSettings)
.UseApi()
.UsePowConsensus()
.Build()
.NodeService<ApiSettings>();
.Build();

return this.fullNode.NodeService<ApiSettings>();
}

public void Dispose()
{
this.fullNode.NodeService<IChainStore>().Dispose();
}
}
}
2 changes: 1 addition & 1 deletion src/Stratis.Bitcoin.Cli/Stratis.Bitcoin.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<Authors>Stratis Group Ltd.</Authors>
<Company>Stratis Group Ltd.</Company>
<Product />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AssemblyName>Stratis.Bitcoin.Features.Api</AssemblyName>
<OutputType>Library</OutputType>
<PackageId>Stratis.Features.Api</PackageId>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<ApplicationIcon />
<OutputTypeEx>library</OutputTypeEx>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,11 @@ private void Initialize([System.Runtime.CompilerServices.CallerMemberName] strin
this.loggerFactory, DateTimeProvider.Default, walletRepository);

var reserveUtxoService = new ReserveUtxoService(this.loggerFactory, new Mock<ISignals>().Object);
var walletFeePolicy = new Mock<IWalletFeePolicy>().Object;
var broadcasterManager = new Mock<IBroadcasterManager>().Object;
var walletTransactionHandler = new WalletTransactionHandler(this.loggerFactory, this.coldStakingManager, walletFeePolicy, this.Network, new StandardTransactionPolicy(this.Network), reserveUtxoService);

var walletTransactionHandler = new WalletTransactionHandler(this.loggerFactory, this.coldStakingManager, new Mock<IWalletFeePolicy>().Object, this.Network, new StandardTransactionPolicy(this.Network), reserveUtxoService);

this.coldStakingController = new ColdStakingController(this.loggerFactory, this.coldStakingManager, walletTransactionHandler);
this.coldStakingController = new ColdStakingController(this.loggerFactory, this.coldStakingManager, walletTransactionHandler, walletFeePolicy, broadcasterManager);

this.asyncProvider = new AsyncProvider(this.loggerFactory, new Mock<ISignals>().Object);

Expand Down
46 changes: 46 additions & 0 deletions src/Stratis.Bitcoin.Features.ColdStaking/ColdStakingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -692,5 +692,51 @@ public IEnumerable<UnspentOutputReference> GetSpendableTransactionsInColdWallet(
this.logger.LogTrace("(-):*.Count={0}", res.Count());
return res;
}

public List<Transaction> RetrieveFilteredUtxos(string walletName, string walletPassword, string transactionHex, FeeRate feeRate, string walletAccount = null)
{
var retrievalTransactions = new List<Transaction>();

Transaction transactionToReclaim = this.network.Consensus.ConsensusFactory.CreateTransaction(transactionHex);

foreach (TxOut output in transactionToReclaim.Outputs)
{
Wallet.Wallet wallet = this.GetWallet(walletName);

HdAddress address = wallet.GetAllAddresses(Wallet.Wallet.AllAccounts).FirstOrDefault(a => a.ScriptPubKey == output.ScriptPubKey);

// The address is not in the wallet so ignore this output.
if (address == null)
continue;

HdAccount destinationAccount = wallet.GetAccounts(Wallet.Wallet.NormalAccounts).First();

// This shouldn't really happen unless the user has no proper accounts in the wallet.
if (destinationAccount == null)
continue;

Script destination = destinationAccount.GetFirstUnusedReceivingAddress().ScriptPubKey;

ISecret extendedPrivateKey = wallet.GetExtendedPrivateKeyForAddress(walletPassword, address);

Key privateKey = extendedPrivateKey.PrivateKey;

var builder = new TransactionBuilder(this.network);

var coin = new Coin(transactionToReclaim, output);

builder.AddCoins(coin);
builder.AddKeys(privateKey);
builder.Send(destination, output.Value);
builder.SubtractFees();
builder.SendEstimatedFees(feeRate);

Transaction builtTransaction = builder.BuildTransaction(true);

retrievalTransactions.Add(builtTransaction);
}

return retrievalTransactions;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,33 @@ namespace Stratis.Bitcoin.Features.ColdStaking.Controllers
public class ColdStakingController : Controller
{
public ColdStakingManager ColdStakingManager { get; private set; }

private readonly IWalletTransactionHandler walletTransactionHandler;
private readonly IWalletFeePolicy walletFeePolicy;
private readonly IBroadcasterManager broadcasterManager;

/// <summary>Instance logger.</summary>
private readonly ILogger logger;

public ColdStakingController(
ILoggerFactory loggerFactory,
IWalletManager walletManager,
IWalletTransactionHandler walletTransactionHandler)
IWalletTransactionHandler walletTransactionHandler,
IWalletFeePolicy walletFeePolicy,
IBroadcasterManager broadcasterManager)
{
Guard.NotNull(loggerFactory, nameof(loggerFactory));
Guard.NotNull(walletManager, nameof(walletManager));
Guard.NotNull(walletTransactionHandler, nameof(walletTransactionHandler));
Guard.NotNull(walletFeePolicy, nameof(walletFeePolicy));
Guard.NotNull(broadcasterManager, nameof(broadcasterManager));

this.ColdStakingManager = walletManager as ColdStakingManager;
Guard.NotNull(this.ColdStakingManager, nameof(this.ColdStakingManager));

this.logger = loggerFactory.CreateLogger(this.GetType().FullName);
this.walletTransactionHandler = walletTransactionHandler;
this.walletFeePolicy = walletFeePolicy;
this.broadcasterManager = broadcasterManager;
}

/// <summary>
Expand Down Expand Up @@ -589,5 +597,45 @@ public IActionResult EstimateColdStakingWithdrawalFee([FromBody] ColdStakingWith
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}

[Route("retrieve-filtered-utxos")]
[HttpPost]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.InternalServerError)]
public IActionResult RetrieveFilteredUtxos([FromBody] RetrieveFilteredUtxosRequest request)
{
Guard.NotNull(request, nameof(request));

// Checks the request is valid.
if (!this.ModelState.IsValid)
{
this.logger.LogTrace("(-)[MODEL_STATE_INVALID]");
return ModelStateErrors.BuildErrorResponse(this.ModelState);
}

try
{
FeeRate feeRate = this.walletFeePolicy.GetFeeRate(FeeType.High.ToConfirmations());

List<Transaction> retrievalTransactions = this.ColdStakingManager.RetrieveFilteredUtxos(request.WalletName, request.WalletPassword, request.Hex, feeRate, request.WalletAccount);

if (request.Broadcast)
{
foreach (Transaction transaction in retrievalTransactions)
{
this.broadcasterManager.BroadcastTransactionAsync(transaction);
}
}

return this.Json(retrievalTransactions.Select(t => t.ToHex()));
}
catch (Exception e)
{
this.logger.LogError("Exception occurred: {0}", e.ToString());
this.logger.LogTrace("(-)[ERROR]");
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,38 @@ public override string ToString()
return $"{nameof(this.TransactionHex)}={this.TransactionHex}";
}
}

public class RetrieveFilteredUtxosRequest
{
/// <summary>The wallet name.</summary>
[Required]
[JsonProperty(PropertyName = "walletName")]
public string WalletName { get; set; }

/// <summary>The wallet password.</summary>
[Required]
[JsonProperty(PropertyName = "walletPassword")]
public string WalletPassword { get; set; }

/// <summary>
/// The (optional) account for the retrieved UTXOs to be sent back to.
/// If this is not specified, the first available non-coldstaking account will be used.
/// </summary>
[JsonProperty(PropertyName = "walletAccount")]
public string WalletAccount { get; set; }

/// <summary>
/// The hex of the transaction to retrieve the UTXOs for.
/// Only UTXOs sent to addresses within the supplied wallet can be reclaimed.
/// </summary>
[Required]
[JsonProperty(PropertyName = "hex")]
public string Hex { get; set; }

/// <summary>
/// Indicate whether the built transactions should be sent to the network immediately after being built.
/// </summary>
[JsonProperty(PropertyName = "broadcast")]
public bool Broadcast { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<Authors>Stratis Group Ltd.</Authors>
<PackageId>Stratis.Features.Interop</PackageId>
<Product>Stratis.Features.Interop</Product>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<OutputTypeEx>library</OutputTypeEx>
<Authors>Stratis Group Ltd.</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Product />
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Stratis.Bitcoin.Features.PoA/FederationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private void AddFederationMemberLocked(IFederationMember federationMember)
this.logger.Warn($"Federation member with address '{collateralFederationMember.CollateralMainchainAddress}' already exists.");
return;
}

if (this.federationMembers.Contains(federationMember))
{
this.logger.Trace("(-)[ALREADY_EXISTS]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<Version>1.0.9.4</Version>
<Version>1.0.9.5</Version>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<Authors>Stratis Group Ltd.</Authors>
</PropertyGroup>
Expand Down
Loading

0 comments on commit 393eec8

Please sign in to comment.