Skip to content

Commit

Permalink
feat(grpc): add preimage to invoice settled events (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Jan 14, 2019
1 parent c5466e6 commit 3abca51
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 15 deletions.
3 changes: 2 additions & 1 deletion lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,12 @@ class GrpcService {
call.write(response);
});

this.service.on('invoice.settled', (invoice: string) => {
this.service.on('invoice.settled', (invoice: string, preimage: string) => {
const response = new boltzrpc.SubscribeInvoicesResponse();

response.setEvent(boltzrpc.InvoiceEvent.SETTLED);
response.setInvoice(invoice);
response.setPreimage(preimage);

call.write(response);
});
Expand Down
8 changes: 4 additions & 4 deletions lib/lightning/LndClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import grpc, { ClientReadableStream } from 'grpc';
import Errors from './Errors';
import Logger from '../Logger';
import BaseClient from '../BaseClient';
import LightningClient from './LightningClient';
import * as lndrpc from '../proto/lndrpc_pb';
import { ClientStatus } from '../consts/Enums';
import LightningClient from './LightningClient';
import { LightningClient as GrpcClient } from '../proto/lndrpc_grpc_pb';

// TODO: error handling
Expand Down Expand Up @@ -43,8 +43,8 @@ interface LndClient {
on(event: 'invoice.paid', listener: (invoice: string) => void): this;
emit(event: 'invoice.paid', invoice: string): boolean;

on(event: 'invoice.settled', listener: (invoice: string) => void): this;
emit(event: 'invoice.settled', string: string): boolean;
on(event: 'invoice.settled', listener: (invoice: string, preimage: string) => void): this;
emit(event: 'invoice.settled', string: string, preimage: string): boolean;
}

interface LightningMethodIndex extends GrpcClient {
Expand Down Expand Up @@ -313,7 +313,7 @@ class LndClient extends BaseClient implements LightningClient {
const paymentReq = invoice.getPaymentRequest();

this.logger.silly(`${this.symbol} LND invoice settled: ${paymentReq}`);
this.emit('invoice.settled', paymentReq);
this.emit('invoice.settled', paymentReq, invoice.getRPreimage_asB64());
}
})
.on('error', (error) => {
Expand Down
4 changes: 4 additions & 0 deletions lib/proto/boltzrpc_pb.d.ts

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

29 changes: 28 additions & 1 deletion lib/proto/boltzrpc_pb.js

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

18 changes: 9 additions & 9 deletions lib/service/Service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { EventEmitter } from 'events';
import { Transaction, address } from 'bitcoinjs-lib';
import Errors from './Errors';
import Logger from '../Logger';
import { Info as ChainInfo } from '../chain/ChainClientInterface';
import { Info as LndInfo } from '../lightning/LndClient';
import SwapManager from '../swap/SwapManager';
import WalletManager, { Currency } from '../wallet/WalletManager';
import { OrderSide } from '../proto/boltzrpc_pb';
import { WalletBalance } from '../wallet/Wallet';
import Errors from './Errors';
import { Info as LndInfo } from '../lightning/LndClient';
import { Info as ChainInfo } from '../chain/ChainClientInterface';
import WalletManager, { Currency } from '../wallet/WalletManager';
import { getHexBuffer, getOutputType, getHexString } from '../Utils';
import { OrderSide } from '../proto/boltzrpc_pb';

const packageJson = require('../../package.json');

Expand Down Expand Up @@ -37,8 +37,8 @@ interface Service {
on(even: 'invoice.paid', listener: (invoice: string) => void): this;
emit(event: 'invoice.paid', invoice: string): boolean;

on(event: 'invoice.settled', listener: (invoice: string) => void): this;
emit(event: 'invoice.settled', string: string): boolean;
on(event: 'invoice.settled', listener: (invoice: string, preimage: string) => void): this;
emit(event: 'invoice.settled', string: string, preimage: string): boolean;
}

// TODO: "invalid argument" errors
Expand Down Expand Up @@ -208,8 +208,8 @@ class Service extends EventEmitter {
this.emit('invoice.paid', invoice);
});

currency.lndClient.on('invoice.settled', (invoice) => {
this.emit('invoice.settled', invoice);
currency.lndClient.on('invoice.settled', (invoice, preimage) => {
this.emit('invoice.settled', invoice, preimage);
});
});
}
Expand Down
1 change: 1 addition & 0 deletions proto/boltzrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ message SubscribeInvoicesRequest {}
message SubscribeInvoicesResponse {
InvoiceEvent event = 1;
string invoice = 2;
string preimage = 3;
}

message CreateSwapRequest {
Expand Down

0 comments on commit 3abca51

Please sign in to comment.