init work

This commit is contained in:
Kukks 2019-11-29 21:24:52 +01:00
parent 579e0d2e09
commit 2da9434571
4 changed files with 64 additions and 1 deletions

View File

@ -17,6 +17,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NBitcoin;
using NBXplorer.DerivationStrategy;
using NBXplorer.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@ -319,6 +320,31 @@ namespace BTCPayServer.Controllers
return ShowAddresses(vm, strategy);
}
[HttpPost]
[Route("{storeId}/derivations/{cryptoCode}/generatenbxwallet")]
public async Task<IActionResult> GenerateNBXWallet(string storeId, string cryptoCode, GenerateWalletRequest request)
{
var network = _NetworkProvider.GetNetwork<BTCPayNetwork>(cryptoCode);
var client = _ExplorerProvider.GetExplorerClient(cryptoCode);
var response = await client.GenerateWalletAsync(request);
var result = await AddDerivationScheme(storeId, new DerivationSchemeViewModel()
{
Confirmation = false,
Network = network,
RootFingerprint = response.AccountKeyPath.MasterFingerprint.ToString(),
RootKeyPath = response.AccountKeyPath.KeyPath,
CryptoCode = cryptoCode,
DerivationScheme = response.DerivationScheme.ToString(),
Source = "NBXplorer",
AccountKey = response.AccountHDKey.ToWif(),
DerivationSchemeFormat = "BTCPay",
KeyPath = response.AccountKeyPath.KeyPath.ToString(),
Enabled = true
}, cryptoCode);
((ViewResult)result).ViewName = nameof(AddDerivationScheme);
return result;
}
private async Task<string> ReadAllText(IFormFile file)
{
using (var stream = new StreamReader(file.OpenReadStream()))

View File

@ -85,6 +85,8 @@
{
<button class="dropdown-item check-for-vault" type="button">... the vault (preview)</button>
}
<button class="dropdown-item" data-toggle="modal" data-target="#nbxplorergeneratewallet" type="button">... a new/existing seed.</button>
</div>
</div>
</div>

View File

@ -1,4 +1,4 @@
@model DerivationSchemeViewModel
<partial name="AddDerivationSchemes_NBXWalletGenerate"/>@model DerivationSchemeViewModel
<div class="modal fade" id="ledgerimport" tabindex="-1" role="dialog" aria-labelledby="ledgerimport" aria-hidden="true">
<div class="modal-dialog" role="document">
@ -121,3 +121,4 @@
</form>
</div>
</template>
<partial name="AddDerivationSchemes_NBXWalletGenerate"/>

View File

@ -0,0 +1,34 @@
@using NBitcoin
@model NBXplorer.Models.GenerateWalletRequest
<div class="modal fade" id="nbxplorergeneratewallet" tabindex="-1" role="dialog" aria-labelledby="nbxplorergeneratewallet" aria-hidden="true">
<div class="modal-dialog" role="document">
<form class="modal-content" form method="post" asp-action="GenerateNBXWallet" enctype="multipart/form-data">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Generate a wallet with a seed</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>You may generate a wallet with a seed and import the xpub it into BTCPay. You can optionally also tell NBX to import the keys to the node wallet to be able to spend received funds from it.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<div id="vault-dropdown" style="display:none;" class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Select the type of address you want
</button>
<div class="dropdown-menu overflow-auto" style="max-height: 200px;">
<button type="submit" class="dropdown-item" asp-for="ScriptPubKeyType" value="@ScriptPubKeyType.Segwit">Segwit (Recommended, cheapest transaction fee)</button>
<a class="dropdown-item" href="#" asp-for="ScriptPubKeyType" value="@ScriptPubKeyType.SegwitP2SH">Segwit wrapped (less cheap but compatible with old wallets)</a>
<a class="dropdown-item" href="#" asp-for="ScriptPubKeyType" value="@ScriptPubKeyType.Legacy">Legacy (Not recommended)</a>
</div>
</div>
</div>
</form>
</div>
</div>