Skip to content

Commit

Permalink
Merge pull request #696 from ExchangeUnion/swap-currency
Browse files Browse the repository at this point in the history
feat(rpc): add currencies to swap result
  • Loading branch information
sangaman authored Nov 30, 2018
2 parents 4445e62 + 86dfed4 commit 1b88899
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/api.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const createSwapResult = (result: SwapResult) => {
swapResult.setRHash(result.rHash);
swapResult.setAmountReceived(result.amountReceived);
swapResult.setAmountSent(result.amountSent);
swapResult.setCurrencyReceived(result.currencyReceived);
swapResult.setCurrencySent(result.currencySent);
swapResult.setPeerPubKey(result.peerPubKey);
swapResult.setRole(result.role as number);
return swapResult;
Expand Down
8 changes: 8 additions & 0 deletions lib/proto/xudrpc.swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions lib/proto/xudrpc_pb.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 55 additions & 1 deletion lib/proto/xudrpc_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions lib/swaps/Swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,16 @@ class Swaps extends EventEmitter {
deal.phase = newPhase;

if (deal.phase === SwapPhase.AmountReceived) {
const wasMaker = deal.role === SwapRole.Maker;
const swapResult = {
orderId: deal.orderId,
localId: deal.localId,
pairId: deal.pairId,
quantity: deal.quantity!,
amountReceived: deal.role === SwapRole.Maker ? deal.makerAmount : deal.takerAmount,
amountSent: deal.role === SwapRole.Maker ? deal.takerAmount : deal.makerAmount,
amountReceived: wasMaker ? deal.makerAmount : deal.takerAmount,
amountSent: wasMaker ? deal.takerAmount : deal.makerAmount,
currencyReceived: wasMaker ? deal.makerCurrency : deal.takerCurrency,
currencySent: wasMaker ? deal.takerCurrency : deal.makerCurrency,
rHash: deal.rHash,
peerPubKey: deal.peerPubKey,
role: deal.role,
Expand Down
4 changes: 4 additions & 0 deletions lib/swaps/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export type SwapResult = Pick<SwapDeal, 'orderId' | 'localId' | 'pairId' | 'rHas
amountReceived: number;
/** The amount of satoshis (or equivalent) sent. */
amountSent: number;
/** The ticker symbol of the currency received. */
currencyReceived: string;
/** The ticker symbol of the currency sent. */
currencySent: string;
/** The quantity that was swapped. */
quantity: number;
};
4 changes: 4 additions & 0 deletions proto/xudrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,10 @@ message SwapResult {
}
// Our role in the swap, either MAKER or TAKER.
Role role = 9 [json_name = "role"];
// The ticker symbol of the currency received.
string currency_received = 10 [json_name = "currency_received"];
// The ticker symbol of the currency sent.
string currency_sent = 11 [json_name = "currency_sent"];
}

message UnbanRequest {
Expand Down
3 changes: 3 additions & 0 deletions test/integration/Swap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import LndClient from '../../lib/lndclient/LndClient';
import Logger, { Level } from '../../lib/Logger';
import DB from '../../lib/db/DB';
import { waitForSpy } from '../utils';
import { SwapResult } from '../../lib/swaps/types';

chai.use(chaiAsPromised);

Expand Down Expand Up @@ -46,6 +47,8 @@ const validSwapResult = () => {
quantity: 0.00001,
amountReceived: 1000,
amountSent: 8,
currencyReceived: 'LTC',
currencySent: 'BTC',
rHash: 'd94c22a73d2741ed5cdcf3714f9ab3c8664793b03a54c74a08877726007d67c2',
peerPubKey: '020c9a0fb8dac5b91756fb21509aefc4e95b585510c4de6e6311f18348a4723cdd',
role: 0,
Expand Down

0 comments on commit 1b88899

Please sign in to comment.