Skip to content

Commit

Permalink
wallet: ignore old auction bids when calculating stats
Browse files Browse the repository at this point in the history
  • Loading branch information
rithvikvibhu committed Jul 27, 2022
1 parent 4a4ac98 commit 9b587aa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/background/wallet/stats.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { states } = require("hsd/lib/covenants/namestate");

/** @param {import('hsd/lib/wallet/wallet')} wallet */
async function fromBids(wallet) {
const height = wallet.wdb.height;
const network = wallet.network;
Expand Down Expand Up @@ -30,6 +31,12 @@ async function fromBids(wallet) {
const ns = await wallet.getNameState(bid.nameHash);
const state = ns.state(height, network);

// Only consider bids from the latest auction (is local?)
const bidTx = await wallet.getTX(bid.prevout.hash);
if (bidTx.height < ns.height) {
continue;
}

// Full bid + blind is locked up in the bidding phase
if (state === states.BIDDING) {
biddingNum++;
Expand Down Expand Up @@ -87,6 +94,7 @@ async function fromBids(wallet) {
};
}

/** @param {import('hsd/lib/wallet/wallet')} wallet */
async function fromReveals(wallet) {
const height = wallet.wdb.height;
const network = wallet.network;
Expand Down Expand Up @@ -145,6 +153,7 @@ async function fromReveals(wallet) {
};
}

/** @param {import('hsd/lib/wallet/wallet')} wallet */
async function fromNames(wallet) {
const height = wallet.wdb.height;
const network = wallet.network;
Expand Down Expand Up @@ -236,6 +245,7 @@ async function fromNames(wallet) {
};
}

/** @param {import('hsd/lib/wallet/wallet')} wallet */
export async function getStats(wallet) {
const [statsFromBids, statsFromReveals, statsFromNames] = await Promise.all([
fromBids(wallet),
Expand Down

0 comments on commit 9b587aa

Please sign in to comment.