Skip to content

Commit 7ffa091

Browse files
committed
fix: persist node id of peer for swapped order
This fixes a bug where the node id of the peer with whom we swapped is missing when persisting a swapped order to the database.
1 parent 4f881cb commit 7ffa091

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

Diff for: lib/orderbook/OrderBook.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,12 @@ class OrderBook extends EventEmitter {
546546
*/
547547
public executeSwap = async (maker: PeerOrder, taker: OwnOrder): Promise<SwapSuccess> => {
548548
// make sure the order is in the database before we begin the swap
549-
await this.repository.addOrderIfNotExists(maker);
549+
if (!(await this.repository.getOrder(maker.id))) {
550+
await this.repository.addOrderIfNotExists({
551+
...maker,
552+
nodeId: this.pool.getNodeId(maker.peerPubKey),
553+
});
554+
}
550555
try {
551556
const swapResult = await this.swaps.executeSwap(maker, taker);
552557
this.emit('peerOrder.filled', maker);
@@ -583,6 +588,7 @@ class OrderBook extends EventEmitter {
583588
if (takerOrder) {
584589
addOrderPromises.push(this.repository.addOrderIfNotExists(takerOrder));
585590
}
591+
586592
await Promise.all(addOrderPromises);
587593
await this.repository.addTrade({
588594
quantity,

Diff for: lib/orderbook/OrderBookRepository.ts

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ class OrderbookRepository {
4848
}
4949
}
5050

51+
public getOrder = (id: string) => {
52+
return this.models.Order.findOne({
53+
where: { id },
54+
});
55+
}
56+
5157
public addTrade = (trade: db.TradeFactory) => {
5258
return this.models.Trade.create(trade);
5359
}

Diff for: lib/p2p/NodeList.ts

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class NodeList extends EventEmitter {
5252
this.nodes.forEach(callback);
5353
}
5454

55+
public getId = (nodePubKey: string) => {
56+
return this.nodes.get(nodePubKey)?.id;
57+
}
58+
5559
/**
5660
* Return list of public keys of all banned nodes with a given alias.
5761
*/

Diff for: lib/p2p/Pool.ts

+4
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ class Pool extends EventEmitter {
153153
return this.nodeState.tokenIdentifiers[currency];
154154
}
155155

156+
public getNodeId = (nodePubKey: string) => {
157+
return this.nodes.getId(nodePubKey);
158+
}
159+
156160
/**
157161
* Initialize the Pool by connecting to known nodes and listening to incoming peer connections, if configured to do so.
158162
*/

0 commit comments

Comments
 (0)