Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,15 @@ public HdAccount GetOrCreateColdStakingAccount(string walletName, bool isColdWal
/// track addresses under the <see cref="ColdWalletAccountIndex"/> HD account.
/// </summary>
/// <inheritdoc />
public override Wallet.Types.Wallet RecoverWallet(string password, string name, string mnemonic, DateTime creationTime, string passphrase, int? coinType = null)
public override Wallet.Types.Wallet RecoverWallet(string password, string name, string mnemonic, DateTime creationTime, string passphrase, int? coinType = null, bool? isColdStakingWallet = false)
{
Wallet.Types.Wallet wallet = base.RecoverWallet(password, name, mnemonic, creationTime, passphrase, coinType);

this.GetOrCreateColdStakingAccount(wallet.Name, false, password);
this.GetOrCreateColdStakingAccount(wallet.Name, true, password);
if (isColdStakingWallet.HasValue && isColdStakingWallet == true)
{
this.GetOrCreateColdStakingAccount(wallet.Name, false, password);
this.GetOrCreateColdStakingAccount(wallet.Name, true, password);
}

return wallet;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public IActionResult Recover([FromBody] WalletRecoveryRequest request)

try
{
Types.Wallet wallet = this.walletManager.RecoverWallet(request.Password, request.Name, request.Mnemonic, request.CreationDate, passphrase: request.Passphrase, request.CoinType);
Types.Wallet wallet = this.walletManager.RecoverWallet(request.Password, request.Name, request.Mnemonic, request.CreationDate, passphrase: request.Passphrase, request.CoinType, request.IsColdStakingWallet);

this.SyncFromBestHeightForRecoveredWallets(request.CreationDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public class WalletRecoveryRequest : RequestModel
/// Optional CoinType to overwrite the default <see cref="Blockcore.Consensus.IConsensus.CoinType"/>.
/// </summary>
public int? CoinType { get; set; }

/// <summary>
/// Optional flag that indicates if the "coldStakingColdAddresses" and "coldStakingHotAddresses" accounts should be restored.
/// </summary>
public bool? IsColdStakingWallet { get; set; }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public interface IWalletManager
/// <param name="creationTime">The date and time this wallet was created.</param>
/// <param name="coinType">Allow to override the default BIP44 cointype.</param>
/// <returns>The recovered wallet.</returns>
Types.Wallet RecoverWallet(string password, string name, string mnemonic, DateTime creationTime, string passphrase = null, int? coinType = null);
Types.Wallet RecoverWallet(string password, string name, string mnemonic, DateTime creationTime, string passphrase = null, int? coinType = null, bool? isColdStakingWallet = false);

/// <summary>
/// Recovers a wallet using extended public key and account index.
Expand Down
2 changes: 1 addition & 1 deletion src/Features/Blockcore.Features.Wallet/WalletManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private SecureString CacheSecret(string name, string walletPassword, TimeSpan du
}

/// <inheritdoc />
public virtual Types.Wallet RecoverWallet(string password, string name, string mnemonic, DateTime creationTime, string passphrase, int? coinType = null)
public virtual Types.Wallet RecoverWallet(string password, string name, string mnemonic, DateTime creationTime, string passphrase, int? coinType = null, bool? isColdStakingWallet = false)
{
Guard.NotEmpty(password, nameof(password));
Guard.NotEmpty(name, nameof(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public void RecoverWalletSuccessfullyReturnsWalletModel()
};

var mockWalletManager = new Mock<IWalletManager>();
mockWalletManager.Setup(w => w.RecoverWallet(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), null, null)).Returns(wallet);
mockWalletManager.Setup(w => w.RecoverWallet(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), null, null, true)).Returns(wallet);

Mock<IWalletSyncManager> walletSyncManager = new Mock<IWalletSyncManager>();
walletSyncManager.Setup(w => w.WalletTip).Returns(new ChainedHeader(this.Network.GetGenesis().Header, this.Network.GetGenesis().Header.GetHash(), 3));
Expand Down Expand Up @@ -368,7 +368,7 @@ public void RecoverWalletWithDatedAfterCurrentSyncHeightDoesNotMoveSyncHeight()
DateTime lastBlockDateTime = chainIndexer.Tip.Header.BlockTime.DateTime;

var mockWalletManager = new Mock<IWalletManager>();
mockWalletManager.Setup(w => w.RecoverWallet(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), null, null)).Returns(wallet);
mockWalletManager.Setup(w => w.RecoverWallet(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), null, null, true)).Returns(wallet);

Mock<IWalletSyncManager> walletSyncManager = new Mock<IWalletSyncManager>();
walletSyncManager.Setup(w => w.WalletTip).Returns(new ChainedHeader(this.Network.GetGenesis().Header, this.Network.GetGenesis().Header.GetHash(), 3));
Expand Down Expand Up @@ -419,7 +419,7 @@ public void RecoverWalletWithInvalidOperationExceptionReturnsConflict()
{
string errorMessage = "An error occurred.";
var mockWalletManager = new Mock<IWalletManager>();
mockWalletManager.Setup(w => w.RecoverWallet(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), null, null))
mockWalletManager.Setup(w => w.RecoverWallet(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), null, null, true))
.Throws(new WalletException(errorMessage));

var controller = new WalletController(this.LoggerFactory.Object, mockWalletManager.Object, new Mock<IWalletTransactionHandler>().Object, new Mock<IWalletSyncManager>().Object, It.IsAny<ConnectionManager>(), this.Network, this.chainIndexer, new Mock<IBroadcasterManager>().Object, DateTimeProvider.Default);
Expand All @@ -445,7 +445,7 @@ public void RecoverWalletWithInvalidOperationExceptionReturnsConflict()
public void RecoverWalletWithFileNotFoundExceptionReturnsNotFound()
{
var mockWalletManager = new Mock<IWalletManager>();
mockWalletManager.Setup(w => w.RecoverWallet(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), null, null))
mockWalletManager.Setup(w => w.RecoverWallet(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), null, null, true))
.Throws(new FileNotFoundException("File not found."));

var controller = new WalletController(this.LoggerFactory.Object, mockWalletManager.Object, new Mock<IWalletTransactionHandler>().Object, new Mock<IWalletSyncManager>().Object, It.IsAny<ConnectionManager>(), this.Network, this.chainIndexer, new Mock<IBroadcasterManager>().Object, DateTimeProvider.Default);
Expand All @@ -472,7 +472,7 @@ public void RecoverWalletWithFileNotFoundExceptionReturnsNotFound()
public void RecoverWalletWithExceptionReturnsBadRequest()
{
var mockWalletManager = new Mock<IWalletManager>();
mockWalletManager.Setup(w => w.RecoverWallet(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), null, null))
mockWalletManager.Setup(w => w.RecoverWallet(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DateTime>(), null, null, true))
.Throws(new FormatException("Formatting failed."));

var controller = new WalletController(this.LoggerFactory.Object, mockWalletManager.Object, new Mock<IWalletTransactionHandler>().Object, new Mock<IWalletSyncManager>().Object, It.IsAny<ConnectionManager>(), this.Network, this.chainIndexer, new Mock<IBroadcasterManager>().Object, DateTimeProvider.Default);
Expand Down