Implement history
MODIFY
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
HiddenWallet/HiddenWallet.API/Controllers/WalletController.cs
@@ -198,5 +198,22 @@ namespace HiddenWallet.API.Controllers
return new ObjectResult(new FailureResponse { Message = ex.Message, Details = ex.ToString() });
}
}
+
+ [Route("history/{account}")]
+ [HttpGet]
+ public IActionResult History(string account)
+ {
+ try
+ {
+ var fail = GetAccount(account, out SafeAccount safeAccount);
+ if (fail != null) return new ObjectResult(fail);
+
+ return new ObjectResult(Global.WalletWrapper.GetHistoryResponse(safeAccount));
+ }
+ 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
@@ -44,6 +44,9 @@ namespace HiddenWallet.API.Wrappers
private ReceiveResponse _receiveAddressesBob = new ReceiveResponse();
public ReceiveResponse GetReceiveResponse(SafeAccount account) => account == AliceAccount ? _receiveAddressesAlice : _receiveAddressesBob;
+ private HistoryResponse _historyResponseAlice = new HistoryResponse();
+ private HistoryResponse _historyResponseBob = new HistoryResponse();
+ public HistoryResponse GetHistoryResponse(SafeAccount account) => account == AliceAccount ? _historyResponseAlice : _historyResponseBob;
#endregion
public WalletWrapper()
@@ -120,8 +123,48 @@ namespace HiddenWallet.API.Wrappers
private void UpdateHistoryRelatedMembers()
{
- var aliceHistory = _walletJob.GetSafeHistory(AliceAccount);
- var bobHistory = _walletJob.GetSafeHistory(BobAccount);
+ // history
+ var aliceHistory = _walletJob.GetSafeHistory(AliceAccount).OrderByDescending(x=> x.TimeStamp);
+ var bobHistory = _walletJob.GetSafeHistory(BobAccount).OrderByDescending(x => x.TimeStamp);
+
+ var hra = new List<HistoryRecordModel>();
+ foreach (var rec in aliceHistory)
+ {
+ string height;
+ if (rec.BlockHeight.Type == HeightType.Chain)
+ {
+ height = rec.BlockHeight.Value.ToString();
+ }
+ else height = "";
+
+ hra.Add(new HistoryRecordModel {
+ Amount = rec.Amount.ToString(true, true),
+ Confirmed = rec.Confirmed,
+ Height = height,
+ TxId = rec.TransactionId.ToString()
+ });
+ }
+ _historyResponseAlice.History = hra.ToArray();
+
+ var hrb = new List<HistoryRecordModel>();
+ foreach (var rec in bobHistory)
+ {
+ string height;
+ if (rec.BlockHeight.Type == HeightType.Chain)
+ {
+ height = rec.BlockHeight.Value.ToString();
+ }
+ else height = "";
+
+ hrb.Add(new HistoryRecordModel
+ {
+ Amount = rec.Amount.ToString(true, true),
+ Confirmed = rec.Confirmed,
+ Height = height,
+ TxId = rec.TransactionId.ToString()
+ });
+ }
+ _historyResponseBob.History = hrb.ToArray();
// balances
CalculateBalances(aliceHistory, out Money aa, out Money ia);
@@ -174,6 +217,7 @@ namespace HiddenWallet.API.Wrappers
{
_walletState = _walletJob.State.ToString();
}
+
#endregion
public async Task EndAsync()

MODIFY
HiddenWallet/HiddenWallet.GUI/app/html/wallet-content.html
HiddenWallet/HiddenWallet.GUI/app/html/wallet-content.html
<ul id="receive-addresses" class="list-group">
</ul>
</div>
+
+<div id="history-content">
+ <table class="table table-striped">
+ <thead>
+ <tr>
+ <th>Block Height</th>
+ <th>Amount</th>
+ <th>Transaction ID</th>
+ </tr>
+ </thead>
+ <tbody id="history-records">
+ </tbody>
+ </table>
+</div>
\ No newline at end of file

MODIFY
HiddenWallet/HiddenWallet.GUI/app/js/wallet-phase.js
HiddenWallet/HiddenWallet.GUI/app/js/wallet-phase.js
@@ -70,10 +70,32 @@ function updateWalletContent() {
node.appendChild(textNode);
document.getElementById("receive-addresses").appendChild(node);
}
+ //for (i = 0; i < resp.Addresses.length; i++) {
+ // var trNode = document.createElement("tr");
+ // var tdNode = document.createElement("td");
+ // tdNode.innerText = resp.Addresses[i];
+ // trNode.appendChild(tdNode);
+ // document.getElementById("receive-addresses").appendChild(trNode);
+ //}
}
else if (menuId === "send-active") {
}
else if (menuId === "history-active") {
+ document.getElementById("content").innerHTML = document.getElementById("wallet-content-frame").contentWindow.document.getElementById("history-content").outerHTML;
+ var resp = httpGetWallet("history/alice");
+ for (i = 0; i < resp.History.length; i++) {
+ var trNode = document.createElement("tr");
+ var tdNodeHeight = document.createElement("td");
+ tdNodeHeight.innerText = resp.History[i].Height;
+ var tdNodeAmount = document.createElement("td");
+ tdNodeAmount.innerText = resp.History[i].Amount;
+ var tdNodeTxId = document.createElement("td");
+ tdNodeTxId.innerText = resp.History[i].TxId;
+ trNode.appendChild(tdNodeHeight);
+ trNode.appendChild(tdNodeAmount);
+ trNode.appendChild(tdNodeTxId);
+ document.getElementById("history-records").appendChild(trNode);
+ }
}
}
}
@@ -98,6 +120,21 @@ function updateWalletContent() {
else if (menuId === "send-active") {
}
else if (menuId === "history-active") {
+ document.getElementById("content").innerHTML = document.getElementById("wallet-content-frame").contentWindow.document.getElementById("history-content").outerHTML;
+ var resp = httpGetWallet("history/bob");
+ for (i = 0; i < resp.History.length; i++) {
+ var trNode = document.createElement("tr");
+ var tdNodeHeight = document.createElement("td");
+ tdNodeHeight.innerText = resp.History[i].Height;
+ var tdNodeAmount = document.createElement("td");
+ tdNodeAmount.innerText = resp.History[i].Amount;
+ var tdNodeTxId = document.createElement("td");
+ tdNodeTxId.innerText = resp.History[i].TxId;
+ trNode.appendChild(tdNodeHeight);
+ trNode.appendChild(tdNodeAmount);
+ trNode.appendChild(tdNodeTxId);
+ document.getElementById("history-records").appendChild(trNode);
+ }
}
}
}

Implement history