Skip to content

Commit

Permalink
http: websocket events for auctions
Browse files Browse the repository at this point in the history
Emit events over websocket for auction
related events that are emitted by the
walletdb.
  • Loading branch information
Mark Tyneway committed Jun 22, 2019
1 parent 0988cef commit 9042ed9
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/wallet/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,21 @@ class HTTP extends Server {
this.to('w:*', event, wallet.id, json);
};

const handleCovenant = (event, wallet, ns, details) => {
const name = `w:${wallet.id}`;

if (!this.channel(name) && !this.channel('w:*'))
return;

const json = details.getJSON(this.network, this.wdb.height);

if (this.channel(name))
this.to(name, event, wallet.id, ns, json);

if (this.channel('w:*'))
this.to('w:*', event, wallet.id, ns, json);
};

this.wdb.on('tx', (wallet, tx, details) => {
handleTX('tx', wallet, tx, details);
});
Expand Down Expand Up @@ -1351,6 +1366,16 @@ class HTTP extends Server {
if (this.channel('w:*'))
this.to('w:*', 'address', wallet.id, json);
});

// set up listener for each covenant type
for (const type of Object.values(rules.typesByVal))
if (type !== 'NONE') {
const action = type.toLowerCase();
const channel = `${action} covenant`;
this.wdb.on(channel, (wallet, data, details) => {
handleCovenant(channel, wallet, data, details);
});
}
}

/**
Expand Down

0 comments on commit 9042ed9

Please sign in to comment.