Commit 1b5310fa authored by Sergei Zubov's avatar Sergei Zubov

Add newaddress request

parent 2fc62ee9
Pipeline #152 failed with stage
in 1 minute and 39 seconds
......@@ -22,13 +22,15 @@ namespace Stratis.Bitcoin.Features.Wallet.Controllers
private readonly ILogger _logger;
private readonly DeStreamNetwork _network;
private readonly IWalletTransactionHandler _walletTransactionHandler;
private readonly IDeStreamWalletManager _walletManager;
public DeStreamWalletController(Network network, IWalletTransactionHandler walletTransactionHandler,
ILoggerFactory loggerFactory)
ILoggerFactory loggerFactory, IDeStreamWalletManager walletManager)
{
this._network = (DeStreamNetwork) network ??
throw new NotSupportedException($"Network must be {nameof(NBitcoin.DeStreamNetwork)}");
this._walletTransactionHandler = walletTransactionHandler;
this._walletManager = walletManager;
this._logger = loggerFactory.CreateLogger(GetType().FullName);
}
......@@ -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>
/// Modifies transfer funds amount according to fee type.
/// For <see cref="DeStreamFeeType.Extra" /> fee type, fee is subtracted from transfer funds.
......
......@@ -95,5 +95,14 @@ namespace Stratis.Bitcoin.Features.Wallet
spentTransaction.SpendingDetails = spendingDetails;
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 @@
/// Processes genesis block
/// </summary>
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