Skip to content

Commit

Permalink
auction: only pick bids from latest auction (#506)
Browse files Browse the repository at this point in the history
  • Loading branch information
rithvikvibhu committed Jun 30, 2022
1 parent d8eb131 commit bc93245
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions app/ducks/names.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export const getNameInfo = name => async (dispatch) => {
try {
const auctionInfo = await walletClient.getAuctionInfo(name);
walletHasName = true;
bids = await inflateBids(nodeClient, walletClient, auctionInfo.bids, info.height);
reveals = await inflateReveals(nodeClient, walletClient, auctionInfo.reveals, info.height);
bids = await inflateBids(auctionInfo.bids, info.height);
reveals = await inflateReveals(auctionInfo.reveals, info.height);
} catch (e) {
if (!e.message.match(/auction not found/i)) {
throw e;
Expand Down Expand Up @@ -144,7 +144,7 @@ export const getNameInfo = name => async (dispatch) => {
});
};

async function inflateBids(nClient, walletClient, bids) {
async function inflateBids(bids, nameHeight) {
if (!bids.length) {
return [];
}
Expand All @@ -156,6 +156,9 @@ async function inflateBids(nClient, walletClient, bids) {

if (!res) continue;

// Ignore bids from previous auctions
if (res.height < nameHeight) continue;

const tx = res;
const out = tx.outputs[bid.prevout.index];

Expand All @@ -171,24 +174,27 @@ async function inflateBids(nClient, walletClient, bids) {
return ret;
}

async function inflateReveals(nClient, walletClient, bids) {
if (!bids.length) {
async function inflateReveals(reveals, nameHeight) {
if (!reveals.length) {
return [];
}

const ret = [];
for (const bid of bids) {
for (const reveal of reveals) {
// Must use node client to get non-own reveals
const res = await nodeClient.getTx(bid.prevout.hash);
const res = await nodeClient.getTx(reveal.prevout.hash);

if (!res) continue;

// Ignore reveals from previous auctions
if (res.height < nameHeight) continue;

const tx = res;
const out = tx.outputs[bid.prevout.index];
const coin = await walletClient.getCoin(bid.prevout.hash, bid.prevout.index);
const out = tx.outputs[reveal.prevout.index];
const coin = await walletClient.getCoin(reveal.prevout.hash, reveal.prevout.index);

ret.push({
bid,
bid: reveal, // yes, it really is reveal
from: out.address,
date: tx.mtime * 1000,
value: out.value,
Expand Down

0 comments on commit bc93245

Please sign in to comment.