Skip to content

Commit

Permalink
feat: query swapinfo by more columns
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Oct 8, 2023
1 parent aac0c92 commit 16fa4a9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
49 changes: 30 additions & 19 deletions lib/notifications/CommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import { coinsToSatoshis, satoshisToCoins } from '../DenominationConverter';
import ReverseSwapRepository from '../db/repositories/ReverseSwapRepository';
import ChannelCreationRepository from '../db/repositories/ChannelCreationRepository';
import {
stringify,
splitPairId,
formatError,
getChainCurrency,
getHexString,
splitPairId,
stringify,
getChainCurrency,
} from '../Utils';

enum Command {
Expand Down Expand Up @@ -262,33 +262,44 @@ class CommandHandler {
return;
}

const id = args[0];
const identifier = args[0];

const swap = await SwapRepository.getSwap({
id,
const swaps = await SwapRepository.getSwaps({
[Op.or]: {
id: identifier,
invoice: identifier,
preimageHash: identifier,
lockupAddress: identifier,
lockupTransactionId: identifier,
},
});

if (swap) {
for (const swap of swaps) {
const channelCreation =
await ChannelCreationRepository.getChannelCreation({
swapId: id,
swapId: swap.id,
});

await this.sendSwapInfo(swap, false, channelCreation);
return;
} else {
// Query for a reverse swap because there was no normal one found with the specified id
const reverseSwap = await ReverseSwapRepository.getReverseSwap({
id,
});
}

if (reverseSwap) {
await this.sendSwapInfo(reverseSwap, true);
return;
}
const reverseSwaps = await ReverseSwapRepository.getReverseSwaps({
[Op.or]: {
id: identifier,
invoice: identifier,
preimageHash: identifier,
lockupAddress: identifier,
transactionId: identifier,
},
});

for (const reverseSwap of reverseSwaps) {
await this.sendSwapInfo(reverseSwap, true);
}

await this.sendCouldNotFindSwap(id);
if (swaps.length === 0 && reverseSwaps.length === 0) {
await this.sendCouldNotFindSwap(identifier);
}
};

private getStats = async () => {
Expand Down
2 changes: 1 addition & 1 deletion lib/notifications/DiscordClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class DiscordClient extends EventEmitter {
public destroy = (): void => {
this.channel = undefined;
if (this.client.isReady()) {
this.client.destroy();
this.client.destroy().then();
}
};

Expand Down
2 changes: 1 addition & 1 deletion lib/notifications/Markup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// TODO: add all other used emojis to this object
export const Emojis = {
Zap: ':zap:',
Checkmark: ':white_check_mark:',
RotatingLight: ':rotating_light:',
};
Expand Down
5 changes: 3 additions & 2 deletions lib/notifications/NotificationProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Logger from '../Logger';
import { Emojis } from './Markup';
import Swap from '../db/models/Swap';
import Service from '../service/Service';
import DiscordClient from './DiscordClient';
Expand Down Expand Up @@ -174,8 +175,8 @@ class NotificationProvider {
orderSide,
);

return `${receiving}${isReverse ? ' :zap:' : ''} -> ${sending}${
!isReverse ? ' :zap:' : ''
return `${receiving}${isReverse ? ` ${Emojis.Zap}` : ''} -> ${sending}${
!isReverse ? ` ${Emojis.Zap}` : ''
}`;
};

Expand Down
4 changes: 2 additions & 2 deletions test/unit/notifications/CommandHandler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { wait } from '../../Utils';
import Logger from '../../../lib/Logger';
import { getHexBuffer, getHexString, stringify } from '../../../lib/Utils';
import Database from '../../../lib/db/Database';
import Service from '../../../lib/service/Service';
import { NotificationConfig } from '../../../lib/Config';
import { Balances, GetBalanceResponse } from '../../../lib/proto/boltzrpc_pb';
import ReferralStats from '../../../lib/data/ReferralStats';
import BackupScheduler from '../../../lib/backup/BackupScheduler';
import DiscordClient from '../../../lib/notifications/DiscordClient';
import CommandHandler from '../../../lib/notifications/CommandHandler';
import PairRepository from '../../../lib/db/repositories/PairRepository';
import SwapRepository from '../../../lib/db/repositories/SwapRepository';
import { getHexBuffer, getHexString, stringify } from '../../../lib/Utils';
import { Balances, GetBalanceResponse } from '../../../lib/proto/boltzrpc_pb';
import ReverseSwapRepository from '../../../lib/db/repositories/ReverseSwapRepository';
import ChannelCreationRepository from '../../../lib/db/repositories/ChannelCreationRepository';
import {
Expand Down

0 comments on commit 16fa4a9

Please sign in to comment.