Skip to content

Commit e007f14

Browse files
author
Mark Tyneway
committed
http: websocket events for auctions
Emit events over websocket for auction related events that are emitted by the walletdb.
1 parent 9722b5c commit e007f14

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/wallet/http.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,21 @@ class HTTP extends Server {
13031303
this.to('w:*', event, wallet.id, json);
13041304
};
13051305

1306+
const handleCovenant = (event, wallet, ns, details) => {
1307+
const name = `w:${wallet.id}`;
1308+
1309+
if (!this.channel(name) && !this.channel('w:*'))
1310+
return;
1311+
1312+
const json = details.getJSON(this.network, this.wdb.height);
1313+
1314+
if (this.channel(name))
1315+
this.to(name, event, wallet.id, ns, json);
1316+
1317+
if (this.channel('w:*'))
1318+
this.to('w:*', event, wallet.id, ns, json);
1319+
};
1320+
13061321
this.wdb.on('tx', (wallet, tx, details) => {
13071322
handleTX('tx', wallet, tx, details);
13081323
});
@@ -1351,6 +1366,16 @@ class HTTP extends Server {
13511366
if (this.channel('w:*'))
13521367
this.to('w:*', 'address', wallet.id, json);
13531368
});
1369+
1370+
// set up listener for each covenant type
1371+
for (const type of Object.values(rules.typesByVal))
1372+
if (type !== 'NONE') {
1373+
const action = type.toLowerCase();
1374+
const channel = `${action} covenant`;
1375+
this.wdb.on(channel, (wallet, data, details) => {
1376+
handleCovenant(channel, wallet, data, details);
1377+
});
1378+
}
13541379
}
13551380

13561381
/**

0 commit comments

Comments
 (0)