Skip to content

Commit

Permalink
fix: alias missing in streamorders (#1725)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsercano committed Oct 27, 2020
1 parent 41d103c commit 6699e62
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const createOrder = (order: Order) => {
} else {
const nodeIdentifier = new xudrpc.NodeIdentifier();
nodeIdentifier.setNodePubKey(order.peerPubKey);
nodeIdentifier.setAlias(order.alias);
grpcOrder.setNodeIdentifier(nodeIdentifier);
grpcOrder.setIsOwnOrder(false);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/orderbook/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ type Local = {
/** Properties that apply only to orders placed by remote peers. */
type Remote = {
/** The nodePubKey of the node which created this order. */
peerPubKey: string;
peerPubKey: string,
/** The alias of the node which created this order. */
alias: string;
};

/** Properties that uniquely identify an order and make it ready to enter the order book. */
Expand Down
4 changes: 2 additions & 2 deletions lib/p2p/Pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ class Pool extends EventEmitter {
this.emit('packet.orderInvalidation', orderInvalidation, peer.nodePubKey!);
}

const incomingOrder: IncomingOrder = { ...receivedOrder, peerPubKey: peer.nodePubKey! };
const incomingOrder: IncomingOrder = { ...receivedOrder, peerPubKey: peer.nodePubKey!, alias: peer.alias! };
this.emit('packet.order', incomingOrder);
} else {
this.logger.debug(`received order ${id} for deactivated trading pair`);
Expand Down Expand Up @@ -809,7 +809,7 @@ class Pool extends EventEmitter {
this.logger.debug(`received ${receivedOrders.length} orders from ${peer.label}`);
receivedOrders.forEach((order) => {
if (peer.isPairActive(order.pairId)) {
this.emit('packet.order', { ...order, peerPubKey: peer.nodePubKey! });
this.emit('packet.order', { ...order, peerPubKey: peer.nodePubKey!, alias: peer.alias! });
} else {
this.logger.debug(`received order ${order.id} for deactivated trading pair`);
}
Expand Down
11 changes: 9 additions & 2 deletions lib/service/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,20 @@ class Service extends EventEmitter {
cancelled$: Observable<void>,
) => {
if (args.existing) {
function setAlias(pool: Pool) {
return (order: PeerOrder) => {
order.alias = pool.getNodeAlias(order.peerPubKey)!;
callback(order);
};
}

this.orderBook.pairIds.forEach((pair) => {
const ownOrders = this.orderBook.getOwnOrders(pair);
const peerOrders = this.orderBook.getPeersOrders(pair);
ownOrders.buyArray.forEach(order => callback(order));
peerOrders.buyArray.forEach(order => callback(order));
peerOrders.buyArray.forEach(setAlias(this.pool));
ownOrders.sellArray.forEach(order => callback(order));
peerOrders.sellArray.forEach(order => callback(order));
peerOrders.sellArray.forEach(setAlias(this.pool));
});
}

Expand Down
2 changes: 2 additions & 0 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const createPeerOrder = (
isBuy: boolean,
createdAt = ms(),
peerPubKey = '029a96c975d301c1c8787fcb4647b5be65a3b8d8a70153ff72e3eac73759e5e345',
alias = 'test_alias',
pairId = 'LTC/BTC',
): PeerOrder => ({
quantity,
Expand All @@ -87,6 +88,7 @@ export const createPeerOrder = (
pairId,
createdAt,
peerPubKey,
alias,
initialQuantity: quantity,
id: uuidv1(),
});
Expand Down

0 comments on commit 6699e62

Please sign in to comment.