diff --git a/src/Features/Blockcore.Features.Wallet/Api/Controllers/WalletController.cs b/src/Features/Blockcore.Features.Wallet/Api/Controllers/WalletController.cs index 531445a74..ba2ddf57d 100644 --- a/src/Features/Blockcore.Features.Wallet/Api/Controllers/WalletController.cs +++ b/src/Features/Blockcore.Features.Wallet/Api/Controllers/WalletController.cs @@ -385,6 +385,69 @@ public IActionResult GetGeneralInfo([FromQuery] WalletName request) } } + /// + /// Toggle's the type of wallet for cold staking. + /// + /// The name of the wallet to get the information for, and if it's a cold wallet or not. + /// A JSON true. + [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()); + } + } + + /// + /// Get's the cold staking type for wallet. + /// + /// The name of the wallet to get the information for. + /// A JSON true/false. + [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()); + } + } + + /// /// Gets the history of a wallet. This includes the transactions held by the entire wallet /// or a single account if one is specified. diff --git a/src/Features/Blockcore.Features.Wallet/Api/Models/RequestModels.cs b/src/Features/Blockcore.Features.Wallet/Api/Models/RequestModels.cs index b55869ff2..834e864e0 100644 --- a/src/Features/Blockcore.Features.Wallet/Api/Models/RequestModels.cs +++ b/src/Features/Blockcore.Features.Wallet/Api/Models/RequestModels.cs @@ -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; } + } + /// /// A class containing the necessary parameters for a transaction fee estimate request. /// diff --git a/src/Features/Blockcore.Features.Wallet/Types/Wallet.cs b/src/Features/Blockcore.Features.Wallet/Types/Wallet.cs index 0f7a84f7b..bf3f8039f 100644 --- a/src/Features/Blockcore.Features.Wallet/Types/Wallet.cs +++ b/src/Features/Blockcore.Features.Wallet/Types/Wallet.cs @@ -47,6 +47,12 @@ public Wallet() [JsonProperty(PropertyName = "isExtPubKeyWallet")] public bool IsExtPubKeyWallet { get; set; } + /// + /// Flag indicating if it is a cold hot wallet. + /// + [JsonProperty(PropertyName = "isColdHotWallet")] + public bool isColdHotWallet { get; set; } + /// /// The seed for this wallet, password encrypted. ///