Skip to content
Open
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 @@ -385,6 +385,69 @@ public IActionResult GetGeneralInfo([FromQuery] WalletName request)
}
}

/// <summary>
/// Toggle's the type of wallet for cold staking.
/// </summary>
/// <param name="request">The name of the wallet to get the information for, and if it's a cold wallet or not.</param>
/// <returns>A JSON true.</returns>
[Route("setcoldhotstate")]
[HttpPost]
public IActionResult SetColdHotState([FromBody] ToggleColdRequest request)
{
Guard.NotNull(request, nameof(request));

// checks the request is valid
if (!this.ModelState.IsValid)
{
return ModelStateErrors.BuildErrorResponse(this.ModelState);
}

try
{
Types.Wallet wallet = this.walletManager.GetWallet(request.Name);
wallet.isColdHotWallet = request.isColdHotWallet;
this.walletManager.SaveWallet(wallet);

return this.Ok();
}
catch (Exception e)
{
this.logger.LogError(e, "Exception occurred: {0}");
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}

/// <summary>
/// Get's the cold staking type for wallet.
/// </summary>
/// <param name="request">The name of the wallet to get the information for.</param>
/// <returns>A JSON true/false.</returns>
[Route("getcoldhotstate")]
[HttpGet]
public IActionResult GetColdHotState([FromQuery] WalletName request)
{
Guard.NotNull(request, nameof(request));

// checks the request is valid
if (!this.ModelState.IsValid)
{
return ModelStateErrors.BuildErrorResponse(this.ModelState);
}

try
{
Types.Wallet wallet = this.walletManager.GetWallet(request.Name);

return this.Json(wallet.isColdHotWallet);
}
catch (Exception e)
{
this.logger.LogError(e, "Exception occurred: {0}");
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}


/// <summary>
/// Gets the history of a wallet. This includes the transactions held by the entire wallet
/// or a single account if one is specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,15 @@ public class WalletName : RequestModel
public string Name { get; set; }
}

public class ToggleColdRequest : RequestModel
{

[Required(ErrorMessage = "The name of the wallet is missing.")]
public string Name { get; set; }

public bool isColdHotWallet { get; set; }
}

/// <summary>
/// A class containing the necessary parameters for a transaction fee estimate request.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Features/Blockcore.Features.Wallet/Types/Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ public Wallet()
[JsonProperty(PropertyName = "isExtPubKeyWallet")]
public bool IsExtPubKeyWallet { get; set; }

/// <summary>
/// Flag indicating if it is a cold hot wallet.
/// </summary>
[JsonProperty(PropertyName = "isColdHotWallet")]
public bool isColdHotWallet { get; set; }

/// <summary>
/// The seed for this wallet, password encrypted.
/// </summary>
Expand Down