Commit c2cde249 authored by Jeremy Bokobza's avatar Jeremy Bokobza

Returning 200 OK for Loading and recovering a wallet

parent bc225cb7
...@@ -148,9 +148,17 @@ POST /wallet/send-transaction - Attempts to send a transaction ...@@ -148,9 +148,17 @@ POST /wallet/send-transaction - Attempts to send a transaction
### Parameters ### Parameters
``` ```
{ {
"password": "password" "password": "123456",
"folderPath": "Wallets", // optional, if the folder path is not the default one
"name": "myWallet"
} }
``` ```
### Response
```
200 (OK)
```
## POST /wallet/recover - Recovers the wallet ## POST /wallet/recover - Recovers the wallet
### Parameters ### Parameters
``` ```
...@@ -158,11 +166,16 @@ POST /wallet/send-transaction - Attempts to send a transaction ...@@ -158,11 +166,16 @@ POST /wallet/send-transaction - Attempts to send a transaction
"network": "main", // "main" or "testnet" "network": "main", // "main" or "testnet"
"password": "password", "password": "password",
"mnemonic": "foo bar buz", "mnemonic": "foo bar buz",
"creationTime": "2017-02-03" // DateTimeOffset.ParseExact("1998-01-01", "yyyy-MM-dd", CultureInfo.InvariantCulture), utc time "name": "testwallet-recovered",
"folderPath": "Wallets", // optional, if the folder path is not the default one
"creationTime": "2017-02-25 16:20:33" // date from which to start looking for transactions
} }
``` ```
### Response ### Response
Cannot check if the password is good or not. If the password is wrong it'll recover a wallet with the wrong password. Cannot check if the password is good or not. If the password is wrong it'll recover a wallet with the wrong password.
```
200 (OK)
```
## DELETE /wallet - Deletes the wallet ## DELETE /wallet - Deletes the wallet
Works as expected. Works as expected.
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170106-08" />
<PackageReference Include="NStratis" Version="3.0.2.17" /> <PackageReference Include="NStratis" Version="3.0.2.23" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" />
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" /> <PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" /> <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" /> <PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="Moq" Version="4.7.8" /> <PackageReference Include="Moq" Version="4.7.10" />
</ItemGroup> </ItemGroup>
</Project> </Project>
...@@ -66,12 +66,8 @@ namespace Breeze.Api.Tests ...@@ -66,12 +66,8 @@ namespace Breeze.Api.Tests
// Assert // Assert
mockWalletWrapper.VerifyAll(); mockWalletWrapper.VerifyAll();
var viewResult = Assert.IsType<JsonResult>(result); var viewResult = Assert.IsType<OkResult>(result);
Assert.NotNull(viewResult.Value); Assert.Equal(200, viewResult.StatusCode);
Assert.IsType<WalletModel>(viewResult.Value);
var model = viewResult.Value as WalletModel;
Assert.Equal("Main", model.Network);
} }
[Fact] [Fact]
...@@ -97,12 +93,8 @@ namespace Breeze.Api.Tests ...@@ -97,12 +93,8 @@ namespace Breeze.Api.Tests
// Assert // Assert
mockWalletWrapper.VerifyAll(); mockWalletWrapper.VerifyAll();
var viewResult = Assert.IsType<JsonResult>(result); var viewResult = Assert.IsType<OkResult>(result);
Assert.NotNull(viewResult.Value); Assert.Equal(200, viewResult.StatusCode);
Assert.IsType<WalletModel>(viewResult.Value);
var model = viewResult.Value as WalletModel;
Assert.Equal("Main", model.Network);
} }
[Fact] [Fact]
......
...@@ -78,14 +78,9 @@ namespace Breeze.Wallet.Controllers ...@@ -78,14 +78,9 @@ namespace Breeze.Wallet.Controllers
{ {
// get the wallet folder // get the wallet folder
DirectoryInfo walletFolder = GetWalletFolder(request.FolderPath); DirectoryInfo walletFolder = GetWalletFolder(request.FolderPath);
Wallet wallet = this.walletManager.LoadWallet(request.Password, walletFolder.FullName, request.Name); Wallet wallet = this.walletManager.LoadWallet(request.Password, walletFolder.FullName, request.Name);
return this.Json(new WalletModel
{ return this.Ok();
Network = wallet.Network.Name,
// Addresses = wallet.GetFirstNAddresses(10).Select(a => a.ToWif()),
FileName = wallet.WalletFilePath
});
} }
catch (FileNotFoundException e) catch (FileNotFoundException e)
{ {
...@@ -122,18 +117,12 @@ namespace Breeze.Wallet.Controllers ...@@ -122,18 +117,12 @@ namespace Breeze.Wallet.Controllers
{ {
// get the wallet folder // get the wallet folder
DirectoryInfo walletFolder = GetWalletFolder(request.FolderPath); DirectoryInfo walletFolder = GetWalletFolder(request.FolderPath);
Wallet wallet = this.walletManager.RecoverWallet(request.Password, walletFolder.FullName, request.Name, request.Network, request.Mnemonic, null, request.CreationDate); Wallet wallet = this.walletManager.RecoverWallet(request.Password, walletFolder.FullName, request.Name, request.Network, request.Mnemonic, null, request.CreationDate);
// start syncing the wallet from the creation date // start syncing the wallet from the creation date
this.tracker.SyncFrom(request.CreationDate); this.tracker.SyncFrom(request.CreationDate);
return this.Json(new WalletModel return this.Ok();
{
Network = wallet.Network.Name,
// Addresses = wallet.GetFirstNAddresses(10).Select(a => a.ToWif()),
FileName = wallet.WalletFilePath
});
} }
catch (InvalidOperationException e) catch (InvalidOperationException e)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment