Implement send-transaction
MODIFY
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
@@ -221,7 +221,7 @@ namespace HiddenWallet.API.Controllers
[Route("build-transaction/{account}")]
[HttpPost]
- public IActionResult History(string account, [FromBody]BuildTransactionRequest request)
+ public IActionResult BuildTransaction(string account, [FromBody]BuildTransactionRequest request)
{
try
{
@@ -286,5 +286,34 @@ namespace HiddenWallet.API.Controllers
return new ObjectResult(new FailureResponse { Message = ex.Message, Details = ex.ToString() });
}
}
+
+ [Route("send-transaction")]
+ [HttpPost]
+ public IActionResult SendTransaction([FromBody]HexModel request)
+ {
+ try
+ {
+ if (request == null || request.Hex == null)
+ {
+ return new ObjectResult(new FailureResponse { Message = "Bad request", Details = "" });
+ }
+
+ Transaction tx;
+ try
+ {
+ tx = new Transaction(request.Hex);
+ }
+ catch
+ {
+ return new ObjectResult(new FailureResponse { Message = "Wrong transaction hex", Details = "" });
+ }
+
+ return new ObjectResult(Global.WalletWrapper.SendTransactionAsync(tx).Result);
+ }
+ catch (Exception ex)
+ {
+ return new ObjectResult(new FailureResponse { Message = ex.Message, Details = ex.ToString() });
+ }
+ }
}
}

MODIFY
HiddenWallet/HiddenWallet.API/Wrappers/WalletWrapper.cs
HiddenWallet/HiddenWallet.API/Wrappers/WalletWrapper.cs
@@ -13,6 +13,7 @@ using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
+using static HBitcoin.FullBlockSpv.WalletJob;
namespace HiddenWallet.API.Wrappers
{
@@ -292,5 +293,13 @@ namespace HiddenWallet.API.Wrappers
};
}
}
+
+ public async Task<BaseResponse> SendTransactionAsync(Transaction tx)
+ {
+ SendTransactionResult result = await _walletJob.SendTransactionAsync(tx).ConfigureAwait(false);
+
+ if (result.Success) return new SuccessResponse();
+ else return new FailureResponse { Message = result.FailingReason };
+ }
}
}

Implement send-transaction