Fully implement transaction building
MODIFY
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
@@ -233,15 +233,31 @@ namespace HiddenWallet.API.Controllers
var fail = GetAccount(account, out SafeAccount safeAccount);
if (fail != null) return new ObjectResult(fail);
- var address = BitcoinAddress.Create(request.Address, Global.WalletWrapper.Network);
-
+ BitcoinAddress address;
+ try
+ {
+ address = BitcoinAddress.Create(request.Address, Global.WalletWrapper.Network);
+ }
+ catch
+ {
+ return new ObjectResult(new FailureResponse { Message = "Wrong address", Details = "" });
+ }
Money amount = Money.Zero; // in this case all funds are sent from the wallet
+ try
+ {
if (request.Amount != "all")
{
- var tmpAmount = new Money(decimal.Parse(request.Amount.Replace('.', ','), NumberStyles.Any, CultureInfo.InvariantCulture), MoneyUnit.BTC);
- if (tmpAmount <= Money.Zero) throw new NotSupportedException("Amount must be > 0 or \"all\"");
+ var tmpAmount = new Money(decimal.Parse(request.Amount.Replace(',', '.'), NumberStyles.Any, CultureInfo.InvariantCulture), MoneyUnit.BTC);
+
+ if (tmpAmount <= Money.Zero) return new ObjectResult(new FailureResponse { Message = "Amount must be > 0 or \"all\"", Details = "" });
amount = tmpAmount;
}
+ }
+ catch
+ {
+ return new ObjectResult(new FailureResponse { Message = "Wrong amount", Details = "" });
+ }
+
FeeType feeType;
if(request.FeeType.Equals("high", StringComparison.OrdinalIgnoreCase))
@@ -258,7 +274,7 @@ namespace HiddenWallet.API.Controllers
}
else
{
- throw new NotSupportedException("Wrong FeeType");
+ return new ObjectResult(new FailureResponse { Message = "Wrong fee type", Details = "" });
}
var allowUnconfirmed = bool.Parse(request.AllowUnconfirmed);

MODIFY
HiddenWallet/HiddenWallet.API/Models/BuildTransactionResponse.cs
HiddenWallet/HiddenWallet.API/Models/BuildTransactionResponse.cs
@@ -8,8 +8,6 @@ namespace HiddenWallet.API.Models
public class BuildTransactionResponse : BaseResponse
{
public BuildTransactionResponse() => Success = true;
- public bool Valid { get; set; }
- public string FailingReason { get; set; }
public bool SpendsUnconfirmed { get; set; }
public string Fee { get; set; }
public string FeePercentOfSent { get; set; }

MODIFY
HiddenWallet/HiddenWallet.API/Wrappers/WalletWrapper.cs
HiddenWallet/HiddenWallet.API/Wrappers/WalletWrapper.cs
@@ -268,15 +268,15 @@ namespace HiddenWallet.API.Wrappers
else return new StatusResponse { HeaderHeight = 0, TrackingHeight = 0, ConnectedNodeCount = 0, MemPoolTransactionCount = 0, WalletState = WalletState.NotStarted.ToString(), ChangeBump = 0 };
}
- public BuildTransactionResponse BuildTransaction(string password, SafeAccount safeAccount, BitcoinAddress address, Money amount, FeeType feeType, bool allowUnconfirmed)
+ public BaseResponse BuildTransaction(string password, SafeAccount safeAccount, BitcoinAddress address, Money amount, FeeType feeType, bool allowUnconfirmed)
{
if (password != _password) throw new InvalidOperationException("Wrong password");
var result = _walletJob.BuildTransactionAsync(address.ScriptPubKey, amount, feeType, safeAccount, allowUnconfirmed).Result;
+ if (result.Success)
+ {
return new BuildTransactionResponse
{
- Valid = result.Success,
- FailingReason = result.FailingReason,
SpendsUnconfirmed = result.SpendsUnconfirmed,
Fee = result.Fee.ToString(false, true),
FeePercentOfSent = result.FeePercentOfSent.ToString("0.##"),
@@ -284,5 +284,13 @@ namespace HiddenWallet.API.Wrappers
Transaction = result.Transaction.ToString()
};
}
+ else
+ {
+ return new FailureResponse
+ {
+ Message = result.FailingReason
+ };
+ }
+ }
}
}

MODIFY
HiddenWallet/HiddenWallet.GUI/HiddenWallet.GUI.njsproj
HiddenWallet/HiddenWallet.GUI/HiddenWallet.GUI.njsproj
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
+ <Compile Include="app\js\broadcast-window.js">
+ <SubType>Code</SubType>
+ </Compile>
<Compile Include="app\js\cleanup.js" />
<Compile Include="app\js\decryption-phase.js" />
<Compile Include="app\js\default.js">
<SubType>Code</SubType>
</Content>
<Content Include="app\css\justified-nav.css" />
+ <Content Include="app\html\broadcast-transaction-window.html" />
<Content Include="app\html\decryption-phase-content.html" />
<Content Include="app\html\decryption-phase-menu.html" />
<Content Include="app\html\shutdown.html" />

MODIFY
HiddenWallet/HiddenWallet.GUI/app/js/wallet-phase.js
HiddenWallet/HiddenWallet.GUI/app/js/wallet-phase.js
@@ -145,21 +145,21 @@ function buildTransaction() {
var password = document.getElementById("send-password").value;
if (!address) {
- alert("Wrong address!");
+ alert("Couldn't build the transaciton: Wrong address!");
return;
}
if (!amount || amount <= 0) {
- alert("Wrong amount!");
+ alert("Couldn't build the transaciton: Wrong amount!");
return;
}
// if both are checked or none are checked (cannot happen)
if ((fastFeeChecked && slowFeeChecked) || (!fastFeeChecked && !slowFeeChecked)) {
- alert("Wrong fee tpye!");
+ alert("Couldn't build the transaciton: Wrong fee tpye!");
return;
}
// (cannot happen)
if (password == null) {
- alert("Wrong fee tpye!");
+ alert("Couldn't build the transaciton: Wrong fee tpye!");
return;
}
@@ -180,11 +180,34 @@ function buildTransaction() {
var bobOrAlice = tabs.firstElementChild.id;
if (bobOrAlice == "alice-active") {
- response = httpPostWallet("build-transaction/alice", obj, true);
+ response = httpPostWallet("build-transaction/alice", obj);
}
if (bobOrAlice == "bob-active") {
- response = httpPostWallet("build-transaction/bob", obj, true);
+ response = httpPostWallet("build-transaction/bob", obj);
}
}
- alert(response);
+ if (response.Success === false) {
+ var alertMessage = "Couldn't build the transaciton: " + response.Message;
+ if (!isBlank(response.Details)) {
+ alertMessage = alertMessage + "\n\nDetails:\n" + response.Details;
+ }
+ alert(alertMessage);
+ return;
+ }
+ else {
+ const remote = require('electron').remote;
+ const window = remote.getCurrentWindow();
+ const BrowserWindow = remote.BrowserWindow;
+ var broadcastWindow = new BrowserWindow({ width: 600, height: 400, frame: false, resizable: false, alwaysOnTop: true, parent: window });
+ broadcastWindow.show();
+ broadcastWindow.focus();
+ broadcastWindow.loadURL('file://' + __dirname + '/app/html/broadcast-transaction-window.html');
+ broadcastWindow.webContents.on('did-finish-load', () => {
+ broadcastWindow.webContents.send('broadcast-response', response);
+ })
+ }
+}
+
+function isBlank(str) {
+ return (!str || /^\s*$/.test(str));
}
\ No newline at end of file

Fully implement transaction building