diff --git a/IotaSDK.NET/Contexts/WalletContext/Commands/BackupStronghold/BackupStrongholdCommand.cs b/IotaSDK.NET/Contexts/WalletContext/Commands/BackupStronghold/BackupStrongholdCommand.cs new file mode 100644 index 0000000..22bee4a --- /dev/null +++ b/IotaSDK.NET/Contexts/WalletContext/Commands/BackupStronghold/BackupStrongholdCommand.cs @@ -0,0 +1,18 @@ +using IotaSDK.NET.Common.Interfaces; +using IotaSDK.NET.Common.Models; +using System; + +namespace IotaSDK.NET.Contexts.WalletContext.Commands.BackupStronghold +{ + internal class BackupStrongholdCommand : WalletRequest> + { + public BackupStrongholdCommand(IntPtr walletHandle, string destinationPath, string password) : base(walletHandle) + { + DestinationPath = destinationPath; + Password = password; + } + + public string DestinationPath { get; } + public string Password { get; } + } +} diff --git a/IotaSDK.NET/Contexts/WalletContext/Commands/BackupStronghold/BackupStrongholdCommandHandler.cs b/IotaSDK.NET/Contexts/WalletContext/Commands/BackupStronghold/BackupStrongholdCommandHandler.cs new file mode 100644 index 0000000..48f6101 --- /dev/null +++ b/IotaSDK.NET/Contexts/WalletContext/Commands/BackupStronghold/BackupStrongholdCommandHandler.cs @@ -0,0 +1,35 @@ +using IotaSDK.NET.Common.Exceptions; +using IotaSDK.NET.Common.Models; +using IotaSDK.NET.Common.Rust; +using MediatR; +using System.Threading; +using System.Threading.Tasks; + +namespace IotaSDK.NET.Contexts.WalletContext.Commands.BackupStronghold +{ + internal class BackupStrongholdCommandHandler : IRequestHandler> + { + private readonly RustBridgeWallet _rustBridgeWallet; + + public BackupStrongholdCommandHandler(RustBridgeWallet rustBridgeWallet) + { + _rustBridgeWallet = rustBridgeWallet; + } + + public async Task> Handle(BackupStrongholdCommand request, CancellationToken cancellationToken) + { + BackupStrongholdCommandModelData modelData = new BackupStrongholdCommandModelData(request.DestinationPath, request.Password); + IotaSDKModel model = new IotaSDKModel("backup", modelData); + string json = model.AsJson(); + + string? walletResponse = await _rustBridgeWallet.CallWalletMethodAsync(request.WalletHandle, json); + + IotaSDKException.CheckForException(walletResponse!); + + var response = IotaSDKResponse.CreateInstance(walletResponse, "backup"); + response.Payload = true; + + return response; + } + } +} diff --git a/IotaSDK.NET/Contexts/WalletContext/Commands/BackupStronghold/BackupStrongholdCommandModelData.cs b/IotaSDK.NET/Contexts/WalletContext/Commands/BackupStronghold/BackupStrongholdCommandModelData.cs new file mode 100644 index 0000000..36f4bee --- /dev/null +++ b/IotaSDK.NET/Contexts/WalletContext/Commands/BackupStronghold/BackupStrongholdCommandModelData.cs @@ -0,0 +1,14 @@ +namespace IotaSDK.NET.Contexts.WalletContext.Commands.BackupStronghold +{ + internal class BackupStrongholdCommandModelData + { + public BackupStrongholdCommandModelData(string destination, string password) + { + Destination = destination; + Password = password; + } + + public string Destination { get; } + public string Password { get; } + } +}