From ba71088b7ac4eae6ea0ce867679391c9faf14e15 Mon Sep 17 00:00:00 2001 From: Daniel McNally Date: Wed, 19 Sep 2018 00:36:19 -0400 Subject: [PATCH] feat(rpc): add new order events rpc subscriptions This commit replaces the old streaming rpc subscription calls with three new streaming rpc calls: - subscribeAddedOrders: Notifies when orders are added to the order book. - subscribeRemovedOrders: Notifies when orders are removed from the order book. - subscribeSwaps: Notifies when swaps that are initiated by a remote user are completed. It also restructures and updates the `Order` grpc message type. Closes #123. --- docs/api.md | 100 +- lib/cli/commands/subscribeorders.ts | 24 + lib/cli/commands/subscribepeerorders.ts | 15 - lib/cli/commands/subscribeswaps.ts | 15 - lib/grpc/GrpcServer.ts | 3 +- lib/grpc/GrpcService.ts | 61 +- lib/orderbook/MatchingEngine.ts | 21 +- lib/orderbook/OrderBook.ts | 42 +- lib/p2p/Pool.ts | 8 +- .../packets/types/OrderInvalidationPacket.ts | 4 +- lib/proto/xudrpc.swagger.json | 115 +- lib/proto/xudrpc_grpc_pb.d.ts | 47 +- lib/proto/xudrpc_grpc_pb.js | 92 +- lib/proto/xudrpc_pb.d.ts | 193 +-- lib/proto/xudrpc_pb.js | 1299 +++++++++-------- lib/service/Service.ts | 36 +- lib/swaps/Swaps.ts | 25 +- lib/types/orders.ts | 16 +- proto/xudrpc.proto | 119 +- test/unit/MatchingEngine.spec.ts | 8 +- 20 files changed, 1300 insertions(+), 943 deletions(-) create mode 100644 lib/cli/commands/subscribeorders.ts delete mode 100644 lib/cli/commands/subscribepeerorders.ts delete mode 100644 lib/cli/commands/subscribeswaps.ts diff --git a/docs/api.md b/docs/api.md index 256e34232..41eabbd64 100644 --- a/docs/api.md +++ b/docs/api.md @@ -33,6 +33,7 @@ - [LndInfo](#xudrpc.LndInfo) - [Order](#xudrpc.Order) - [OrderMatch](#xudrpc.OrderMatch) + - [OrderRemoval](#xudrpc.OrderRemoval) - [Orders](#xudrpc.Orders) - [OrdersCount](#xudrpc.OrdersCount) - [Peer](#xudrpc.Peer) @@ -45,11 +46,10 @@ - [RemovePairResponse](#xudrpc.RemovePairResponse) - [ShutdownRequest](#xudrpc.ShutdownRequest) - [ShutdownResponse](#xudrpc.ShutdownResponse) - - [SubscribePeerOrdersRequest](#xudrpc.SubscribePeerOrdersRequest) - - [SubscribePeerOrdersResponse](#xudrpc.SubscribePeerOrdersResponse) + - [SubscribeAddedOrdersRequest](#xudrpc.SubscribeAddedOrdersRequest) + - [SubscribeRemovedOrdersRequest](#xudrpc.SubscribeRemovedOrdersRequest) - [SubscribeSwapsRequest](#xudrpc.SubscribeSwapsRequest) - - [SubscribeSwapsResponse](#xudrpc.SubscribeSwapsResponse) - - [SwapPayload](#xudrpc.SwapPayload) + - [Swap](#xudrpc.Swap) - [AddCurrencyRequest.SwapClient](#xudrpc.AddCurrencyRequest.SwapClient) - [OrderSide](#xudrpc.OrderSide) @@ -461,16 +461,15 @@ | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| price | [double](#double) | | The price of the order, precise to 6 decimal places. | -| quantity | [double](#double) | | The quantity of the order, precise to 6 decimal places. | -| pair_id | [string](#string) | | The trading pair that this order is for | -| peer_pub_key | [string](#string) | | The node pub key of the peer that created this order | -| id | [string](#string) | | A UUID for this order | -| local_id | [string](#string) | | The local id for this order | -| created_at | [int64](#int64) | | The epoch time when this order was created | -| invoice | [string](#string) | | Lightning invoice | -| canceled | [bool](#bool) | | Indicates whether an order was canceled | -| side | [OrderSide](#xudrpc.OrderSide) | | Whether the order is a Buy or Sell | +| price | [double](#double) | | The price of the order. | +| quantity | [double](#double) | | The quantity of the order. | +| pair_id | [string](#string) | | The trading pair that this order is for. | +| id | [string](#string) | | A UUID for this order. | +| peer_pub_key | [string](#string) | | The node pub key of the peer that created this order. | +| local_id | [string](#string) | | The local id for this order. | +| created_at | [int64](#int64) | | The epoch time when this order was created. | +| side | [OrderSide](#xudrpc.OrderSide) | | Whether this order is a buy or sell | +| is_own_order | [bool](#bool) | | Whether this order is a local own order or a remote peer order. | @@ -493,6 +492,25 @@ + + +### OrderRemoval + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| quantity | [double](#double) | | The quantity of the order being removed. | +| pair_id | [string](#string) | | The trading pair that the order is for. | +| order_id | [string](#string) | | The global UUID for the order. | +| local_id | [string](#string) | | The local id for the order, if applicable. | +| is_own_order | [bool](#bool) | | Whether the order being removed is a local own order or a remote peer order. | + + + + + + ### Orders @@ -553,8 +571,8 @@ | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| price | [double](#double) | | The price of the order, precise to 6 decimal places. | -| quantity | [double](#double) | | The quantity of the order, precise to 6 decimal places. | +| price | [double](#double) | | The price of the order. | +| quantity | [double](#double) | | The quantity of the order. | | pair_id | [string](#string) | | The trading pair that the order is for | | order_id | [string](#string) | | The local id to assign to the order | | side | [OrderSide](#xudrpc.OrderSide) | | Whether the order is a Buy or Sell | @@ -668,25 +686,20 @@ - - -### SubscribePeerOrdersRequest - + +### SubscribeAddedOrdersRequest - -### SubscribePeerOrdersResponse + +### SubscribeRemovedOrdersRequest -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| order | [Order](#xudrpc.Order) | | | @@ -703,35 +716,21 @@ - + -### SubscribeSwapsResponse +### Swap | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| order | [string](#string) | | The order which was executed for the swap with updated remaining quantity | - - - - - - - - -### SwapPayload - - - -| Field | Type | Label | Description | -| ----- | ---- | ----- | ----------- | -| role | [string](#string) | | | -| sending_amount | [uint64](#uint64) | | | -| sending_token | [string](#string) | | | -| receiving_amount | [uint64](#uint64) | | | -| receiving_token | [string](#string) | | | -| node_pub_key | [string](#string) | | | +| order_id | [string](#string) | | The global UUID for the order that was swapped. | +| local_id | [string](#string) | | The local id for the order that was swapped. | +| pair_id | [string](#string) | | The trading pair that this order is for. | +| r_hash | [string](#string) | | The hex-encoded r_hash for the swap payments. | +| amount_received | [int64](#int64) | | The amount of subunits (satoshis) received. | +| amount_sent | [int64](#int64) | | The amount of subunits (satoshis) sent. | +| peer_pub_key | [string](#string) | | The node pub key of the peer that executed this order. | @@ -790,8 +789,9 @@ | RemoveCurrency | [RemoveCurrencyRequest](#xudrpc.RemoveCurrencyRequest) | [RemoveCurrencyResponse](#xudrpc.RemoveCurrencyResponse) | Remove a currency. | | RemovePair | [RemovePairRequest](#xudrpc.RemovePairRequest) | [RemovePairResponse](#xudrpc.RemovePairResponse) | Remove a trading pair. | | Shutdown | [ShutdownRequest](#xudrpc.ShutdownRequest) | [ShutdownResponse](#xudrpc.ShutdownResponse) | Begin shutting down xud. | -| SubscribePeerOrders | [SubscribePeerOrdersRequest](#xudrpc.SubscribePeerOrdersRequest) | [SubscribePeerOrdersResponse](#xudrpc.SubscribePeerOrdersResponse) stream | Subscribe to peer order events. | -| SubscribeSwaps | [SubscribeSwapsRequest](#xudrpc.SubscribeSwapsRequest) | [SubscribeSwapsResponse](#xudrpc.SubscribeSwapsResponse) stream | Subscribe executed swaps. | +| SubscribeAddedOrders | [SubscribeAddedOrdersRequest](#xudrpc.SubscribeAddedOrdersRequest) | [Order](#xudrpc.Order) stream | Subscribe to orders being added to the order book. | +| SubscribeRemovedOrders | [SubscribeRemovedOrdersRequest](#xudrpc.SubscribeRemovedOrdersRequest) | [OrderRemoval](#xudrpc.OrderRemoval) stream | Subscribe to orders being removed from the order book. | +| SubscribeSwaps | [SubscribeSwapsRequest](#xudrpc.SubscribeSwapsRequest) | [Swap](#xudrpc.Swap) stream | Subscribe to completed swaps that are initiated by a remote peer. Sentence 2. Sentence 3. | diff --git a/lib/cli/commands/subscribeorders.ts b/lib/cli/commands/subscribeorders.ts new file mode 100644 index 000000000..6012bdf1e --- /dev/null +++ b/lib/cli/commands/subscribeorders.ts @@ -0,0 +1,24 @@ +import { loadXudClient } from '../command'; +import { Arguments } from 'yargs'; +import { SubscribeAddedOrdersRequest, Order, SubscribeRemovedOrdersRequest, SubscribeSwapsRequest, Swap, OrderRemoval } from '../../proto/xudrpc_pb'; + +export const command = 'streamorders'; + +export const describe = 'stream order added, removed, and swapped events (DEMO)'; + +export const handler = (argv: Arguments) => { + const addedOrdersSubscription = loadXudClient(argv).subscribeAddedOrders(new SubscribeAddedOrdersRequest()); + addedOrdersSubscription.on('data', (order: Order) => { + console.log(`Order added: ${JSON.stringify(order.toObject())}`); + }); + + const removedOrdersSubscription = loadXudClient(argv).subscribeRemovedOrders(new SubscribeRemovedOrdersRequest()); + removedOrdersSubscription.on('data', (orderRemoval: OrderRemoval) => { + console.log(`Order removed: ${JSON.stringify(orderRemoval.toObject())}`); + }); + + const swapsSubscription = loadXudClient(argv).subscribeSwaps(new SubscribeSwapsRequest()); + swapsSubscription.on('data', (swap: Swap) => { + console.log(`Order swapped: ${JSON.stringify(swap.toObject())}`); + }); +}; diff --git a/lib/cli/commands/subscribepeerorders.ts b/lib/cli/commands/subscribepeerorders.ts deleted file mode 100644 index fb45aa010..000000000 --- a/lib/cli/commands/subscribepeerorders.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { loadXudClient } from '../command'; -import { Arguments } from 'yargs'; -import { SubscribePeerOrdersRequest, SubscribePeerOrdersResponse } from '../../proto/xudrpc_pb'; - -export const command = 'subscribepeerorders'; - -export const describe = 'subscribe to peer order events'; - -export const handler = (argv: Arguments) => { - const request = new SubscribePeerOrdersRequest(); - const call = loadXudClient(argv).subscribePeerOrders(request); - call.on('data', (message: SubscribePeerOrdersResponse) => { - console.log(message.toObject()); - }); -}; diff --git a/lib/cli/commands/subscribeswaps.ts b/lib/cli/commands/subscribeswaps.ts deleted file mode 100644 index 4145f0aec..000000000 --- a/lib/cli/commands/subscribeswaps.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { loadXudClient } from '../command'; -import { Arguments } from 'yargs'; -import { SubscribeSwapsRequest, SubscribeSwapsResponse } from '../../proto/xudrpc_pb'; - -export const command = 'subscribeswaps'; - -export const describe = 'subscribe to executed swaps'; - -export const handler = (argv: Arguments) => { - const request = new SubscribeSwapsRequest(); - const call = loadXudClient(argv).subscribeSwaps(request); - call.on('data', (message: SubscribeSwapsResponse) => { - console.log(message.toObject()); - }); -}; diff --git a/lib/grpc/GrpcServer.ts b/lib/grpc/GrpcServer.ts index f1646f644..12bfc18bd 100644 --- a/lib/grpc/GrpcServer.ts +++ b/lib/grpc/GrpcServer.ts @@ -30,7 +30,8 @@ class GrpcServer { removeCurrency: grpcService.removeCurrency, removePair: grpcService.removePair, shutdown: grpcService.shutdown, - subscribePeerOrders: grpcService.subscribePeerOrders, + subscribeAddedOrders: grpcService.subscribeAddedOrders, + subscribeRemovedOrders: grpcService.subscribeRemovedOrders, subscribeSwaps: grpcService.subscribeSwaps, }); diff --git a/lib/grpc/GrpcService.ts b/lib/grpc/GrpcService.ts index c3076567e..7672a13a1 100644 --- a/lib/grpc/GrpcService.ts +++ b/lib/grpc/GrpcService.ts @@ -4,7 +4,7 @@ import Logger from '../Logger'; import Service from '../service/Service'; import * as xudrpc from '../proto/xudrpc_pb'; import { ResolveRequest, ResolveResponse } from '../proto/lndrpc_pb'; -import { StampedPeerOrder, StampedOrder, StampedOwnOrder } from '../types/orders'; +import { StampedOrder, isOwnOrder, OrderPortion, SwapResult } from '../types/orders'; import { errorCodes as orderErrorCodes } from '../orderbook/errors'; import { errorCodes as serviceErrorCodes } from '../service/errors'; import { errorCodes as p2pErrorCodes } from '../p2p/errors'; @@ -12,16 +12,20 @@ import { errorCodes as lndErrorCodes } from '../lndclient/errors'; import { LndInfo } from '../lndclient/LndClient'; /** - * Convert a [[StampedOrder]] to an xudrpc Order message. + * Creates an xudrpc Order message from a [[StampedOrder]]. */ -const getOrder = (order: StampedOrder) => { +const createOrder = (order: StampedOrder) => { const grpcOrder = new xudrpc.Order(); - grpcOrder.setCanceled(false); grpcOrder.setCreatedAt(order.createdAt); grpcOrder.setId(order.id); - grpcOrder.setLocalId((order as StampedOwnOrder).localId); + if (isOwnOrder(order)) { + grpcOrder.setLocalId((order).localId); + grpcOrder.setIsOwnOrder(true); + } else { + grpcOrder.setPeerPubKey((order).peerPubKey); + grpcOrder.setIsOwnOrder(false); + } grpcOrder.setPairId(order.pairId); - grpcOrder.setPeerPubKey((order as StampedPeerOrder).peerPubKey); grpcOrder.setPrice(order.price); grpcOrder.setQuantity(order.quantity); grpcOrder.setSide(order.isBuy ? xudrpc.OrderSide.BUY : xudrpc.OrderSide.SELL); @@ -228,7 +232,7 @@ class GrpcService { const getOrdersList = (orders: T[]) => { const ordersList: xudrpc.Order[] = []; - orders.forEach(order => ordersList.push(getOrder(order))); + orders.forEach(order => ordersList.push(createOrder(order))); return ordersList; }; @@ -312,14 +316,14 @@ class GrpcService { const matchesList: xudrpc.OrderMatch[] = []; placeOrderResponse.matches.forEach((match) => { const orderMatch = new xudrpc.OrderMatch(); - orderMatch.setMaker(getOrder(match.maker)); - orderMatch.setTaker(getOrder(match.taker)); + orderMatch.setMaker(createOrder(match.maker)); + orderMatch.setTaker(createOrder(match.taker)); matchesList.push(orderMatch); }); response.setMatchesList(matchesList); if (placeOrderResponse.remainingOrder) { - response.setRemainingOrder(getOrder(placeOrderResponse.remainingOrder)); + response.setRemainingOrder(createOrder(placeOrderResponse.remainingOrder)); } callback(null, response); } catch (err) { @@ -382,17 +386,44 @@ class GrpcService { } /* - * See [[Service.subscribePeerOrders]] + * See [[Service.subscribeAddedOrders]] + */ + public subscribeAddedOrders: grpc.handleServerStreamingCall = (call) => { + this.service.subscribeAddedOrders((order: StampedOrder) => { + call.write(createOrder(order)); + }); + } + + /* + * See [[Service.subscribeRemovedOrders]] */ - public subscribePeerOrders: grpc.handleServerStreamingCall = (call) => { - this.service.subscribePeerOrders((order: StampedPeerOrder) => call.write({ order })); + public subscribeRemovedOrders: grpc.handleServerStreamingCall = (call) => { + this.service.subscribeRemovedOrders((order: OrderPortion) => { + const orderRemoval = new xudrpc.OrderRemoval(); + orderRemoval.setPairId(order.pairId); + orderRemoval.setOrderId(order.orderId); + orderRemoval.setQuantity(order.quantity); + orderRemoval.setLocalId(order.localId || ''); + orderRemoval.setIsOwnOrder(!!order.localId); + call.write(orderRemoval); + }); } /* * See [[Service.subscribeSwaps]] */ - public subscribeSwaps: grpc.handleServerStreamingCall = (call) => { - this.service.subscribeSwaps((order: StampedOrder) => call.write({ order })); + public subscribeSwaps: grpc.handleServerStreamingCall = (call) => { + this.service.subscribeSwaps((swapResult: SwapResult) => { + const swap = new xudrpc.Swap(); + swap.setAmountReceived(swapResult.amountReceived); + swap.setAmountSent(swapResult.amountSent); + swap.setLocalId(swapResult.localId); + swap.setPairId(swapResult.pairId); + swap.setPeerPubKey(swapResult.peerPubKey); + swap.setRHash(swapResult.r_hash); + swap.setOrderId(swapResult.orderId); + call.write(swap); + }); } } diff --git a/lib/orderbook/MatchingEngine.ts b/lib/orderbook/MatchingEngine.ts index e4de6e1ea..2a43d2d74 100644 --- a/lib/orderbook/MatchingEngine.ts +++ b/lib/orderbook/MatchingEngine.ts @@ -139,19 +139,22 @@ class MatchingEngine { } /** - * Remove a quantity from a peer order. if the entire quantity is met, the order will be removed entirely. - * @returns undefined if the order wasn't found, otherwise the removed order or order portion + * Removes a quantity from a peer order. If the entire quantity is met, the order will be removed entirely. + * @param quantityToRemove the quantity to remove, if undefined or if greater than or equal to the available + * quantity then the entire order is removed + * @returns the removed order or order portion, otherwise undefined if the order wasn't found */ - public removePeerOrderQuantity = (orderId: string, quantityToDecrease?: number): StampedPeerOrder | undefined => { + public removePeerOrderQuantity = (orderId: string, quantityToRemove?: number): StampedPeerOrder | undefined => { const order = this.peerOrders.buy.get(orderId) || this.peerOrders.sell.get(orderId); if (!order) { return; } - if (quantityToDecrease && quantityToDecrease < order.quantity) { - // if quantityToDecrease is below the order quantity, mutate the order quantity, and return a simulation of the removed order portion - order.quantity = order.quantity - quantityToDecrease; - return { ...order, quantity: quantityToDecrease }; + if (quantityToRemove && quantityToRemove < order.quantity) { + // if quantityToRemove is below the order quantity, reduce the order quantity + // and return a copy of the order with the quantity that was removed + order.quantity = order.quantity - quantityToRemove; + return { ...order, quantity: quantityToRemove }; } else { // otherwise, remove the order entirely, and return it this.removePeerOrder(order); @@ -180,6 +183,10 @@ class MatchingEngine { return removedOrders; } + /** + * Removes an own order by its global order id. + * @returns the removed order, or undefined if no order with the provided id could be found + */ public removeOwnOrder = (orderId: string): StampedOwnOrder | undefined => { const order = this.ownOrders.buy.get(orderId) || this.ownOrders.sell.get(orderId); if (!order) { diff --git a/lib/orderbook/OrderBook.ts b/lib/orderbook/OrderBook.ts index 33f26bae4..b3e0ab867 100644 --- a/lib/orderbook/OrderBook.ts +++ b/lib/orderbook/OrderBook.ts @@ -13,13 +13,17 @@ import { Models } from '../db/DB'; import Swaps from '../swaps/Swaps'; import { SwapDealRole } from '../types/enums'; import { CurrencyInstance, PairInstance, CurrencyFactory } from '../types/db'; -import { Pair, OrderIdentifier } from '../types/orders'; +import { Pair, OrderPortion, OrderIdentifier } from '../types/orders'; interface OrderBook { on(event: 'peerOrder.incoming', listener: (order: orders.StampedPeerOrder) => void): this; - on(event: 'peerOrder.invalidation', listener: (order: orders.OrderIdentifier) => void): this; + on(event: 'peerOrder.invalidation', listener: (order: orders.OrderPortion) => void): this; + /** Adds a listener to be called when all or part of a local order is filled. */ + on(event: 'ownOrder.filled', listener: (order: orders.OrderPortion) => void): this; emit(event: 'peerOrder.incoming', order: orders.StampedPeerOrder): boolean; - emit(event: 'peerOrder.invalidation', order: orders.OrderIdentifier): boolean; + emit(event: 'peerOrder.invalidation', order: orders.OrderPortion): boolean; + /** Notifies listeners that all or part of a local order was filled. */ + emit(event: 'ownOrder.filled', order: orders.OrderPortion): boolean; } /** A class representing an orderbook containing all orders for all active trading pairs. */ @@ -61,10 +65,10 @@ class OrderBook extends EventEmitter { private bindSwaps = () => { if (this.swaps) { - this.swaps.on('swap.paid', (deal) => { - if (deal.myRole === SwapDealRole.Maker) { + this.swaps.on('swap.paid', (swapResult, myRole) => { + if (myRole === SwapDealRole.Maker) { // assume full order execution of an own order - this.removeOwnOrder(deal.orderId, deal.pairId, deal.takerPubKey); + this.removeOwnOrder(swapResult.orderId, swapResult.pairId, swapResult.peerPubKey); // TODO: handle partial order execution, updating existing order } @@ -263,39 +267,40 @@ class OrderBook extends EventEmitter { return false; } - const order = matchingEngine.removeOwnOrder(orderId); - if (!order) { + const removedOrder = matchingEngine.removeOwnOrder(orderId); + if (!removedOrder) { this.logger.warn(`invalid orderId: ${pairId}`); return false; } - this.localIdMap.delete(order.localId); + this.localIdMap.delete(removedOrder.localId); this.logger.debug(`order removed: ${JSON.stringify(orderId)}`); if (this.pool) { this.pool.broadcastOrderInvalidation({ orderId, pairId, + quantity: removedOrder.quantity, }, takerPubKey); } return true; } - private removePeerOrder = (orderId: string, pairId: string, quantityToDecrease?: number): orders.StampedPeerOrder | undefined => { + private removePeerOrder = (orderId: string, pairId: string, quantityToRemove?: number): orders.StampedPeerOrder | undefined => { const matchingEngine = this.matchingEngines.get(pairId); if (!matchingEngine) { this.logger.warn(`incoming order invalidation: invalid pairId (${pairId})`); return; } - const order = matchingEngine.removePeerOrderQuantity(orderId, quantityToDecrease); - if (!order) { + const removedOrder = matchingEngine.removePeerOrderQuantity(orderId, quantityToRemove); + if (!removedOrder) { this.logger.warn(`incoming order invalidation: invalid orderId (${orderId})`); return; } else { - assert(order.quantity === quantityToDecrease, 'order quantity must equal quantityToDecrease'); - this.emit('peerOrder.invalidation', { orderId, pairId, quantity: order.quantity }); - return order; + assert(removedOrder.quantity === quantityToRemove, 'order quantity must equal quantityToRemove'); + this.emit('peerOrder.invalidation', { orderId, pairId, quantity: removedOrder.quantity }); + return removedOrder; } } @@ -308,6 +313,7 @@ class OrderBook extends EventEmitter { this.emit('peerOrder.invalidation', { orderId: order.id, pairId: order.pairId, + quantity: order.quantity, }); }); }); @@ -351,11 +357,13 @@ class OrderBook extends EventEmitter { if (this.pool) { const { maker } = match; if (orders.isOwnOrder(maker)) { - this.pool.broadcastOrderInvalidation({ + const orderIdentifier: OrderPortion = { orderId: maker.id, pairId: maker.pairId, quantity: maker.quantity, - }); + }; + this.pool.broadcastOrderInvalidation(orderIdentifier); + this.emit('ownOrder.filled', { ...orderIdentifier, localId: maker.localId }); } } diff --git a/lib/p2p/Pool.ts b/lib/p2p/Pool.ts index eb804d306..b7f7f01e8 100644 --- a/lib/p2p/Pool.ts +++ b/lib/p2p/Pool.ts @@ -7,7 +7,7 @@ import PeerList from './PeerList'; import P2PRepository from './P2PRepository'; import * as packets from './packets/types'; import { Packet, PacketType } from './packets'; -import { OutgoingOrder, OrderIdentifier, StampedPeerOrder } from '../types/orders'; +import { OutgoingOrder, OrderPortion, StampedPeerOrder } from '../types/orders'; import { Models } from '../db/DB'; import Logger from '../Logger'; import { HandshakeState, Address, NodeConnectionInfo } from '../types/p2p'; @@ -30,7 +30,7 @@ type PoolConfig = { interface Pool { on(event: 'packet.order', listener: (order: StampedPeerOrder) => void): this; on(event: 'packet.getOrders', listener: (peer: Peer, reqId: string) => void): this; - on(event: 'packet.orderInvalidation', listener: (orderInvalidation: OrderIdentifier) => void): this; + on(event: 'packet.orderInvalidation', listener: (orderInvalidation: OrderPortion) => void): this; on(event: 'peer.close', listener: (peer: Peer) => void): this; on(event: 'packet.swapRequest', listener: (packet: packets.SwapRequestPacket, peer: Peer) => void): this; on(event: 'packet.swapResponse', listener: (packet: packets.SwapResponsePacket, peer: Peer) => void): this; @@ -38,7 +38,7 @@ interface Pool { on(event: 'packet.swapError', listener: (packet: packets.SwapErrorPacket) => void): this; emit(event: 'packet.order', order: StampedPeerOrder): boolean; emit(event: 'packet.getOrders', peer: Peer, reqId: string): boolean; - emit(event: 'packet.orderInvalidation', orderInvalidation: OrderIdentifier): boolean; + emit(event: 'packet.orderInvalidation', orderInvalidation: OrderPortion): boolean; emit(event: 'peer.close', peer: Peer): boolean; emit(event: 'packet.swapRequest', packet: packets.SwapRequestPacket, peer: Peer): boolean; emit(event: 'packet.swapResponse', packet: packets.SwapResponsePacket, peer: Peer): boolean; @@ -339,7 +339,7 @@ class Pool extends EventEmitter { * Broadcasts an [[OrderInvalidationPacket]] to all currently connected peers. * @param nodeToExclude the node pub key of a node to exclude from the packet broadcast */ - public broadcastOrderInvalidation = (order: OrderIdentifier, nodeToExclude?: string) => { + public broadcastOrderInvalidation = (order: OrderPortion, nodeToExclude?: string) => { const orderInvalidationPacket = new packets.OrderInvalidationPacket(order); this.peers.forEach((peer) => { if (!nodeToExclude || peer.nodePubKey !== nodeToExclude) { diff --git a/lib/p2p/packets/types/OrderInvalidationPacket.ts b/lib/p2p/packets/types/OrderInvalidationPacket.ts index a1acdc2fa..c77833e55 100644 --- a/lib/p2p/packets/types/OrderInvalidationPacket.ts +++ b/lib/p2p/packets/types/OrderInvalidationPacket.ts @@ -1,8 +1,8 @@ import Packet, { PacketDirection } from '../Packet'; import PacketType from '../PacketType'; -import { OrderIdentifier } from '../../../types/orders'; +import { OrderPortion } from '../../../types/orders'; -type OrderInvalidationPacketBody = OrderIdentifier; +type OrderInvalidationPacketBody = OrderPortion; class OrderInvalidationPacket extends Packet { public get type() { diff --git a/lib/proto/xudrpc.swagger.json b/lib/proto/xudrpc.swagger.json index b304af8c4..ce0773b08 100644 --- a/lib/proto/xudrpc.swagger.json +++ b/lib/proto/xudrpc.swagger.json @@ -386,15 +386,15 @@ ] } }, - "/v1/subscribepeerorders": { + "/v1/subscribeorders": { "get": { - "summary": "Subscribe to peer order events.", - "operationId": "SubscribePeerOrders", + "summary": "Subscribe to orders being removed from the order book.", + "operationId": "SubscribeRemovedOrders", "responses": { "200": { "description": "(streaming responses)", "schema": { - "$ref": "#/definitions/xudrpcSubscribePeerOrdersResponse" + "$ref": "#/definitions/xudrpcOrderRemoval" } } }, @@ -405,13 +405,13 @@ }, "/v1/subscribeswaps": { "get": { - "summary": "Subscribe executed swaps.", + "summary": "Subscribe to completed swaps that are initiated by a remote peer. \nSentence 2.\nSentence 3.", "operationId": "SubscribeSwaps", "responses": { "200": { "description": "(streaming responses)", "schema": { - "$ref": "#/definitions/xudrpcSubscribeSwapsResponse" + "$ref": "#/definitions/xudrpcSwap" } } }, @@ -672,46 +672,42 @@ "price": { "type": "number", "format": "double", - "description": "The price of the order, precise to 6 decimal places." + "description": "The price of the order." }, "quantity": { "type": "number", "format": "double", - "description": "The quantity of the order, precise to 6 decimal places." + "description": "The quantity of the order." }, "pair_id": { "type": "string", - "title": "The trading pair that this order is for" + "description": "The trading pair that this order is for." }, - "peer_pub_key": { + "id": { "type": "string", - "title": "The node pub key of the peer that created this order" + "description": "A UUID for this order." }, - "id": { + "peer_pub_key": { "type": "string", - "title": "A UUID for this order" + "description": "The node pub key of the peer that created this order." }, "local_id": { "type": "string", - "title": "The local id for this order" + "description": "The local id for this order." }, "created_at": { "type": "string", "format": "int64", - "title": "The epoch time when this order was created" + "description": "The epoch time when this order was created." }, - "invoice": { - "type": "string", - "title": "Lightning invoice" + "side": { + "$ref": "#/definitions/xudrpcOrderSide", + "title": "Whether this order is a buy or sell" }, - "canceled": { + "is_own_order": { "type": "boolean", "format": "boolean", - "title": "Indicates whether an order was canceled" - }, - "side": { - "$ref": "#/definitions/xudrpcOrderSide", - "title": "Whether the order is a Buy or Sell" + "description": "Whether this order is a local own order or a remote peer order." } } }, @@ -726,6 +722,33 @@ } } }, + "xudrpcOrderRemoval": { + "type": "object", + "properties": { + "quantity": { + "type": "number", + "format": "double", + "description": "The quantity of the order being removed." + }, + "pair_id": { + "type": "string", + "description": "The trading pair that the order is for." + }, + "order_id": { + "type": "string", + "description": "The global UUID for the order." + }, + "local_id": { + "type": "string", + "description": "The local id for the order, if applicable." + }, + "is_own_order": { + "type": "boolean", + "format": "boolean", + "description": "Whether the order being removed is a local own order or a remote peer order." + } + } + }, "xudrpcOrderSide": { "type": "string", "enum": [ @@ -806,12 +829,12 @@ "price": { "type": "number", "format": "double", - "description": "The price of the order, precise to 6 decimal places." + "description": "The price of the order." }, "quantity": { "type": "number", "format": "double", - "description": "The quantity of the order, precise to 6 decimal places." + "description": "The quantity of the order." }, "pair_id": { "type": "string", @@ -891,20 +914,38 @@ "xudrpcShutdownResponse": { "type": "object" }, - "xudrpcSubscribePeerOrdersResponse": { - "type": "object", - "properties": { - "order": { - "$ref": "#/definitions/xudrpcOrder" - } - } - }, - "xudrpcSubscribeSwapsResponse": { + "xudrpcSwap": { "type": "object", "properties": { - "order": { + "order_id": { + "type": "string", + "description": "The global UUID for the order that was swapped." + }, + "local_id": { + "type": "string", + "description": "The local id for the order that was swapped." + }, + "pair_id": { + "type": "string", + "description": "The trading pair that this order is for." + }, + "r_hash": { + "type": "string", + "description": "The hex-encoded r_hash for the swap payments." + }, + "amount_received": { + "type": "string", + "format": "int64", + "description": "The amount of subunits (satoshis) received." + }, + "amount_sent": { + "type": "string", + "format": "int64", + "description": "The amount of subunits (satoshis) sent." + }, + "peer_pub_key": { "type": "string", - "title": "The order which was executed for the swap with updated remaining quantity" + "description": "The node pub key of the peer that executed this order." } } } diff --git a/lib/proto/xudrpc_grpc_pb.d.ts b/lib/proto/xudrpc_grpc_pb.d.ts index f2dabc4e3..4b91102c8 100644 --- a/lib/proto/xudrpc_grpc_pb.d.ts +++ b/lib/proto/xudrpc_grpc_pb.d.ts @@ -23,7 +23,8 @@ interface IXudService extends grpc.ServiceDefinition; responseDeserialize: grpc.deserialize; } -interface IXudService_ISubscribePeerOrders extends grpc.MethodDefinition { - path: string; // "/xudrpc.Xud/SubscribePeerOrders" +interface IXudService_ISubscribeAddedOrders extends grpc.MethodDefinition { + path: string; // "/xudrpc.Xud/SubscribeAddedOrders" requestStream: boolean; // false responseStream: boolean; // true - requestSerialize: grpc.serialize; - requestDeserialize: grpc.deserialize; - responseSerialize: grpc.serialize; - responseDeserialize: grpc.deserialize; + requestSerialize: grpc.serialize; + requestDeserialize: grpc.deserialize; + responseSerialize: grpc.serialize; + responseDeserialize: grpc.deserialize; } -interface IXudService_ISubscribeSwaps extends grpc.MethodDefinition { +interface IXudService_ISubscribeRemovedOrders extends grpc.MethodDefinition { + path: string; // "/xudrpc.Xud/SubscribeRemovedOrders" + requestStream: boolean; // false + responseStream: boolean; // true + requestSerialize: grpc.serialize; + requestDeserialize: grpc.deserialize; + responseSerialize: grpc.serialize; + responseDeserialize: grpc.deserialize; +} +interface IXudService_ISubscribeSwaps extends grpc.MethodDefinition { path: string; // "/xudrpc.Xud/SubscribeSwaps" requestStream: boolean; // false responseStream: boolean; // true requestSerialize: grpc.serialize; requestDeserialize: grpc.deserialize; - responseSerialize: grpc.serialize; - responseDeserialize: grpc.deserialize; + responseSerialize: grpc.serialize; + responseDeserialize: grpc.deserialize; } export const XudService: IXudService; @@ -199,8 +209,9 @@ export interface IXudServer { removeCurrency: grpc.handleUnaryCall; removePair: grpc.handleUnaryCall; shutdown: grpc.handleUnaryCall; - subscribePeerOrders: grpc.handleServerStreamingCall; - subscribeSwaps: grpc.handleServerStreamingCall; + subscribeAddedOrders: grpc.handleServerStreamingCall; + subscribeRemovedOrders: grpc.handleServerStreamingCall; + subscribeSwaps: grpc.handleServerStreamingCall; } export interface IXudClient { @@ -249,8 +260,10 @@ export interface IXudClient { shutdown(request: xudrpc_pb.ShutdownRequest, callback: (error: Error | null, response: xudrpc_pb.ShutdownResponse) => void): grpc.ClientUnaryCall; shutdown(request: xudrpc_pb.ShutdownRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: xudrpc_pb.ShutdownResponse) => void): grpc.ClientUnaryCall; shutdown(request: xudrpc_pb.ShutdownRequest, metadata: grpc.Metadata, options: Partial, callback: (error: Error | null, response: xudrpc_pb.ShutdownResponse) => void): grpc.ClientUnaryCall; - subscribePeerOrders(request: xudrpc_pb.SubscribePeerOrdersRequest, options?: Partial): grpc.ClientReadableStream; - subscribePeerOrders(request: xudrpc_pb.SubscribePeerOrdersRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; + subscribeAddedOrders(request: xudrpc_pb.SubscribeAddedOrdersRequest, options?: Partial): grpc.ClientReadableStream; + subscribeAddedOrders(request: xudrpc_pb.SubscribeAddedOrdersRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; + subscribeRemovedOrders(request: xudrpc_pb.SubscribeRemovedOrdersRequest, options?: Partial): grpc.ClientReadableStream; + subscribeRemovedOrders(request: xudrpc_pb.SubscribeRemovedOrdersRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; subscribeSwaps(request: xudrpc_pb.SubscribeSwapsRequest, options?: Partial): grpc.ClientReadableStream; subscribeSwaps(request: xudrpc_pb.SubscribeSwapsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; } @@ -302,8 +315,10 @@ export class XudClient extends grpc.Client implements IXudClient { public shutdown(request: xudrpc_pb.ShutdownRequest, callback: (error: Error | null, response: xudrpc_pb.ShutdownResponse) => void): grpc.ClientUnaryCall; public shutdown(request: xudrpc_pb.ShutdownRequest, metadata: grpc.Metadata, callback: (error: Error | null, response: xudrpc_pb.ShutdownResponse) => void): grpc.ClientUnaryCall; public shutdown(request: xudrpc_pb.ShutdownRequest, metadata: grpc.Metadata, options: Partial, callback: (error: Error | null, response: xudrpc_pb.ShutdownResponse) => void): grpc.ClientUnaryCall; - public subscribePeerOrders(request: xudrpc_pb.SubscribePeerOrdersRequest, options?: Partial): grpc.ClientReadableStream; - public subscribePeerOrders(request: xudrpc_pb.SubscribePeerOrdersRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; + public subscribeAddedOrders(request: xudrpc_pb.SubscribeAddedOrdersRequest, options?: Partial): grpc.ClientReadableStream; + public subscribeAddedOrders(request: xudrpc_pb.SubscribeAddedOrdersRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; + public subscribeRemovedOrders(request: xudrpc_pb.SubscribeRemovedOrdersRequest, options?: Partial): grpc.ClientReadableStream; + public subscribeRemovedOrders(request: xudrpc_pb.SubscribeRemovedOrdersRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; public subscribeSwaps(request: xudrpc_pb.SubscribeSwapsRequest, options?: Partial): grpc.ClientReadableStream; public subscribeSwaps(request: xudrpc_pb.SubscribeSwapsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; } diff --git a/lib/proto/xudrpc_grpc_pb.js b/lib/proto/xudrpc_grpc_pb.js index 450f52857..499a86b45 100644 --- a/lib/proto/xudrpc_grpc_pb.js +++ b/lib/proto/xudrpc_grpc_pb.js @@ -268,6 +268,28 @@ function deserialize_xudrpc_ListPeersResponse(buffer_arg) { return xudrpc_pb.ListPeersResponse.deserializeBinary(new Uint8Array(buffer_arg)); } +function serialize_xudrpc_Order(arg) { + if (!(arg instanceof xudrpc_pb.Order)) { + throw new Error('Expected argument of type xudrpc.Order'); + } + return new Buffer(arg.serializeBinary()); +} + +function deserialize_xudrpc_Order(buffer_arg) { + return xudrpc_pb.Order.deserializeBinary(new Uint8Array(buffer_arg)); +} + +function serialize_xudrpc_OrderRemoval(arg) { + if (!(arg instanceof xudrpc_pb.OrderRemoval)) { + throw new Error('Expected argument of type xudrpc.OrderRemoval'); + } + return new Buffer(arg.serializeBinary()); +} + +function deserialize_xudrpc_OrderRemoval(buffer_arg) { + return xudrpc_pb.OrderRemoval.deserializeBinary(new Uint8Array(buffer_arg)); +} + function serialize_xudrpc_PlaceOrderRequest(arg) { if (!(arg instanceof xudrpc_pb.PlaceOrderRequest)) { throw new Error('Expected argument of type xudrpc.PlaceOrderRequest'); @@ -356,26 +378,26 @@ function deserialize_xudrpc_ShutdownResponse(buffer_arg) { return xudrpc_pb.ShutdownResponse.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_xudrpc_SubscribePeerOrdersRequest(arg) { - if (!(arg instanceof xudrpc_pb.SubscribePeerOrdersRequest)) { - throw new Error('Expected argument of type xudrpc.SubscribePeerOrdersRequest'); +function serialize_xudrpc_SubscribeAddedOrdersRequest(arg) { + if (!(arg instanceof xudrpc_pb.SubscribeAddedOrdersRequest)) { + throw new Error('Expected argument of type xudrpc.SubscribeAddedOrdersRequest'); } return new Buffer(arg.serializeBinary()); } -function deserialize_xudrpc_SubscribePeerOrdersRequest(buffer_arg) { - return xudrpc_pb.SubscribePeerOrdersRequest.deserializeBinary(new Uint8Array(buffer_arg)); +function deserialize_xudrpc_SubscribeAddedOrdersRequest(buffer_arg) { + return xudrpc_pb.SubscribeAddedOrdersRequest.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_xudrpc_SubscribePeerOrdersResponse(arg) { - if (!(arg instanceof xudrpc_pb.SubscribePeerOrdersResponse)) { - throw new Error('Expected argument of type xudrpc.SubscribePeerOrdersResponse'); +function serialize_xudrpc_SubscribeRemovedOrdersRequest(arg) { + if (!(arg instanceof xudrpc_pb.SubscribeRemovedOrdersRequest)) { + throw new Error('Expected argument of type xudrpc.SubscribeRemovedOrdersRequest'); } return new Buffer(arg.serializeBinary()); } -function deserialize_xudrpc_SubscribePeerOrdersResponse(buffer_arg) { - return xudrpc_pb.SubscribePeerOrdersResponse.deserializeBinary(new Uint8Array(buffer_arg)); +function deserialize_xudrpc_SubscribeRemovedOrdersRequest(buffer_arg) { + return xudrpc_pb.SubscribeRemovedOrdersRequest.deserializeBinary(new Uint8Array(buffer_arg)); } function serialize_xudrpc_SubscribeSwapsRequest(arg) { @@ -389,15 +411,15 @@ function deserialize_xudrpc_SubscribeSwapsRequest(buffer_arg) { return xudrpc_pb.SubscribeSwapsRequest.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_xudrpc_SubscribeSwapsResponse(arg) { - if (!(arg instanceof xudrpc_pb.SubscribeSwapsResponse)) { - throw new Error('Expected argument of type xudrpc.SubscribeSwapsResponse'); +function serialize_xudrpc_Swap(arg) { + if (!(arg instanceof xudrpc_pb.Swap)) { + throw new Error('Expected argument of type xudrpc.Swap'); } return new Buffer(arg.serializeBinary()); } -function deserialize_xudrpc_SubscribeSwapsResponse(buffer_arg) { - return xudrpc_pb.SubscribeSwapsResponse.deserializeBinary(new Uint8Array(buffer_arg)); +function deserialize_xudrpc_Swap(buffer_arg) { + return xudrpc_pb.Swap.deserializeBinary(new Uint8Array(buffer_arg)); } @@ -583,29 +605,43 @@ var XudService = exports.XudService = { responseSerialize: serialize_xudrpc_ShutdownResponse, responseDeserialize: deserialize_xudrpc_ShutdownResponse, }, - // Subscribe to peer order events. - subscribePeerOrders: { - path: '/xudrpc.Xud/SubscribePeerOrders', + // Subscribe to orders being added to the order book. + subscribeAddedOrders: { + path: '/xudrpc.Xud/SubscribeAddedOrders', + requestStream: false, + responseStream: true, + requestType: xudrpc_pb.SubscribeAddedOrdersRequest, + responseType: xudrpc_pb.Order, + requestSerialize: serialize_xudrpc_SubscribeAddedOrdersRequest, + requestDeserialize: deserialize_xudrpc_SubscribeAddedOrdersRequest, + responseSerialize: serialize_xudrpc_Order, + responseDeserialize: deserialize_xudrpc_Order, + }, + // Subscribe to orders being removed from the order book. + subscribeRemovedOrders: { + path: '/xudrpc.Xud/SubscribeRemovedOrders', requestStream: false, responseStream: true, - requestType: xudrpc_pb.SubscribePeerOrdersRequest, - responseType: xudrpc_pb.SubscribePeerOrdersResponse, - requestSerialize: serialize_xudrpc_SubscribePeerOrdersRequest, - requestDeserialize: deserialize_xudrpc_SubscribePeerOrdersRequest, - responseSerialize: serialize_xudrpc_SubscribePeerOrdersResponse, - responseDeserialize: deserialize_xudrpc_SubscribePeerOrdersResponse, + requestType: xudrpc_pb.SubscribeRemovedOrdersRequest, + responseType: xudrpc_pb.OrderRemoval, + requestSerialize: serialize_xudrpc_SubscribeRemovedOrdersRequest, + requestDeserialize: deserialize_xudrpc_SubscribeRemovedOrdersRequest, + responseSerialize: serialize_xudrpc_OrderRemoval, + responseDeserialize: deserialize_xudrpc_OrderRemoval, }, - // Subscribe executed swaps. + // Subscribe to completed swaps that are initiated by a remote peer. + // Sentence 2. + // Sentence 3. subscribeSwaps: { path: '/xudrpc.Xud/SubscribeSwaps', requestStream: false, responseStream: true, requestType: xudrpc_pb.SubscribeSwapsRequest, - responseType: xudrpc_pb.SubscribeSwapsResponse, + responseType: xudrpc_pb.Swap, requestSerialize: serialize_xudrpc_SubscribeSwapsRequest, requestDeserialize: deserialize_xudrpc_SubscribeSwapsRequest, - responseSerialize: serialize_xudrpc_SubscribeSwapsResponse, - responseDeserialize: deserialize_xudrpc_SubscribeSwapsResponse, + responseSerialize: serialize_xudrpc_Swap, + responseDeserialize: deserialize_xudrpc_Swap, }, }; diff --git a/lib/proto/xudrpc_pb.d.ts b/lib/proto/xudrpc_pb.d.ts index d6ffcdfe1..12d787164 100644 --- a/lib/proto/xudrpc_pb.d.ts +++ b/lib/proto/xudrpc_pb.d.ts @@ -630,27 +630,32 @@ export class Order extends jspb.Message { getPairId(): string; setPairId(value: string): void; + getId(): string; + setId(value: string): void; + + + hasPeerPubKey(): boolean; + clearPeerPubKey(): void; getPeerPubKey(): string; setPeerPubKey(value: string): void; - getId(): string; - setId(value: string): void; + hasLocalId(): boolean; + clearLocalId(): void; getLocalId(): string; setLocalId(value: string): void; getCreatedAt(): number; setCreatedAt(value: number): void; - getInvoice(): string; - setInvoice(value: string): void; - - getCanceled(): boolean; - setCanceled(value: boolean): void; - getSide(): OrderSide; setSide(value: OrderSide): void; + getIsOwnOrder(): boolean; + setIsOwnOrder(value: boolean): void; + + + getOwnOrPeerCase(): Order.OwnOrPeerCase; serializeBinary(): Uint8Array; toObject(includeInstance?: boolean): Order.AsObject; @@ -667,13 +672,59 @@ export namespace Order { price: number, quantity: number, pairId: string, - peerPubKey: string, id: string, + peerPubKey: string, localId: string, createdAt: number, - invoice: string, - canceled: boolean, side: OrderSide, + isOwnOrder: boolean, + } + + export enum OwnOrPeerCase { + OWNORPEER_NOT_SET = 0, + + PEER_PUB_KEY = 5, + + LOCAL_ID = 6, + + } + +} + +export class OrderRemoval extends jspb.Message { + getQuantity(): number; + setQuantity(value: number): void; + + getPairId(): string; + setPairId(value: string): void; + + getOrderId(): string; + setOrderId(value: string): void; + + getLocalId(): string; + setLocalId(value: string): void; + + getIsOwnOrder(): boolean; + setIsOwnOrder(value: boolean): void; + + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): OrderRemoval.AsObject; + static toObject(includeInstance: boolean, msg: OrderRemoval): OrderRemoval.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: OrderRemoval, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): OrderRemoval; + static deserializeBinaryFromReader(message: OrderRemoval, reader: jspb.BinaryReader): OrderRemoval; +} + +export namespace OrderRemoval { + export type AsObject = { + quantity: number, + pairId: string, + orderId: string, + localId: string, + isOwnOrder: boolean, } } @@ -981,47 +1032,6 @@ export namespace RemovePairResponse { } } -export class SwapPayload extends jspb.Message { - getRole(): string; - setRole(value: string): void; - - getSendingAmount(): number; - setSendingAmount(value: number): void; - - getSendingToken(): string; - setSendingToken(value: string): void; - - getReceivingAmount(): number; - setReceivingAmount(value: number): void; - - getReceivingToken(): string; - setReceivingToken(value: string): void; - - getNodePubKey(): string; - setNodePubKey(value: string): void; - - - serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): SwapPayload.AsObject; - static toObject(includeInstance: boolean, msg: SwapPayload): SwapPayload.AsObject; - static extensions: {[key: number]: jspb.ExtensionFieldInfo}; - static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: SwapPayload, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): SwapPayload; - static deserializeBinaryFromReader(message: SwapPayload, reader: jspb.BinaryReader): SwapPayload; -} - -export namespace SwapPayload { - export type AsObject = { - role: string, - sendingAmount: number, - sendingToken: string, - receivingAmount: number, - receivingToken: string, - nodePubKey: string, - } -} - export class ShutdownRequest extends jspb.Message { serializeBinary(): Uint8Array; @@ -1056,44 +1066,37 @@ export namespace ShutdownResponse { } } -export class SubscribePeerOrdersRequest extends jspb.Message { +export class SubscribeAddedOrdersRequest extends jspb.Message { serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): SubscribePeerOrdersRequest.AsObject; - static toObject(includeInstance: boolean, msg: SubscribePeerOrdersRequest): SubscribePeerOrdersRequest.AsObject; + toObject(includeInstance?: boolean): SubscribeAddedOrdersRequest.AsObject; + static toObject(includeInstance: boolean, msg: SubscribeAddedOrdersRequest): SubscribeAddedOrdersRequest.AsObject; static extensions: {[key: number]: jspb.ExtensionFieldInfo}; static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: SubscribePeerOrdersRequest, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): SubscribePeerOrdersRequest; - static deserializeBinaryFromReader(message: SubscribePeerOrdersRequest, reader: jspb.BinaryReader): SubscribePeerOrdersRequest; + static serializeBinaryToWriter(message: SubscribeAddedOrdersRequest, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): SubscribeAddedOrdersRequest; + static deserializeBinaryFromReader(message: SubscribeAddedOrdersRequest, reader: jspb.BinaryReader): SubscribeAddedOrdersRequest; } -export namespace SubscribePeerOrdersRequest { +export namespace SubscribeAddedOrdersRequest { export type AsObject = { } } -export class SubscribePeerOrdersResponse extends jspb.Message { - - hasOrder(): boolean; - clearOrder(): void; - getOrder(): Order | undefined; - setOrder(value?: Order): void; - +export class SubscribeRemovedOrdersRequest extends jspb.Message { serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): SubscribePeerOrdersResponse.AsObject; - static toObject(includeInstance: boolean, msg: SubscribePeerOrdersResponse): SubscribePeerOrdersResponse.AsObject; + toObject(includeInstance?: boolean): SubscribeRemovedOrdersRequest.AsObject; + static toObject(includeInstance: boolean, msg: SubscribeRemovedOrdersRequest): SubscribeRemovedOrdersRequest.AsObject; static extensions: {[key: number]: jspb.ExtensionFieldInfo}; static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: SubscribePeerOrdersResponse, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): SubscribePeerOrdersResponse; - static deserializeBinaryFromReader(message: SubscribePeerOrdersResponse, reader: jspb.BinaryReader): SubscribePeerOrdersResponse; + static serializeBinaryToWriter(message: SubscribeRemovedOrdersRequest, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): SubscribeRemovedOrdersRequest; + static deserializeBinaryFromReader(message: SubscribeRemovedOrdersRequest, reader: jspb.BinaryReader): SubscribeRemovedOrdersRequest; } -export namespace SubscribePeerOrdersResponse { +export namespace SubscribeRemovedOrdersRequest { export type AsObject = { - order?: Order.AsObject, } } @@ -1114,24 +1117,48 @@ export namespace SubscribeSwapsRequest { } } -export class SubscribeSwapsResponse extends jspb.Message { - getOrder(): string; - setOrder(value: string): void; +export class Swap extends jspb.Message { + getOrderId(): string; + setOrderId(value: string): void; + + getLocalId(): string; + setLocalId(value: string): void; + + getPairId(): string; + setPairId(value: string): void; + + getRHash(): string; + setRHash(value: string): void; + + getAmountReceived(): number; + setAmountReceived(value: number): void; + + getAmountSent(): number; + setAmountSent(value: number): void; + + getPeerPubKey(): string; + setPeerPubKey(value: string): void; serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): SubscribeSwapsResponse.AsObject; - static toObject(includeInstance: boolean, msg: SubscribeSwapsResponse): SubscribeSwapsResponse.AsObject; + toObject(includeInstance?: boolean): Swap.AsObject; + static toObject(includeInstance: boolean, msg: Swap): Swap.AsObject; static extensions: {[key: number]: jspb.ExtensionFieldInfo}; static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: SubscribeSwapsResponse, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): SubscribeSwapsResponse; - static deserializeBinaryFromReader(message: SubscribeSwapsResponse, reader: jspb.BinaryReader): SubscribeSwapsResponse; + static serializeBinaryToWriter(message: Swap, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): Swap; + static deserializeBinaryFromReader(message: Swap, reader: jspb.BinaryReader): Swap; } -export namespace SubscribeSwapsResponse { +export namespace Swap { export type AsObject = { - order: string, + orderId: string, + localId: string, + pairId: string, + rHash: string, + amountReceived: number, + amountSent: number, + peerPubKey: string, } } diff --git a/lib/proto/xudrpc_pb.js b/lib/proto/xudrpc_pb.js index 9c4758d4a..af0de4e6b 100644 --- a/lib/proto/xudrpc_pb.js +++ b/lib/proto/xudrpc_pb.js @@ -40,6 +40,7 @@ goog.exportSymbol('proto.xudrpc.LndChannels', null, global); goog.exportSymbol('proto.xudrpc.LndInfo', null, global); goog.exportSymbol('proto.xudrpc.Order', null, global); goog.exportSymbol('proto.xudrpc.OrderMatch', null, global); +goog.exportSymbol('proto.xudrpc.OrderRemoval', null, global); goog.exportSymbol('proto.xudrpc.OrderSide', null, global); goog.exportSymbol('proto.xudrpc.Orders', null, global); goog.exportSymbol('proto.xudrpc.OrdersCount', null, global); @@ -53,11 +54,10 @@ goog.exportSymbol('proto.xudrpc.RemovePairRequest', null, global); goog.exportSymbol('proto.xudrpc.RemovePairResponse', null, global); goog.exportSymbol('proto.xudrpc.ShutdownRequest', null, global); goog.exportSymbol('proto.xudrpc.ShutdownResponse', null, global); -goog.exportSymbol('proto.xudrpc.SubscribePeerOrdersRequest', null, global); -goog.exportSymbol('proto.xudrpc.SubscribePeerOrdersResponse', null, global); +goog.exportSymbol('proto.xudrpc.SubscribeAddedOrdersRequest', null, global); +goog.exportSymbol('proto.xudrpc.SubscribeRemovedOrdersRequest', null, global); goog.exportSymbol('proto.xudrpc.SubscribeSwapsRequest', null, global); -goog.exportSymbol('proto.xudrpc.SubscribeSwapsResponse', null, global); -goog.exportSymbol('proto.xudrpc.SwapPayload', null, global); +goog.exportSymbol('proto.xudrpc.Swap', null, global); /** * Generated by JsPbCodeGenerator. @@ -4203,12 +4203,38 @@ proto.xudrpc.LndInfo.prototype.setAlias = function(value) { * @constructor */ proto.xudrpc.Order = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, null, null); + jspb.Message.initialize(this, opt_data, 0, -1, null, proto.xudrpc.Order.oneofGroups_); }; goog.inherits(proto.xudrpc.Order, jspb.Message); if (goog.DEBUG && !COMPILED) { proto.xudrpc.Order.displayName = 'proto.xudrpc.Order'; } +/** + * Oneof group definitions for this message. Each group defines the field + * numbers belonging to that group. When of these fields' value is set, all + * other fields in the group are cleared. During deserialization, if multiple + * fields are encountered for a group, only the last value seen will be kept. + * @private {!Array>} + * @const + */ +proto.xudrpc.Order.oneofGroups_ = [[5,6]]; + +/** + * @enum {number} + */ +proto.xudrpc.Order.OwnOrPeerCase = { + OWN_OR_PEER_NOT_SET: 0, + PEER_PUB_KEY: 5, + LOCAL_ID: 6 +}; + +/** + * @return {proto.xudrpc.Order.OwnOrPeerCase} + */ +proto.xudrpc.Order.prototype.getOwnOrPeerCase = function() { + return /** @type {proto.xudrpc.Order.OwnOrPeerCase} */(jspb.Message.computeOneofCase(this, proto.xudrpc.Order.oneofGroups_[0])); +}; + if (jspb.Message.GENERATE_TO_OBJECT) { @@ -4241,13 +4267,12 @@ proto.xudrpc.Order.toObject = function(includeInstance, msg) { price: +jspb.Message.getFieldWithDefault(msg, 1, 0.0), quantity: +jspb.Message.getFieldWithDefault(msg, 2, 0.0), pairId: jspb.Message.getFieldWithDefault(msg, 3, ""), - peerPubKey: jspb.Message.getFieldWithDefault(msg, 4, ""), - id: jspb.Message.getFieldWithDefault(msg, 5, ""), + id: jspb.Message.getFieldWithDefault(msg, 4, ""), + peerPubKey: jspb.Message.getFieldWithDefault(msg, 5, ""), localId: jspb.Message.getFieldWithDefault(msg, 6, ""), createdAt: jspb.Message.getFieldWithDefault(msg, 7, 0), - invoice: jspb.Message.getFieldWithDefault(msg, 8, ""), - canceled: jspb.Message.getFieldWithDefault(msg, 9, false), - side: jspb.Message.getFieldWithDefault(msg, 10, 0) + side: jspb.Message.getFieldWithDefault(msg, 8, 0), + isOwnOrder: jspb.Message.getFieldWithDefault(msg, 9, false) }; if (includeInstance) { @@ -4298,11 +4323,11 @@ proto.xudrpc.Order.deserializeBinaryFromReader = function(msg, reader) { break; case 4: var value = /** @type {string} */ (reader.readString()); - msg.setPeerPubKey(value); + msg.setId(value); break; case 5: var value = /** @type {string} */ (reader.readString()); - msg.setId(value); + msg.setPeerPubKey(value); break; case 6: var value = /** @type {string} */ (reader.readString()); @@ -4313,16 +4338,12 @@ proto.xudrpc.Order.deserializeBinaryFromReader = function(msg, reader) { msg.setCreatedAt(value); break; case 8: - var value = /** @type {string} */ (reader.readString()); - msg.setInvoice(value); + var value = /** @type {!proto.xudrpc.OrderSide} */ (reader.readEnum()); + msg.setSide(value); break; case 9: var value = /** @type {boolean} */ (reader.readBool()); - msg.setCanceled(value); - break; - case 10: - var value = /** @type {!proto.xudrpc.OrderSide} */ (reader.readEnum()); - msg.setSide(value); + msg.setIsOwnOrder(value); break; default: reader.skipField(); @@ -4374,22 +4395,22 @@ proto.xudrpc.Order.serializeBinaryToWriter = function(message, writer) { f ); } - f = message.getPeerPubKey(); + f = message.getId(); if (f.length > 0) { writer.writeString( 4, f ); } - f = message.getId(); - if (f.length > 0) { + f = /** @type {string} */ (jspb.Message.getField(message, 5)); + if (f != null) { writer.writeString( 5, f ); } - f = message.getLocalId(); - if (f.length > 0) { + f = /** @type {string} */ (jspb.Message.getField(message, 6)); + if (f != null) { writer.writeString( 6, f @@ -4402,27 +4423,20 @@ proto.xudrpc.Order.serializeBinaryToWriter = function(message, writer) { f ); } - f = message.getInvoice(); - if (f.length > 0) { - writer.writeString( + f = message.getSide(); + if (f !== 0.0) { + writer.writeEnum( 8, f ); } - f = message.getCanceled(); + f = message.getIsOwnOrder(); if (f) { writer.writeBool( 9, f ); } - f = message.getSide(); - if (f !== 0.0) { - writer.writeEnum( - 10, - f - ); - } }; @@ -4472,32 +4486,46 @@ proto.xudrpc.Order.prototype.setPairId = function(value) { /** - * optional string peer_pub_key = 4; + * optional string id = 4; * @return {string} */ -proto.xudrpc.Order.prototype.getPeerPubKey = function() { +proto.xudrpc.Order.prototype.getId = function() { return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 4, "")); }; /** @param {string} value */ -proto.xudrpc.Order.prototype.setPeerPubKey = function(value) { +proto.xudrpc.Order.prototype.setId = function(value) { jspb.Message.setField(this, 4, value); }; /** - * optional string id = 5; + * optional string peer_pub_key = 5; * @return {string} */ -proto.xudrpc.Order.prototype.getId = function() { +proto.xudrpc.Order.prototype.getPeerPubKey = function() { return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 5, "")); }; /** @param {string} value */ -proto.xudrpc.Order.prototype.setId = function(value) { - jspb.Message.setField(this, 5, value); +proto.xudrpc.Order.prototype.setPeerPubKey = function(value) { + jspb.Message.setOneofField(this, 5, proto.xudrpc.Order.oneofGroups_[0], value); +}; + + +proto.xudrpc.Order.prototype.clearPeerPubKey = function() { + jspb.Message.setOneofField(this, 5, proto.xudrpc.Order.oneofGroups_[0], undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.xudrpc.Order.prototype.hasPeerPubKey = function() { + return jspb.Message.getField(this, 5) != null; }; @@ -4512,7 +4540,21 @@ proto.xudrpc.Order.prototype.getLocalId = function() { /** @param {string} value */ proto.xudrpc.Order.prototype.setLocalId = function(value) { - jspb.Message.setField(this, 6, value); + jspb.Message.setOneofField(this, 6, proto.xudrpc.Order.oneofGroups_[0], value); +}; + + +proto.xudrpc.Order.prototype.clearLocalId = function() { + jspb.Message.setOneofField(this, 6, proto.xudrpc.Order.oneofGroups_[0], undefined); +}; + + +/** + * Returns whether this field is set. + * @return {!boolean} + */ +proto.xudrpc.Order.prototype.hasLocalId = function() { + return jspb.Message.getField(this, 6) != null; }; @@ -4532,52 +4574,37 @@ proto.xudrpc.Order.prototype.setCreatedAt = function(value) { /** - * optional string invoice = 8; - * @return {string} + * optional OrderSide side = 8; + * @return {!proto.xudrpc.OrderSide} */ -proto.xudrpc.Order.prototype.getInvoice = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 8, "")); +proto.xudrpc.Order.prototype.getSide = function() { + return /** @type {!proto.xudrpc.OrderSide} */ (jspb.Message.getFieldWithDefault(this, 8, 0)); }; -/** @param {string} value */ -proto.xudrpc.Order.prototype.setInvoice = function(value) { +/** @param {!proto.xudrpc.OrderSide} value */ +proto.xudrpc.Order.prototype.setSide = function(value) { jspb.Message.setField(this, 8, value); }; /** - * optional bool canceled = 9; + * optional bool is_own_order = 9; * Note that Boolean fields may be set to 0/1 when serialized from a Java server. * You should avoid comparisons like {@code val === true/false} in those cases. * @return {boolean} */ -proto.xudrpc.Order.prototype.getCanceled = function() { +proto.xudrpc.Order.prototype.getIsOwnOrder = function() { return /** @type {boolean} */ (jspb.Message.getFieldWithDefault(this, 9, false)); }; /** @param {boolean} value */ -proto.xudrpc.Order.prototype.setCanceled = function(value) { +proto.xudrpc.Order.prototype.setIsOwnOrder = function(value) { jspb.Message.setField(this, 9, value); }; -/** - * optional OrderSide side = 10; - * @return {!proto.xudrpc.OrderSide} - */ -proto.xudrpc.Order.prototype.getSide = function() { - return /** @type {!proto.xudrpc.OrderSide} */ (jspb.Message.getFieldWithDefault(this, 10, 0)); -}; - - -/** @param {!proto.xudrpc.OrderSide} value */ -proto.xudrpc.Order.prototype.setSide = function(value) { - jspb.Message.setField(this, 10, value); -}; - - /** * Generated by JsPbCodeGenerator. @@ -4589,20 +4616,13 @@ proto.xudrpc.Order.prototype.setSide = function(value) { * @extends {jspb.Message} * @constructor */ -proto.xudrpc.Orders = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, proto.xudrpc.Orders.repeatedFields_, null); +proto.xudrpc.OrderRemoval = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; -goog.inherits(proto.xudrpc.Orders, jspb.Message); +goog.inherits(proto.xudrpc.OrderRemoval, jspb.Message); if (goog.DEBUG && !COMPILED) { - proto.xudrpc.Orders.displayName = 'proto.xudrpc.Orders'; + proto.xudrpc.OrderRemoval.displayName = 'proto.xudrpc.OrderRemoval'; } -/** - * List of repeated fields within this message type. - * @private {!Array} - * @const - */ -proto.xudrpc.Orders.repeatedFields_ = [1,2]; - if (jspb.Message.GENERATE_TO_OBJECT) { @@ -4616,8 +4636,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ -proto.xudrpc.Orders.prototype.toObject = function(opt_includeInstance) { - return proto.xudrpc.Orders.toObject(opt_includeInstance, this); +proto.xudrpc.OrderRemoval.prototype.toObject = function(opt_includeInstance) { + return proto.xudrpc.OrderRemoval.toObject(opt_includeInstance, this); }; @@ -4626,16 +4646,17 @@ proto.xudrpc.Orders.prototype.toObject = function(opt_includeInstance) { * @param {boolean|undefined} includeInstance Whether to include the JSPB * instance for transitional soy proto support: * http://goto/soy-param-migration - * @param {!proto.xudrpc.Orders} msg The msg instance to transform. + * @param {!proto.xudrpc.OrderRemoval} msg The msg instance to transform. * @return {!Object} * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.Orders.toObject = function(includeInstance, msg) { +proto.xudrpc.OrderRemoval.toObject = function(includeInstance, msg) { var f, obj = { - buyOrdersList: jspb.Message.toObjectList(msg.getBuyOrdersList(), - proto.xudrpc.Order.toObject, includeInstance), - sellOrdersList: jspb.Message.toObjectList(msg.getSellOrdersList(), - proto.xudrpc.Order.toObject, includeInstance) + quantity: +jspb.Message.getFieldWithDefault(msg, 1, 0.0), + pairId: jspb.Message.getFieldWithDefault(msg, 2, ""), + orderId: jspb.Message.getFieldWithDefault(msg, 3, ""), + localId: jspb.Message.getFieldWithDefault(msg, 4, ""), + isOwnOrder: jspb.Message.getFieldWithDefault(msg, 5, false) }; if (includeInstance) { @@ -4649,23 +4670,23 @@ proto.xudrpc.Orders.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.xudrpc.Orders} + * @return {!proto.xudrpc.OrderRemoval} */ -proto.xudrpc.Orders.deserializeBinary = function(bytes) { +proto.xudrpc.OrderRemoval.deserializeBinary = function(bytes) { var reader = new jspb.BinaryReader(bytes); - var msg = new proto.xudrpc.Orders; - return proto.xudrpc.Orders.deserializeBinaryFromReader(msg, reader); + var msg = new proto.xudrpc.OrderRemoval; + return proto.xudrpc.OrderRemoval.deserializeBinaryFromReader(msg, reader); }; /** * Deserializes binary data (in protobuf wire format) from the * given reader into the given message object. - * @param {!proto.xudrpc.Orders} msg The message object to deserialize into. + * @param {!proto.xudrpc.OrderRemoval} msg The message object to deserialize into. * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.xudrpc.Orders} + * @return {!proto.xudrpc.OrderRemoval} */ -proto.xudrpc.Orders.deserializeBinaryFromReader = function(msg, reader) { +proto.xudrpc.OrderRemoval.deserializeBinaryFromReader = function(msg, reader) { while (reader.nextField()) { if (reader.isEndGroup()) { break; @@ -4673,14 +4694,24 @@ proto.xudrpc.Orders.deserializeBinaryFromReader = function(msg, reader) { var field = reader.getFieldNumber(); switch (field) { case 1: - var value = new proto.xudrpc.Order; - reader.readMessage(value,proto.xudrpc.Order.deserializeBinaryFromReader); - msg.addBuyOrders(value); + var value = /** @type {number} */ (reader.readDouble()); + msg.setQuantity(value); break; case 2: - var value = new proto.xudrpc.Order; - reader.readMessage(value,proto.xudrpc.Order.deserializeBinaryFromReader); - msg.addSellOrders(value); + var value = /** @type {string} */ (reader.readString()); + msg.setPairId(value); + break; + case 3: + var value = /** @type {string} */ (reader.readString()); + msg.setOrderId(value); + break; + case 4: + var value = /** @type {string} */ (reader.readString()); + msg.setLocalId(value); + break; + case 5: + var value = /** @type {boolean} */ (reader.readBool()); + msg.setIsOwnOrder(value); break; default: reader.skipField(); @@ -4695,9 +4726,9 @@ proto.xudrpc.Orders.deserializeBinaryFromReader = function(msg, reader) { * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.xudrpc.Orders.prototype.serializeBinary = function() { +proto.xudrpc.OrderRemoval.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - proto.xudrpc.Orders.serializeBinaryToWriter(this, writer); + proto.xudrpc.OrderRemoval.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; @@ -4705,90 +4736,124 @@ proto.xudrpc.Orders.prototype.serializeBinary = function() { /** * Serializes the given message to binary data (in protobuf wire * format), writing to the given BinaryWriter. - * @param {!proto.xudrpc.Orders} message + * @param {!proto.xudrpc.OrderRemoval} message * @param {!jspb.BinaryWriter} writer * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.Orders.serializeBinaryToWriter = function(message, writer) { +proto.xudrpc.OrderRemoval.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = message.getBuyOrdersList(); - if (f.length > 0) { - writer.writeRepeatedMessage( + f = message.getQuantity(); + if (f !== 0.0) { + writer.writeDouble( 1, - f, - proto.xudrpc.Order.serializeBinaryToWriter + f ); } - f = message.getSellOrdersList(); + f = message.getPairId(); if (f.length > 0) { - writer.writeRepeatedMessage( + writer.writeString( 2, - f, - proto.xudrpc.Order.serializeBinaryToWriter + f + ); + } + f = message.getOrderId(); + if (f.length > 0) { + writer.writeString( + 3, + f + ); + } + f = message.getLocalId(); + if (f.length > 0) { + writer.writeString( + 4, + f + ); + } + f = message.getIsOwnOrder(); + if (f) { + writer.writeBool( + 5, + f ); } }; /** - * repeated Order buy_orders = 1; - * @return {!Array.} + * optional double quantity = 1; + * @return {number} */ -proto.xudrpc.Orders.prototype.getBuyOrdersList = function() { - return /** @type{!Array.} */ ( - jspb.Message.getRepeatedWrapperField(this, proto.xudrpc.Order, 1)); +proto.xudrpc.OrderRemoval.prototype.getQuantity = function() { + return /** @type {number} */ (+jspb.Message.getFieldWithDefault(this, 1, 0.0)); }; -/** @param {!Array.} value */ -proto.xudrpc.Orders.prototype.setBuyOrdersList = function(value) { - jspb.Message.setRepeatedWrapperField(this, 1, value); +/** @param {number} value */ +proto.xudrpc.OrderRemoval.prototype.setQuantity = function(value) { + jspb.Message.setField(this, 1, value); }; /** - * @param {!proto.xudrpc.Order=} opt_value - * @param {number=} opt_index - * @return {!proto.xudrpc.Order} + * optional string pair_id = 2; + * @return {string} */ -proto.xudrpc.Orders.prototype.addBuyOrders = function(opt_value, opt_index) { - return jspb.Message.addToRepeatedWrapperField(this, 1, opt_value, proto.xudrpc.Order, opt_index); +proto.xudrpc.OrderRemoval.prototype.getPairId = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); }; -proto.xudrpc.Orders.prototype.clearBuyOrdersList = function() { - this.setBuyOrdersList([]); +/** @param {string} value */ +proto.xudrpc.OrderRemoval.prototype.setPairId = function(value) { + jspb.Message.setField(this, 2, value); }; /** - * repeated Order sell_orders = 2; - * @return {!Array.} + * optional string order_id = 3; + * @return {string} */ -proto.xudrpc.Orders.prototype.getSellOrdersList = function() { - return /** @type{!Array.} */ ( - jspb.Message.getRepeatedWrapperField(this, proto.xudrpc.Order, 2)); +proto.xudrpc.OrderRemoval.prototype.getOrderId = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); }; -/** @param {!Array.} value */ -proto.xudrpc.Orders.prototype.setSellOrdersList = function(value) { - jspb.Message.setRepeatedWrapperField(this, 2, value); +/** @param {string} value */ +proto.xudrpc.OrderRemoval.prototype.setOrderId = function(value) { + jspb.Message.setField(this, 3, value); }; /** - * @param {!proto.xudrpc.Order=} opt_value - * @param {number=} opt_index - * @return {!proto.xudrpc.Order} + * optional string local_id = 4; + * @return {string} */ -proto.xudrpc.Orders.prototype.addSellOrders = function(opt_value, opt_index) { - return jspb.Message.addToRepeatedWrapperField(this, 2, opt_value, proto.xudrpc.Order, opt_index); +proto.xudrpc.OrderRemoval.prototype.getLocalId = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 4, "")); }; -proto.xudrpc.Orders.prototype.clearSellOrdersList = function() { - this.setSellOrdersList([]); +/** @param {string} value */ +proto.xudrpc.OrderRemoval.prototype.setLocalId = function(value) { + jspb.Message.setField(this, 4, value); +}; + + +/** + * optional bool is_own_order = 5; + * Note that Boolean fields may be set to 0/1 when serialized from a Java server. + * You should avoid comparisons like {@code val === true/false} in those cases. + * @return {boolean} + */ +proto.xudrpc.OrderRemoval.prototype.getIsOwnOrder = function() { + return /** @type {boolean} */ (jspb.Message.getFieldWithDefault(this, 5, false)); +}; + + +/** @param {boolean} value */ +proto.xudrpc.OrderRemoval.prototype.setIsOwnOrder = function(value) { + jspb.Message.setField(this, 5, value); }; @@ -4803,13 +4868,20 @@ proto.xudrpc.Orders.prototype.clearSellOrdersList = function() { * @extends {jspb.Message} * @constructor */ -proto.xudrpc.OrderMatch = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, null, null); +proto.xudrpc.Orders = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, proto.xudrpc.Orders.repeatedFields_, null); }; -goog.inherits(proto.xudrpc.OrderMatch, jspb.Message); +goog.inherits(proto.xudrpc.Orders, jspb.Message); if (goog.DEBUG && !COMPILED) { - proto.xudrpc.OrderMatch.displayName = 'proto.xudrpc.OrderMatch'; + proto.xudrpc.Orders.displayName = 'proto.xudrpc.Orders'; } +/** + * List of repeated fields within this message type. + * @private {!Array} + * @const + */ +proto.xudrpc.Orders.repeatedFields_ = [1,2]; + if (jspb.Message.GENERATE_TO_OBJECT) { @@ -4823,8 +4895,215 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ -proto.xudrpc.OrderMatch.prototype.toObject = function(opt_includeInstance) { - return proto.xudrpc.OrderMatch.toObject(opt_includeInstance, this); +proto.xudrpc.Orders.prototype.toObject = function(opt_includeInstance) { + return proto.xudrpc.Orders.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.xudrpc.Orders} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.xudrpc.Orders.toObject = function(includeInstance, msg) { + var f, obj = { + buyOrdersList: jspb.Message.toObjectList(msg.getBuyOrdersList(), + proto.xudrpc.Order.toObject, includeInstance), + sellOrdersList: jspb.Message.toObjectList(msg.getSellOrdersList(), + proto.xudrpc.Order.toObject, includeInstance) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.xudrpc.Orders} + */ +proto.xudrpc.Orders.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.xudrpc.Orders; + return proto.xudrpc.Orders.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.xudrpc.Orders} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.xudrpc.Orders} + */ +proto.xudrpc.Orders.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = new proto.xudrpc.Order; + reader.readMessage(value,proto.xudrpc.Order.deserializeBinaryFromReader); + msg.addBuyOrders(value); + break; + case 2: + var value = new proto.xudrpc.Order; + reader.readMessage(value,proto.xudrpc.Order.deserializeBinaryFromReader); + msg.addSellOrders(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.xudrpc.Orders.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.xudrpc.Orders.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.xudrpc.Orders} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.xudrpc.Orders.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getBuyOrdersList(); + if (f.length > 0) { + writer.writeRepeatedMessage( + 1, + f, + proto.xudrpc.Order.serializeBinaryToWriter + ); + } + f = message.getSellOrdersList(); + if (f.length > 0) { + writer.writeRepeatedMessage( + 2, + f, + proto.xudrpc.Order.serializeBinaryToWriter + ); + } +}; + + +/** + * repeated Order buy_orders = 1; + * @return {!Array.} + */ +proto.xudrpc.Orders.prototype.getBuyOrdersList = function() { + return /** @type{!Array.} */ ( + jspb.Message.getRepeatedWrapperField(this, proto.xudrpc.Order, 1)); +}; + + +/** @param {!Array.} value */ +proto.xudrpc.Orders.prototype.setBuyOrdersList = function(value) { + jspb.Message.setRepeatedWrapperField(this, 1, value); +}; + + +/** + * @param {!proto.xudrpc.Order=} opt_value + * @param {number=} opt_index + * @return {!proto.xudrpc.Order} + */ +proto.xudrpc.Orders.prototype.addBuyOrders = function(opt_value, opt_index) { + return jspb.Message.addToRepeatedWrapperField(this, 1, opt_value, proto.xudrpc.Order, opt_index); +}; + + +proto.xudrpc.Orders.prototype.clearBuyOrdersList = function() { + this.setBuyOrdersList([]); +}; + + +/** + * repeated Order sell_orders = 2; + * @return {!Array.} + */ +proto.xudrpc.Orders.prototype.getSellOrdersList = function() { + return /** @type{!Array.} */ ( + jspb.Message.getRepeatedWrapperField(this, proto.xudrpc.Order, 2)); +}; + + +/** @param {!Array.} value */ +proto.xudrpc.Orders.prototype.setSellOrdersList = function(value) { + jspb.Message.setRepeatedWrapperField(this, 2, value); +}; + + +/** + * @param {!proto.xudrpc.Order=} opt_value + * @param {number=} opt_index + * @return {!proto.xudrpc.Order} + */ +proto.xudrpc.Orders.prototype.addSellOrders = function(opt_value, opt_index) { + return jspb.Message.addToRepeatedWrapperField(this, 2, opt_value, proto.xudrpc.Order, opt_index); +}; + + +proto.xudrpc.Orders.prototype.clearSellOrdersList = function() { + this.setSellOrdersList([]); +}; + + + +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.xudrpc.OrderMatch = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.xudrpc.OrderMatch, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.xudrpc.OrderMatch.displayName = 'proto.xudrpc.OrderMatch'; +} + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto suitable for use in Soy templates. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. + * @param {boolean=} opt_includeInstance Whether to include the JSPB instance + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.xudrpc.OrderMatch.prototype.toObject = function(opt_includeInstance) { + return proto.xudrpc.OrderMatch.toObject(opt_includeInstance, this); }; @@ -6577,368 +6856,91 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * For the list of reserved names please see: * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. * @param {boolean=} opt_includeInstance Whether to include the JSPB instance - * for transitional soy proto support: http://goto/soy-param-migration - * @return {!Object} - */ -proto.xudrpc.RemovePairResponse.prototype.toObject = function(opt_includeInstance) { - return proto.xudrpc.RemovePairResponse.toObject(opt_includeInstance, this); -}; - - -/** - * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Whether to include the JSPB - * instance for transitional soy proto support: - * http://goto/soy-param-migration - * @param {!proto.xudrpc.RemovePairResponse} msg The msg instance to transform. - * @return {!Object} - * @suppress {unusedLocalVariables} f is only used for nested messages - */ -proto.xudrpc.RemovePairResponse.toObject = function(includeInstance, msg) { - var f, obj = { - - }; - - if (includeInstance) { - obj.$jspbMessageInstance = msg; - } - return obj; -}; -} - - -/** - * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.xudrpc.RemovePairResponse} - */ -proto.xudrpc.RemovePairResponse.deserializeBinary = function(bytes) { - var reader = new jspb.BinaryReader(bytes); - var msg = new proto.xudrpc.RemovePairResponse; - return proto.xudrpc.RemovePairResponse.deserializeBinaryFromReader(msg, reader); -}; - - -/** - * Deserializes binary data (in protobuf wire format) from the - * given reader into the given message object. - * @param {!proto.xudrpc.RemovePairResponse} msg The message object to deserialize into. - * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.xudrpc.RemovePairResponse} - */ -proto.xudrpc.RemovePairResponse.deserializeBinaryFromReader = function(msg, reader) { - while (reader.nextField()) { - if (reader.isEndGroup()) { - break; - } - var field = reader.getFieldNumber(); - switch (field) { - default: - reader.skipField(); - break; - } - } - return msg; -}; - - -/** - * Serializes the message to binary data (in protobuf wire format). - * @return {!Uint8Array} - */ -proto.xudrpc.RemovePairResponse.prototype.serializeBinary = function() { - var writer = new jspb.BinaryWriter(); - proto.xudrpc.RemovePairResponse.serializeBinaryToWriter(this, writer); - return writer.getResultBuffer(); -}; - - -/** - * Serializes the given message to binary data (in protobuf wire - * format), writing to the given BinaryWriter. - * @param {!proto.xudrpc.RemovePairResponse} message - * @param {!jspb.BinaryWriter} writer - * @suppress {unusedLocalVariables} f is only used for nested messages - */ -proto.xudrpc.RemovePairResponse.serializeBinaryToWriter = function(message, writer) { - var f = undefined; -}; - - - -/** - * Generated by JsPbCodeGenerator. - * @param {Array=} opt_data Optional initial data array, typically from a - * server response, or constructed directly in Javascript. The array is used - * in place and becomes part of the constructed object. It is not cloned. - * If no data is provided, the constructed object will be empty, but still - * valid. - * @extends {jspb.Message} - * @constructor - */ -proto.xudrpc.SwapPayload = function(opt_data) { - jspb.Message.initialize(this, opt_data, 0, -1, null, null); -}; -goog.inherits(proto.xudrpc.SwapPayload, jspb.Message); -if (goog.DEBUG && !COMPILED) { - proto.xudrpc.SwapPayload.displayName = 'proto.xudrpc.SwapPayload'; -} - - -if (jspb.Message.GENERATE_TO_OBJECT) { -/** - * Creates an object representation of this proto suitable for use in Soy templates. - * Field names that are reserved in JavaScript and will be renamed to pb_name. - * To access a reserved field use, foo.pb_, eg, foo.pb_default. - * For the list of reserved names please see: - * com.google.apps.jspb.JsClassTemplate.JS_RESERVED_WORDS. - * @param {boolean=} opt_includeInstance Whether to include the JSPB instance - * for transitional soy proto support: http://goto/soy-param-migration - * @return {!Object} - */ -proto.xudrpc.SwapPayload.prototype.toObject = function(opt_includeInstance) { - return proto.xudrpc.SwapPayload.toObject(opt_includeInstance, this); -}; - - -/** - * Static version of the {@see toObject} method. - * @param {boolean|undefined} includeInstance Whether to include the JSPB - * instance for transitional soy proto support: - * http://goto/soy-param-migration - * @param {!proto.xudrpc.SwapPayload} msg The msg instance to transform. - * @return {!Object} - * @suppress {unusedLocalVariables} f is only used for nested messages - */ -proto.xudrpc.SwapPayload.toObject = function(includeInstance, msg) { - var f, obj = { - role: jspb.Message.getFieldWithDefault(msg, 1, ""), - sendingAmount: jspb.Message.getFieldWithDefault(msg, 2, 0), - sendingToken: jspb.Message.getFieldWithDefault(msg, 3, ""), - receivingAmount: jspb.Message.getFieldWithDefault(msg, 4, 0), - receivingToken: jspb.Message.getFieldWithDefault(msg, 5, ""), - nodePubKey: jspb.Message.getFieldWithDefault(msg, 6, "") - }; - - if (includeInstance) { - obj.$jspbMessageInstance = msg; - } - return obj; -}; -} - - -/** - * Deserializes binary data (in protobuf wire format). - * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.xudrpc.SwapPayload} - */ -proto.xudrpc.SwapPayload.deserializeBinary = function(bytes) { - var reader = new jspb.BinaryReader(bytes); - var msg = new proto.xudrpc.SwapPayload; - return proto.xudrpc.SwapPayload.deserializeBinaryFromReader(msg, reader); -}; - - -/** - * Deserializes binary data (in protobuf wire format) from the - * given reader into the given message object. - * @param {!proto.xudrpc.SwapPayload} msg The message object to deserialize into. - * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.xudrpc.SwapPayload} - */ -proto.xudrpc.SwapPayload.deserializeBinaryFromReader = function(msg, reader) { - while (reader.nextField()) { - if (reader.isEndGroup()) { - break; - } - var field = reader.getFieldNumber(); - switch (field) { - case 1: - var value = /** @type {string} */ (reader.readString()); - msg.setRole(value); - break; - case 2: - var value = /** @type {number} */ (reader.readUint64()); - msg.setSendingAmount(value); - break; - case 3: - var value = /** @type {string} */ (reader.readString()); - msg.setSendingToken(value); - break; - case 4: - var value = /** @type {number} */ (reader.readUint64()); - msg.setReceivingAmount(value); - break; - case 5: - var value = /** @type {string} */ (reader.readString()); - msg.setReceivingToken(value); - break; - case 6: - var value = /** @type {string} */ (reader.readString()); - msg.setNodePubKey(value); - break; - default: - reader.skipField(); - break; - } - } - return msg; -}; - - -/** - * Serializes the message to binary data (in protobuf wire format). - * @return {!Uint8Array} - */ -proto.xudrpc.SwapPayload.prototype.serializeBinary = function() { - var writer = new jspb.BinaryWriter(); - proto.xudrpc.SwapPayload.serializeBinaryToWriter(this, writer); - return writer.getResultBuffer(); -}; - - -/** - * Serializes the given message to binary data (in protobuf wire - * format), writing to the given BinaryWriter. - * @param {!proto.xudrpc.SwapPayload} message - * @param {!jspb.BinaryWriter} writer - * @suppress {unusedLocalVariables} f is only used for nested messages - */ -proto.xudrpc.SwapPayload.serializeBinaryToWriter = function(message, writer) { - var f = undefined; - f = message.getRole(); - if (f.length > 0) { - writer.writeString( - 1, - f - ); - } - f = message.getSendingAmount(); - if (f !== 0) { - writer.writeUint64( - 2, - f - ); - } - f = message.getSendingToken(); - if (f.length > 0) { - writer.writeString( - 3, - f - ); - } - f = message.getReceivingAmount(); - if (f !== 0) { - writer.writeUint64( - 4, - f - ); - } - f = message.getReceivingToken(); - if (f.length > 0) { - writer.writeString( - 5, - f - ); - } - f = message.getNodePubKey(); - if (f.length > 0) { - writer.writeString( - 6, - f - ); - } -}; - - -/** - * optional string role = 1; - * @return {string} - */ -proto.xudrpc.SwapPayload.prototype.getRole = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); -}; - - -/** @param {string} value */ -proto.xudrpc.SwapPayload.prototype.setRole = function(value) { - jspb.Message.setField(this, 1, value); -}; - - -/** - * optional uint64 sending_amount = 2; - * @return {number} - */ -proto.xudrpc.SwapPayload.prototype.getSendingAmount = function() { - return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); -}; - - -/** @param {number} value */ -proto.xudrpc.SwapPayload.prototype.setSendingAmount = function(value) { - jspb.Message.setField(this, 2, value); + * for transitional soy proto support: http://goto/soy-param-migration + * @return {!Object} + */ +proto.xudrpc.RemovePairResponse.prototype.toObject = function(opt_includeInstance) { + return proto.xudrpc.RemovePairResponse.toObject(opt_includeInstance, this); }; /** - * optional string sending_token = 3; - * @return {string} + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Whether to include the JSPB + * instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.xudrpc.RemovePairResponse} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.SwapPayload.prototype.getSendingToken = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); -}; +proto.xudrpc.RemovePairResponse.toObject = function(includeInstance, msg) { + var f, obj = { + }; -/** @param {string} value */ -proto.xudrpc.SwapPayload.prototype.setSendingToken = function(value) { - jspb.Message.setField(this, 3, value); + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; }; +} /** - * optional uint64 receiving_amount = 4; - * @return {number} + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.xudrpc.RemovePairResponse} */ -proto.xudrpc.SwapPayload.prototype.getReceivingAmount = function() { - return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 4, 0)); -}; - - -/** @param {number} value */ -proto.xudrpc.SwapPayload.prototype.setReceivingAmount = function(value) { - jspb.Message.setField(this, 4, value); +proto.xudrpc.RemovePairResponse.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.xudrpc.RemovePairResponse; + return proto.xudrpc.RemovePairResponse.deserializeBinaryFromReader(msg, reader); }; /** - * optional string receiving_token = 5; - * @return {string} + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.xudrpc.RemovePairResponse} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.xudrpc.RemovePairResponse} */ -proto.xudrpc.SwapPayload.prototype.getReceivingToken = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 5, "")); -}; - - -/** @param {string} value */ -proto.xudrpc.SwapPayload.prototype.setReceivingToken = function(value) { - jspb.Message.setField(this, 5, value); +proto.xudrpc.RemovePairResponse.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + default: + reader.skipField(); + break; + } + } + return msg; }; /** - * optional string node_pub_key = 6; - * @return {string} + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} */ -proto.xudrpc.SwapPayload.prototype.getNodePubKey = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 6, "")); +proto.xudrpc.RemovePairResponse.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.xudrpc.RemovePairResponse.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); }; -/** @param {string} value */ -proto.xudrpc.SwapPayload.prototype.setNodePubKey = function(value) { - jspb.Message.setField(this, 6, value); +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.xudrpc.RemovePairResponse} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.xudrpc.RemovePairResponse.serializeBinaryToWriter = function(message, writer) { + var f = undefined; }; @@ -7185,12 +7187,12 @@ proto.xudrpc.ShutdownResponse.serializeBinaryToWriter = function(message, writer * @extends {jspb.Message} * @constructor */ -proto.xudrpc.SubscribePeerOrdersRequest = function(opt_data) { +proto.xudrpc.SubscribeAddedOrdersRequest = function(opt_data) { jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; -goog.inherits(proto.xudrpc.SubscribePeerOrdersRequest, jspb.Message); +goog.inherits(proto.xudrpc.SubscribeAddedOrdersRequest, jspb.Message); if (goog.DEBUG && !COMPILED) { - proto.xudrpc.SubscribePeerOrdersRequest.displayName = 'proto.xudrpc.SubscribePeerOrdersRequest'; + proto.xudrpc.SubscribeAddedOrdersRequest.displayName = 'proto.xudrpc.SubscribeAddedOrdersRequest'; } @@ -7205,8 +7207,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ -proto.xudrpc.SubscribePeerOrdersRequest.prototype.toObject = function(opt_includeInstance) { - return proto.xudrpc.SubscribePeerOrdersRequest.toObject(opt_includeInstance, this); +proto.xudrpc.SubscribeAddedOrdersRequest.prototype.toObject = function(opt_includeInstance) { + return proto.xudrpc.SubscribeAddedOrdersRequest.toObject(opt_includeInstance, this); }; @@ -7215,11 +7217,11 @@ proto.xudrpc.SubscribePeerOrdersRequest.prototype.toObject = function(opt_includ * @param {boolean|undefined} includeInstance Whether to include the JSPB * instance for transitional soy proto support: * http://goto/soy-param-migration - * @param {!proto.xudrpc.SubscribePeerOrdersRequest} msg The msg instance to transform. + * @param {!proto.xudrpc.SubscribeAddedOrdersRequest} msg The msg instance to transform. * @return {!Object} * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.SubscribePeerOrdersRequest.toObject = function(includeInstance, msg) { +proto.xudrpc.SubscribeAddedOrdersRequest.toObject = function(includeInstance, msg) { var f, obj = { }; @@ -7235,23 +7237,23 @@ proto.xudrpc.SubscribePeerOrdersRequest.toObject = function(includeInstance, msg /** * Deserializes binary data (in protobuf wire format). * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.xudrpc.SubscribePeerOrdersRequest} + * @return {!proto.xudrpc.SubscribeAddedOrdersRequest} */ -proto.xudrpc.SubscribePeerOrdersRequest.deserializeBinary = function(bytes) { +proto.xudrpc.SubscribeAddedOrdersRequest.deserializeBinary = function(bytes) { var reader = new jspb.BinaryReader(bytes); - var msg = new proto.xudrpc.SubscribePeerOrdersRequest; - return proto.xudrpc.SubscribePeerOrdersRequest.deserializeBinaryFromReader(msg, reader); + var msg = new proto.xudrpc.SubscribeAddedOrdersRequest; + return proto.xudrpc.SubscribeAddedOrdersRequest.deserializeBinaryFromReader(msg, reader); }; /** * Deserializes binary data (in protobuf wire format) from the * given reader into the given message object. - * @param {!proto.xudrpc.SubscribePeerOrdersRequest} msg The message object to deserialize into. + * @param {!proto.xudrpc.SubscribeAddedOrdersRequest} msg The message object to deserialize into. * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.xudrpc.SubscribePeerOrdersRequest} + * @return {!proto.xudrpc.SubscribeAddedOrdersRequest} */ -proto.xudrpc.SubscribePeerOrdersRequest.deserializeBinaryFromReader = function(msg, reader) { +proto.xudrpc.SubscribeAddedOrdersRequest.deserializeBinaryFromReader = function(msg, reader) { while (reader.nextField()) { if (reader.isEndGroup()) { break; @@ -7271,9 +7273,9 @@ proto.xudrpc.SubscribePeerOrdersRequest.deserializeBinaryFromReader = function(m * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.xudrpc.SubscribePeerOrdersRequest.prototype.serializeBinary = function() { +proto.xudrpc.SubscribeAddedOrdersRequest.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - proto.xudrpc.SubscribePeerOrdersRequest.serializeBinaryToWriter(this, writer); + proto.xudrpc.SubscribeAddedOrdersRequest.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; @@ -7281,11 +7283,11 @@ proto.xudrpc.SubscribePeerOrdersRequest.prototype.serializeBinary = function() { /** * Serializes the given message to binary data (in protobuf wire * format), writing to the given BinaryWriter. - * @param {!proto.xudrpc.SubscribePeerOrdersRequest} message + * @param {!proto.xudrpc.SubscribeAddedOrdersRequest} message * @param {!jspb.BinaryWriter} writer * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.SubscribePeerOrdersRequest.serializeBinaryToWriter = function(message, writer) { +proto.xudrpc.SubscribeAddedOrdersRequest.serializeBinaryToWriter = function(message, writer) { var f = undefined; }; @@ -7301,12 +7303,12 @@ proto.xudrpc.SubscribePeerOrdersRequest.serializeBinaryToWriter = function(messa * @extends {jspb.Message} * @constructor */ -proto.xudrpc.SubscribePeerOrdersResponse = function(opt_data) { +proto.xudrpc.SubscribeRemovedOrdersRequest = function(opt_data) { jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; -goog.inherits(proto.xudrpc.SubscribePeerOrdersResponse, jspb.Message); +goog.inherits(proto.xudrpc.SubscribeRemovedOrdersRequest, jspb.Message); if (goog.DEBUG && !COMPILED) { - proto.xudrpc.SubscribePeerOrdersResponse.displayName = 'proto.xudrpc.SubscribePeerOrdersResponse'; + proto.xudrpc.SubscribeRemovedOrdersRequest.displayName = 'proto.xudrpc.SubscribeRemovedOrdersRequest'; } @@ -7321,8 +7323,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ -proto.xudrpc.SubscribePeerOrdersResponse.prototype.toObject = function(opt_includeInstance) { - return proto.xudrpc.SubscribePeerOrdersResponse.toObject(opt_includeInstance, this); +proto.xudrpc.SubscribeRemovedOrdersRequest.prototype.toObject = function(opt_includeInstance) { + return proto.xudrpc.SubscribeRemovedOrdersRequest.toObject(opt_includeInstance, this); }; @@ -7331,13 +7333,13 @@ proto.xudrpc.SubscribePeerOrdersResponse.prototype.toObject = function(opt_inclu * @param {boolean|undefined} includeInstance Whether to include the JSPB * instance for transitional soy proto support: * http://goto/soy-param-migration - * @param {!proto.xudrpc.SubscribePeerOrdersResponse} msg The msg instance to transform. + * @param {!proto.xudrpc.SubscribeRemovedOrdersRequest} msg The msg instance to transform. * @return {!Object} * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.SubscribePeerOrdersResponse.toObject = function(includeInstance, msg) { +proto.xudrpc.SubscribeRemovedOrdersRequest.toObject = function(includeInstance, msg) { var f, obj = { - order: (f = msg.getOrder()) && proto.xudrpc.Order.toObject(includeInstance, f) + }; if (includeInstance) { @@ -7351,34 +7353,29 @@ proto.xudrpc.SubscribePeerOrdersResponse.toObject = function(includeInstance, ms /** * Deserializes binary data (in protobuf wire format). * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.xudrpc.SubscribePeerOrdersResponse} + * @return {!proto.xudrpc.SubscribeRemovedOrdersRequest} */ -proto.xudrpc.SubscribePeerOrdersResponse.deserializeBinary = function(bytes) { +proto.xudrpc.SubscribeRemovedOrdersRequest.deserializeBinary = function(bytes) { var reader = new jspb.BinaryReader(bytes); - var msg = new proto.xudrpc.SubscribePeerOrdersResponse; - return proto.xudrpc.SubscribePeerOrdersResponse.deserializeBinaryFromReader(msg, reader); + var msg = new proto.xudrpc.SubscribeRemovedOrdersRequest; + return proto.xudrpc.SubscribeRemovedOrdersRequest.deserializeBinaryFromReader(msg, reader); }; /** * Deserializes binary data (in protobuf wire format) from the * given reader into the given message object. - * @param {!proto.xudrpc.SubscribePeerOrdersResponse} msg The message object to deserialize into. + * @param {!proto.xudrpc.SubscribeRemovedOrdersRequest} msg The message object to deserialize into. * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.xudrpc.SubscribePeerOrdersResponse} + * @return {!proto.xudrpc.SubscribeRemovedOrdersRequest} */ -proto.xudrpc.SubscribePeerOrdersResponse.deserializeBinaryFromReader = function(msg, reader) { +proto.xudrpc.SubscribeRemovedOrdersRequest.deserializeBinaryFromReader = function(msg, reader) { while (reader.nextField()) { if (reader.isEndGroup()) { break; } var field = reader.getFieldNumber(); switch (field) { - case 1: - var value = new proto.xudrpc.Order; - reader.readMessage(value,proto.xudrpc.Order.deserializeBinaryFromReader); - msg.setOrder(value); - break; default: reader.skipField(); break; @@ -7392,9 +7389,9 @@ proto.xudrpc.SubscribePeerOrdersResponse.deserializeBinaryFromReader = function( * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.xudrpc.SubscribePeerOrdersResponse.prototype.serializeBinary = function() { +proto.xudrpc.SubscribeRemovedOrdersRequest.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - proto.xudrpc.SubscribePeerOrdersResponse.serializeBinaryToWriter(this, writer); + proto.xudrpc.SubscribeRemovedOrdersRequest.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; @@ -7402,50 +7399,12 @@ proto.xudrpc.SubscribePeerOrdersResponse.prototype.serializeBinary = function() /** * Serializes the given message to binary data (in protobuf wire * format), writing to the given BinaryWriter. - * @param {!proto.xudrpc.SubscribePeerOrdersResponse} message + * @param {!proto.xudrpc.SubscribeRemovedOrdersRequest} message * @param {!jspb.BinaryWriter} writer * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.SubscribePeerOrdersResponse.serializeBinaryToWriter = function(message, writer) { +proto.xudrpc.SubscribeRemovedOrdersRequest.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = message.getOrder(); - if (f != null) { - writer.writeMessage( - 1, - f, - proto.xudrpc.Order.serializeBinaryToWriter - ); - } -}; - - -/** - * optional Order order = 1; - * @return {?proto.xudrpc.Order} - */ -proto.xudrpc.SubscribePeerOrdersResponse.prototype.getOrder = function() { - return /** @type{?proto.xudrpc.Order} */ ( - jspb.Message.getWrapperField(this, proto.xudrpc.Order, 1)); -}; - - -/** @param {?proto.xudrpc.Order|undefined} value */ -proto.xudrpc.SubscribePeerOrdersResponse.prototype.setOrder = function(value) { - jspb.Message.setWrapperField(this, 1, value); -}; - - -proto.xudrpc.SubscribePeerOrdersResponse.prototype.clearOrder = function() { - this.setOrder(undefined); -}; - - -/** - * Returns whether this field is set. - * @return {!boolean} - */ -proto.xudrpc.SubscribePeerOrdersResponse.prototype.hasOrder = function() { - return jspb.Message.getField(this, 1) != null; }; @@ -7576,12 +7535,12 @@ proto.xudrpc.SubscribeSwapsRequest.serializeBinaryToWriter = function(message, w * @extends {jspb.Message} * @constructor */ -proto.xudrpc.SubscribeSwapsResponse = function(opt_data) { +proto.xudrpc.Swap = function(opt_data) { jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; -goog.inherits(proto.xudrpc.SubscribeSwapsResponse, jspb.Message); +goog.inherits(proto.xudrpc.Swap, jspb.Message); if (goog.DEBUG && !COMPILED) { - proto.xudrpc.SubscribeSwapsResponse.displayName = 'proto.xudrpc.SubscribeSwapsResponse'; + proto.xudrpc.Swap.displayName = 'proto.xudrpc.Swap'; } @@ -7596,8 +7555,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ -proto.xudrpc.SubscribeSwapsResponse.prototype.toObject = function(opt_includeInstance) { - return proto.xudrpc.SubscribeSwapsResponse.toObject(opt_includeInstance, this); +proto.xudrpc.Swap.prototype.toObject = function(opt_includeInstance) { + return proto.xudrpc.Swap.toObject(opt_includeInstance, this); }; @@ -7606,13 +7565,19 @@ proto.xudrpc.SubscribeSwapsResponse.prototype.toObject = function(opt_includeIns * @param {boolean|undefined} includeInstance Whether to include the JSPB * instance for transitional soy proto support: * http://goto/soy-param-migration - * @param {!proto.xudrpc.SubscribeSwapsResponse} msg The msg instance to transform. + * @param {!proto.xudrpc.Swap} msg The msg instance to transform. * @return {!Object} * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.SubscribeSwapsResponse.toObject = function(includeInstance, msg) { +proto.xudrpc.Swap.toObject = function(includeInstance, msg) { var f, obj = { - order: jspb.Message.getFieldWithDefault(msg, 1, "") + orderId: jspb.Message.getFieldWithDefault(msg, 1, ""), + localId: jspb.Message.getFieldWithDefault(msg, 2, ""), + pairId: jspb.Message.getFieldWithDefault(msg, 3, ""), + rHash: jspb.Message.getFieldWithDefault(msg, 4, ""), + amountReceived: jspb.Message.getFieldWithDefault(msg, 5, 0), + amountSent: jspb.Message.getFieldWithDefault(msg, 6, 0), + peerPubKey: jspb.Message.getFieldWithDefault(msg, 7, "") }; if (includeInstance) { @@ -7626,23 +7591,23 @@ proto.xudrpc.SubscribeSwapsResponse.toObject = function(includeInstance, msg) { /** * Deserializes binary data (in protobuf wire format). * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.xudrpc.SubscribeSwapsResponse} + * @return {!proto.xudrpc.Swap} */ -proto.xudrpc.SubscribeSwapsResponse.deserializeBinary = function(bytes) { +proto.xudrpc.Swap.deserializeBinary = function(bytes) { var reader = new jspb.BinaryReader(bytes); - var msg = new proto.xudrpc.SubscribeSwapsResponse; - return proto.xudrpc.SubscribeSwapsResponse.deserializeBinaryFromReader(msg, reader); + var msg = new proto.xudrpc.Swap; + return proto.xudrpc.Swap.deserializeBinaryFromReader(msg, reader); }; /** * Deserializes binary data (in protobuf wire format) from the * given reader into the given message object. - * @param {!proto.xudrpc.SubscribeSwapsResponse} msg The message object to deserialize into. + * @param {!proto.xudrpc.Swap} msg The message object to deserialize into. * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.xudrpc.SubscribeSwapsResponse} + * @return {!proto.xudrpc.Swap} */ -proto.xudrpc.SubscribeSwapsResponse.deserializeBinaryFromReader = function(msg, reader) { +proto.xudrpc.Swap.deserializeBinaryFromReader = function(msg, reader) { while (reader.nextField()) { if (reader.isEndGroup()) { break; @@ -7651,7 +7616,31 @@ proto.xudrpc.SubscribeSwapsResponse.deserializeBinaryFromReader = function(msg, switch (field) { case 1: var value = /** @type {string} */ (reader.readString()); - msg.setOrder(value); + msg.setOrderId(value); + break; + case 2: + var value = /** @type {string} */ (reader.readString()); + msg.setLocalId(value); + break; + case 3: + var value = /** @type {string} */ (reader.readString()); + msg.setPairId(value); + break; + case 4: + var value = /** @type {string} */ (reader.readString()); + msg.setRHash(value); + break; + case 5: + var value = /** @type {number} */ (reader.readInt64()); + msg.setAmountReceived(value); + break; + case 6: + var value = /** @type {number} */ (reader.readInt64()); + msg.setAmountSent(value); + break; + case 7: + var value = /** @type {string} */ (reader.readString()); + msg.setPeerPubKey(value); break; default: reader.skipField(); @@ -7666,9 +7655,9 @@ proto.xudrpc.SubscribeSwapsResponse.deserializeBinaryFromReader = function(msg, * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.xudrpc.SubscribeSwapsResponse.prototype.serializeBinary = function() { +proto.xudrpc.Swap.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - proto.xudrpc.SubscribeSwapsResponse.serializeBinaryToWriter(this, writer); + proto.xudrpc.Swap.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; @@ -7676,37 +7665,169 @@ proto.xudrpc.SubscribeSwapsResponse.prototype.serializeBinary = function() { /** * Serializes the given message to binary data (in protobuf wire * format), writing to the given BinaryWriter. - * @param {!proto.xudrpc.SubscribeSwapsResponse} message + * @param {!proto.xudrpc.Swap} message * @param {!jspb.BinaryWriter} writer * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.xudrpc.SubscribeSwapsResponse.serializeBinaryToWriter = function(message, writer) { +proto.xudrpc.Swap.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = message.getOrder(); + f = message.getOrderId(); if (f.length > 0) { writer.writeString( 1, f ); } + f = message.getLocalId(); + if (f.length > 0) { + writer.writeString( + 2, + f + ); + } + f = message.getPairId(); + if (f.length > 0) { + writer.writeString( + 3, + f + ); + } + f = message.getRHash(); + if (f.length > 0) { + writer.writeString( + 4, + f + ); + } + f = message.getAmountReceived(); + if (f !== 0) { + writer.writeInt64( + 5, + f + ); + } + f = message.getAmountSent(); + if (f !== 0) { + writer.writeInt64( + 6, + f + ); + } + f = message.getPeerPubKey(); + if (f.length > 0) { + writer.writeString( + 7, + f + ); + } }; /** - * optional string order = 1; + * optional string order_id = 1; * @return {string} */ -proto.xudrpc.SubscribeSwapsResponse.prototype.getOrder = function() { +proto.xudrpc.Swap.prototype.getOrderId = function() { return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); }; /** @param {string} value */ -proto.xudrpc.SubscribeSwapsResponse.prototype.setOrder = function(value) { +proto.xudrpc.Swap.prototype.setOrderId = function(value) { jspb.Message.setField(this, 1, value); }; +/** + * optional string local_id = 2; + * @return {string} + */ +proto.xudrpc.Swap.prototype.getLocalId = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); +}; + + +/** @param {string} value */ +proto.xudrpc.Swap.prototype.setLocalId = function(value) { + jspb.Message.setField(this, 2, value); +}; + + +/** + * optional string pair_id = 3; + * @return {string} + */ +proto.xudrpc.Swap.prototype.getPairId = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); +}; + + +/** @param {string} value */ +proto.xudrpc.Swap.prototype.setPairId = function(value) { + jspb.Message.setField(this, 3, value); +}; + + +/** + * optional string r_hash = 4; + * @return {string} + */ +proto.xudrpc.Swap.prototype.getRHash = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 4, "")); +}; + + +/** @param {string} value */ +proto.xudrpc.Swap.prototype.setRHash = function(value) { + jspb.Message.setField(this, 4, value); +}; + + +/** + * optional int64 amount_received = 5; + * @return {number} + */ +proto.xudrpc.Swap.prototype.getAmountReceived = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 5, 0)); +}; + + +/** @param {number} value */ +proto.xudrpc.Swap.prototype.setAmountReceived = function(value) { + jspb.Message.setField(this, 5, value); +}; + + +/** + * optional int64 amount_sent = 6; + * @return {number} + */ +proto.xudrpc.Swap.prototype.getAmountSent = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 6, 0)); +}; + + +/** @param {number} value */ +proto.xudrpc.Swap.prototype.setAmountSent = function(value) { + jspb.Message.setField(this, 6, value); +}; + + +/** + * optional string peer_pub_key = 7; + * @return {string} + */ +proto.xudrpc.Swap.prototype.getPeerPubKey = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 7, "")); +}; + + +/** @param {string} value */ +proto.xudrpc.Swap.prototype.setPeerPubKey = function(value) { + jspb.Message.setField(this, 7, value); +}; + + /** * @enum {number} */ diff --git a/lib/service/Service.ts b/lib/service/Service.ts index c43d27ad6..025048248 100644 --- a/lib/service/Service.ts +++ b/lib/service/Service.ts @@ -5,10 +5,10 @@ import LndClient, { LndInfo } from '../lndclient/LndClient'; import RaidenClient, { RaidenInfo } from '../raidenclient/RaidenClient'; import { EventEmitter } from 'events'; import errors from './errors'; -import { SwapClients, OrderSide } from '../types/enums'; +import { SwapClients, OrderSide, SwapDealRole } from '../types/enums'; import { parseUri, getUri, UriParts } from '../utils/utils'; import * as lndrpc from '../proto/lndrpc_pb'; -import { Pair } from '../types/orders'; +import { Pair, StampedPeerOrder, SwapResult, OrderPortion } from '../types/orders'; import Swaps from '../swaps/Swaps'; import { OrderSidesArrays } from '../orderbook/MatchingEngine'; @@ -319,22 +319,34 @@ class Service extends EventEmitter { } /* - * Subscribe to incoming peer orders. + * Subscribe to orders being added to the order book. */ - public subscribePeerOrders = async (callback: Function) => { + public subscribeAddedOrders = async (callback: (order: StampedPeerOrder) => void) => { this.orderBook.on('peerOrder.incoming', order => callback(order)); - this.orderBook.on('peerOrder.invalidation', order => callback({ - canceled: true, - id: order.orderId, - pairId: order.pairId, - quantity: order.quantity, - })); + // TODO: send message on remaining order from placeOrder + } + + /** + * Subscribe to orders being removed from the order book. + */ + public subscribeRemovedOrders = async (callback: (order: OrderPortion) => void) => { + this.orderBook.on('peerOrder.invalidation', order => callback(order)); + this.orderBook.on('ownOrder.filled', order => callback(order)); + // TODO: send message when peerOrder is filled by one of our taker orders + // TODO: send message when one of our maker orders is filled remotely via swap } /* - * Subscribe to executed swaps + * Subscribe to completed swaps that are initiated by a remote peer. */ - public subscribeSwaps = async (_callback: Function) => {}; + public subscribeSwaps = async (callback: (swapResult: SwapResult) => void) => { + this.swaps.on('swap.paid', (swapResult, myRole) => { + if (myRole === SwapDealRole.Maker) { + // only alert client for maker matches, taker matches are handled via placeOrder + callback(swapResult); + } + }); + } /** * resolveHash resolve hash to preimage. diff --git a/lib/swaps/Swaps.ts b/lib/swaps/Swaps.ts index 91e21f756..ee782c1fb 100644 --- a/lib/swaps/Swaps.ts +++ b/lib/swaps/Swaps.ts @@ -7,7 +7,7 @@ import * as lndrpc from '../proto/lndrpc_pb'; import LndClient from '../lndclient/LndClient'; import Pool from '../p2p/Pool'; import { EventEmitter } from 'events'; -import { StampedOwnOrder, StampedPeerOrder } from '../types/orders'; +import { StampedOwnOrder, StampedPeerOrder, SwapResult } from '../types/orders'; import assert from 'assert'; type SwapDeal = { @@ -20,12 +20,14 @@ type SwapDeal = { * life cycle and if the deal is active, errored or completed. */ state: SwapDealState; - /** The reason for being in current state */ + /** The reason for being in the current state. */ stateReason: string; /** The xud node pub key of the counterparty to this swap deal. */ peerPubKey: string; - /** Global order id in the XU network. */ + /** The global order id in the XU network for the order being executed. */ orderId: string; + /** The local id for the order being executed. */ + localOrderId: string; /** The quantity of the order to execute as proposed by the taker. Negative when the taker is selling. */ // TODO: is it needed here? if yes, should be in satoshis proposedQuantity: number; @@ -61,11 +63,11 @@ interface Swaps { // TODO: put swap.rejected and swap.accepted to work or delete them. on(event: 'swap.rejected', listener: (deal: SwapDeal) => void): this; on(event: 'swap.accepted', listener: (deal: SwapDeal, quantity: number) => void): this; - on(event: 'swap.paid', listener: (deal: SwapDeal) => void): this; + on(event: 'swap.paid', listener: (deal: SwapResult, myRole: SwapDealRole) => void): this; on(event: 'swap.failed', listener: (deal: SwapDeal) => void): this; emit(event: 'swap.rejected', deal: SwapDeal): boolean; emit(event: 'swap.accepted', deal: SwapDeal, quantity: number): boolean; - emit(event: 'swap.paid', deal: SwapDeal): boolean; + emit(event: 'swap.paid', swapResult: SwapResult, myRole: SwapDealRole): boolean; emit(event: 'swap.failed', deal: SwapDeal): boolean; } @@ -238,6 +240,7 @@ class Swaps extends EventEmitter { const deal: SwapDeal = { ...swapRequestBody, peerPubKey: peer.nodePubKey!, + localOrderId: taker.localId, phase: SwapDealPhase.SwapCreated, state: SwapDealState.Active, stateReason: '', @@ -286,6 +289,7 @@ class Swaps extends EventEmitter { const deal: SwapDeal = { ...requestBody, peerPubKey: peer.nodePubKey!, + localOrderId: '', // TODO: get local id from order book quantity: requestBody.proposedQuantity, phase: SwapDealPhase.SwapCreated, state: SwapDealState.Active, @@ -629,7 +633,16 @@ class Swaps extends EventEmitter { deal.phase = newPhase; if (deal.phase === SwapDealPhase.AmountReceived) { - this.emit('swap.paid', deal); + const swapResult = { + orderId: deal.orderId, + localId: deal.localOrderId, + pairId: deal.pairId, + amountReceived: deal.makerAmount, + amountSent: deal.takerAmount, + r_hash: deal.r_hash, + peerPubKey: deal.peerPubKey, + }; + this.emit('swap.paid', swapResult, deal.myRole); } } diff --git a/lib/types/orders.ts b/lib/types/orders.ts index efdb8810d..1fb1090a3 100644 --- a/lib/types/orders.ts +++ b/lib/types/orders.ts @@ -48,7 +48,21 @@ export type OutgoingOrder = Pick { it('should add a new peerOrder and then remove it partially', () => { const quantity = 5; - const quantityToDecrease = 3; + const quantityToRemove = 3; const order = createPeerOrder(5, quantity, false); engine.addPeerOrder(order); - let removedOrder = engine.removePeerOrderQuantity(order.id, quantityToDecrease) as orders.StampedPeerOrder; - expect(removedOrder.quantity).to.be.equal(quantityToDecrease); + let removedOrder = engine.removePeerOrderQuantity(order.id, quantityToRemove) as orders.StampedPeerOrder; + expect(removedOrder.quantity).to.be.equal(quantityToRemove); removedOrder = engine.removePeerOrderQuantity(order.id) as orders.StampedPeerOrder; - expect(removedOrder.quantity).to.be.equal(quantity - quantityToDecrease); + expect(removedOrder.quantity).to.be.equal(quantity - quantityToRemove); }); });