Commit 8b4a2c48 authored by Sergei Zubov's avatar Sergei Zubov

Add newaddress request

parent a309dcac
...@@ -22,13 +22,15 @@ namespace Stratis.Bitcoin.Features.Wallet.Controllers ...@@ -22,13 +22,15 @@ namespace Stratis.Bitcoin.Features.Wallet.Controllers
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly DeStreamNetwork _network; private readonly DeStreamNetwork _network;
private readonly IWalletTransactionHandler _walletTransactionHandler; private readonly IWalletTransactionHandler _walletTransactionHandler;
private readonly IDeStreamWalletManager _walletManager;
public DeStreamWalletController(Network network, IWalletTransactionHandler walletTransactionHandler, public DeStreamWalletController(Network network, IWalletTransactionHandler walletTransactionHandler,
ILoggerFactory loggerFactory) ILoggerFactory loggerFactory, IDeStreamWalletManager walletManager)
{ {
this._network = (DeStreamNetwork) network ?? this._network = (DeStreamNetwork) network ??
throw new NotSupportedException($"Network must be {nameof(NBitcoin.DeStreamNetwork)}"); throw new NotSupportedException($"Network must be {nameof(NBitcoin.DeStreamNetwork)}");
this._walletTransactionHandler = walletTransactionHandler; this._walletTransactionHandler = walletTransactionHandler;
this._walletManager = walletManager;
this._logger = loggerFactory.CreateLogger(GetType().FullName); this._logger = loggerFactory.CreateLogger(GetType().FullName);
} }
...@@ -139,6 +141,30 @@ namespace Stratis.Bitcoin.Features.Wallet.Controllers ...@@ -139,6 +141,30 @@ namespace Stratis.Bitcoin.Features.Wallet.Controllers
} }
} }
[Route("newaddress")]
[HttpGet]
public IActionResult GetNewAddress([FromQuery] GetNewAddressModel request)
{
Guard.NotNull(request, nameof(request));
// checks the request is valid
if (!this.ModelState.IsValid)
{
return ModelStateErrors.BuildErrorResponse(this.ModelState);
}
try
{
return this.Json(this._walletManager.CreateAddress(new WalletAccountReference(request.WalletName,
request.AccountName)));
}
catch (Exception e)
{
this._logger.LogError("Exception occurred: {0}", e.ToString());
return ErrorHelpers.BuildErrorResponse(HttpStatusCode.BadRequest, e.Message, e.ToString());
}
}
/// <summary> /// <summary>
/// Modifies transfer funds amount according to fee type. /// Modifies transfer funds amount according to fee type.
/// For <see cref="DeStreamFeeType.Extra" /> fee type, fee is subtracted from transfer funds. /// For <see cref="DeStreamFeeType.Extra" /> fee type, fee is subtracted from transfer funds.
......
...@@ -95,5 +95,14 @@ namespace Stratis.Bitcoin.Features.Wallet ...@@ -95,5 +95,14 @@ namespace Stratis.Bitcoin.Features.Wallet
spentTransaction.SpendingDetails = spendingDetails; spentTransaction.SpendingDetails = spendingDetails;
spentTransaction.MerkleProof = null; spentTransaction.MerkleProof = null;
} }
public HdAddress CreateAddress(WalletAccountReference accountReference)
{
Guard.NotNull(accountReference, nameof(accountReference));
return this.GetWalletByName(accountReference.WalletName)
.GetAccountByCoinType(accountReference.AccountName, this.coinType).CreateAddresses(this.network, 1)
.Single();
}
} }
} }
\ No newline at end of file
...@@ -6,5 +6,7 @@ ...@@ -6,5 +6,7 @@
/// Processes genesis block /// Processes genesis block
/// </summary> /// </summary>
void ProcessGenesisBlock(); void ProcessGenesisBlock();
HdAddress CreateAddress(WalletAccountReference accountReference);
} }
} }
\ No newline at end of file
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