Implement receive
MODIFY
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
@@ -5,6 +5,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using HiddenWallet.API.Models;
using HiddenWallet.API.Wrappers;
+using HBitcoin.KeyManagement;
namespace HiddenWallet.API.Controllers
{
@@ -142,30 +143,55 @@ namespace HiddenWallet.API.Controllers
{
try
{
+ var fail = GetAccount(account, out SafeAccount safeAccount);
+ if (fail != null) return new ObjectResult(fail);
+
+ return new ObjectResult(new BalancesResponse
+ {
+ Available = Global.WalletWrapper.GetAvailable(safeAccount).ToString(false, true),
+ Incoming = Global.WalletWrapper.GetIncoming(safeAccount).ToString(false, true)
+ });
+ }
+ catch (Exception ex)
+ {
+ return new ObjectResult(new FailureResponse { Message = ex.Message, Details = ex.ToString() });
+ }
+ }
+
+ /// <returns>null if didn't fail</returns>
+ private FailureResponse GetAccount(string account, out SafeAccount safeAccount)
+ {
+ safeAccount = null;
if (account == null)
- return new ObjectResult(new FailureResponse { Message = "No request body specified" });
+ return new FailureResponse { Message = "No request body specified" };
if (!Global.WalletWrapper.IsDecrypted)
- return new ObjectResult(new FailureResponse { Message = "Wallet isn't decrypted" });
+ return new FailureResponse { Message = "Wallet isn't decrypted" };
var trimmed = account;
if (String.Equals(trimmed, "alice", StringComparison.OrdinalIgnoreCase))
{
- return new ObjectResult(new BalancesResponse
- {
- Available = Global.WalletWrapper.GetAvailable(Global.WalletWrapper.AliceAccount).ToString(false, true),
- Incoming = Global.WalletWrapper.GetIncoming(Global.WalletWrapper.AliceAccount).ToString(false, true)
- });
+ safeAccount = Global.WalletWrapper.AliceAccount;
+ return null;
}
else if (String.Equals(trimmed, "bob", StringComparison.OrdinalIgnoreCase))
{
- return new ObjectResult(new BalancesResponse
- {
- Available = Global.WalletWrapper.GetAvailable(Global.WalletWrapper.BobAccount).ToString(false, true),
- Incoming = Global.WalletWrapper.GetIncoming(Global.WalletWrapper.BobAccount).ToString(false, true)
- });
+ safeAccount = Global.WalletWrapper.BobAccount;
+ return null;
+ }
+ else return new FailureResponse { Message = "Wrong account" };
}
- else return new ObjectResult(new FailureResponse { Message = "Wrong account" });
+
+ [Route("receive/{account}")]
+ [HttpGet]
+ public IActionResult Receive(string account)
+ {
+ try
+ {
+ var fail = GetAccount(account, out SafeAccount safeAccount);
+ if (fail != null) return new ObjectResult(fail);
+
+ return new ObjectResult(Global.WalletWrapper.GetReceiveResponse(safeAccount));
}
catch (Exception ex)
{

MODIFY
HiddenWallet/HiddenWallet.API/Wrappers/WalletWrapper.cs
HiddenWallet/HiddenWallet.API/Wrappers/WalletWrapper.cs
@@ -40,6 +40,10 @@ namespace HiddenWallet.API.Wrappers
public Money GetAvailable(SafeAccount account) => account == AliceAccount ? _availableAlice : _availableBob;
public Money GetIncoming(SafeAccount account) => account == AliceAccount ? _incomingAlice : _incomingBob;
+ private ReceiveResponse _receiveAddressesAlice = new ReceiveResponse();
+ private ReceiveResponse _receiveAddressesBob = new ReceiveResponse();
+ public ReceiveResponse GetReceiveResponse(SafeAccount account) => account == AliceAccount ? _receiveAddressesAlice : _receiveAddressesBob;
+
#endregion
public WalletWrapper()
@@ -81,6 +85,8 @@ namespace HiddenWallet.API.Wrappers
_walletJob.Tracker.TrackedTransactions.CollectionChanged += TrackedTransactions_CollectionChanged;
_walletJobTask = _walletJob.StartAsync(_cts.Token);
+
+ UpdateHistoryRelatedMembers();
}
}
@@ -98,10 +104,26 @@ namespace HiddenWallet.API.Wrappers
#region EventSubscriptions
private void TrackedTransactions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
+ {
+ UpdateHistoryRelatedMembers();
+
+ // changeBump
+ if (_changeBump >= 10000)
+ {
+ _changeBump = 0;
+ }
+ else
+ {
+ _changeBump++;
+ }
+ }
+
+ private void UpdateHistoryRelatedMembers()
{
var aliceHistory = _walletJob.GetSafeHistory(AliceAccount);
var bobHistory = _walletJob.GetSafeHistory(BobAccount);
+ // balances
CalculateBalances(aliceHistory, out Money aa, out Money ia);
_availableAlice = aa;
_incomingAlice = ia;
@@ -109,14 +131,18 @@ namespace HiddenWallet.API.Wrappers
_availableBob = ab;
_incomingBob = ib;
- // bump change
- if (_changeBump >= 10000)
- {
- _changeBump = 0;
- }
- else
- {
- _changeBump++;
+ // receive
+ var ua = _walletJob.GetUnusedScriptPubKeys(AliceAccount, HdPathType.Receive).ToArray();
+ var ub = _walletJob.GetUnusedScriptPubKeys(BobAccount, HdPathType.Receive).ToArray();
+ _receiveAddressesAlice.Addresses = new string[7];
+ _receiveAddressesBob.Addresses = new string[7];
+ var network = _walletJob.Safe.Network;
+ for (int i = 0; i < 7; i++)
+ {
+ if (ua[i] != null) _receiveAddressesAlice.Addresses[i] = ua[i].GetDestinationAddress(network).ToWif();
+ else _receiveAddressesAlice.Addresses[i] = "";
+ if (ub[i] != null) _receiveAddressesBob.Addresses[i] = ub[i].GetDestinationAddress(network).ToWif();
+ else _receiveAddressesBob.Addresses[i] = "";
}
}

MODIFY
HiddenWallet/HiddenWallet.GUI/app/css/default.css
HiddenWallet/HiddenWallet.GUI/app/css/default.css
@@ -62,7 +62,8 @@ body {
background-color: #3F3F41;
}
-
-a {
- color: #68217A;
+#content {
+ overflow-y: auto;
+ position: relative;
+ max-height: 340px;
}
\ No newline at end of file

MODIFY
HiddenWallet/HiddenWallet.GUI/app/html/wallet-content.html
HiddenWallet/HiddenWallet.GUI/app/html/wallet-content.html
-<ul id="receive-content" class="list-group">
- <li class="list-group-item">1BoatSLRHtKNngkdXEeobR76b53LETtpyT</li>
- <li class="list-group-item">1BoatSLRHtKNngkdXEeobR76b53LETtpyT</li>
- <li class="list-group-item">1BoatSLRHtKNngkdXEeobR76b53LETtpyT</li>
- <li class="list-group-item">1BoatSLRHtKNngkdXEeobR76b53LETtpyT</li>
- <li class="list-group-item">1BoatSLRHtKNngkdXEeobR76b53LETtpyT</li>
- <li class="list-group-item">1BoatSLRHtKNngkdXEeobR76b53LETtpyT</li>
- <li class="list-group-item">1BoatSLRHtKNngkdXEeobR76b53LETtpyT</li>
+<div id="receive-content">
+ <label>Unused receive addresses:</label>
+ <ul id="receive-addresses" class="list-group">
</ul>
+</div>
\ No newline at end of file

MODIFY
HiddenWallet/HiddenWallet.GUI/app/js/wallet-phase.js
HiddenWallet/HiddenWallet.GUI/app/js/wallet-phase.js
@@ -28,20 +28,18 @@ function walletPhaseShow(tabItem = "") {
walletShow('receive');
document.getElementById("before-menu-br").outerHTML = "";
- document.getElementById("content").innerHTML = "";
- //document.getElementById("content").innerHTML = document.getElementById("wallet-content-frame").contentWindow.document.getElementById("receive-content").outerHTML;
}
function walletShow(menuItem) {
if (menuItem === 'receive') {
- document.getElementById("menu").innerHTML = document.getElementById("wallet-menu-frame").contentWindow.document.getElementById("receive-active").innerHTML;
+ document.getElementById("menu").innerHTML = document.getElementById("wallet-menu-frame").contentWindow.document.getElementById("receive-active").outerHTML;
}
else if (menuItem === 'send') {
writeHint('Would you consider feeding the developer with some pizza? 186n7me3QKajQZJnUsVsezVhVrSwyFCCZ');
- document.getElementById("menu").innerHTML = document.getElementById("wallet-menu-frame").contentWindow.document.getElementById("send-active").innerHTML;
+ document.getElementById("menu").innerHTML = document.getElementById("wallet-menu-frame").contentWindow.document.getElementById("send-active").outerHTML;
}
else if (menuItem === 'history') {
- document.getElementById("menu").innerHTML = document.getElementById("wallet-menu-frame").contentWindow.document.getElementById("history-active").innerHTML;
+ document.getElementById("menu").innerHTML = document.getElementById("wallet-menu-frame").contentWindow.document.getElementById("history-active").outerHTML;
writeHint('HiddenWallet? Easy Peasy Lemon Squeezey!');
}
@@ -55,11 +53,53 @@ function updateWalletContent() {
if (bobOrAlice == "alice-active") {
var resp = httpGetWallet("balances/alice");
- document.getElementById("balances").innerHTML = '<h4><span class="label label-default" style="display:block;">Available: ' + resp.Available + ' BTC, Incoming: ' + resp.Incoming + ' BTC </span></h4>';
+ var labelType = "default";
+ if (resp.Incoming > 0) labelType = "danger";
+ document.getElementById("balances").innerHTML = '<h4><span class="label label-' + labelType + '" style="display:block;">Available: ' + resp.Available + ' BTC, Incoming: ' + resp.Incoming + ' BTC </span></h4>';
+
+ var menu = document.getElementById("menu");
+ if (menu.childElementCount > 0) {
+ var menuId = menu.firstElementChild.id;
+ if (menuId === "receive-active") {
+ document.getElementById("content").innerHTML = document.getElementById("wallet-content-frame").contentWindow.document.getElementById("receive-content").outerHTML;
+ var resp = httpGetWallet("receive/alice");
+ for (i = 0; i < 7; i++) {
+ var node = document.createElement("li");
+ node.setAttribute("class", "list-group-item");
+ var textNode = document.createTextNode(resp.Addresses[i]);
+ node.appendChild(textNode);
+ document.getElementById("receive-addresses").appendChild(node);
+ }
+ }
+ else if (menuId === "send-active") {
+ }
+ else if (menuId === "history-active") {
+ }
+ }
}
else if (bobOrAlice == "bob-active") {
var resp = httpGetWallet("balances/bob");
document.getElementById("balances").innerHTML = '<h4><span class="label label-default" style="display:block;">Available: ' + resp.Available + ' BTC, Incoming: ' + resp.Incoming + ' BTC </span></h4>';
+
+ var menu = document.getElementById("menu");
+ if (menu.childElementCount > 0) {
+ var menuId = menu.firstElementChild.id;
+ if (menuId === "receive-active") {
+ document.getElementById("content").innerHTML = document.getElementById("wallet-content-frame").contentWindow.document.getElementById("receive-content").outerHTML;
+ var resp = httpGetWallet("receive/bob");
+ for (i = 0; i < 7; i++) {
+ var node = document.createElement("li");
+ node.setAttribute("class", "list-group-item");
+ var textNode = document.createTextNode(resp.Addresses[i]);
+ node.appendChild(textNode);
+ document.getElementById("receive-addresses").appendChild(node);
+ }
+ }
+ else if (menuId === "send-active") {
+ }
+ else if (menuId === "history-active") {
+ }
+ }
}
}
}
\ No newline at end of file

Implement receive