Skip to content

Commit

Permalink
feat: add event for not payable invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
michael1011 committed Mar 8, 2019
1 parent de7b64c commit 98bfa5c
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/chain/ChainClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ interface ChainClient {
}

class ChainClient extends BaseClient {
public zmqClient: ZmqClient;

private client: RpcClient;
private zmqClient: ZmqClient;

private static readonly decimals = 100000000;

Expand Down
8 changes: 8 additions & 0 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ class GrpcService {
call.write(response);
});

this.service.on('invoice.failedToPay', (invoice: string) => {
const response = new boltzrpc.SubscribeInvoicesResponse();
response.setEvent(boltzrpc.InvoiceEvent.FAILED_TO_PAY);
response.setInvoice(invoice);

call.write(response);
});

this.service.on('invoice.settled', (invoice: string, preimage: string) => {
const response = new boltzrpc.SubscribeInvoicesResponse();
response.setEvent(boltzrpc.InvoiceEvent.SETTLED);
Expand Down
2 changes: 1 addition & 1 deletion lib/proto/boltzrpc_grpc_pb.js

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

3 changes: 2 additions & 1 deletion lib/proto/boltzrpc_pb.d.ts

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

3 changes: 2 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.

7 changes: 7 additions & 0 deletions lib/service/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ interface Service {
on(even: 'invoice.paid', listener: (invoice: string) => void): this;
emit(event: 'invoice.paid', invoice: string): boolean;

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

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

Expand Down Expand Up @@ -401,6 +404,10 @@ class Service extends EventEmitter {
this.emit('invoice.settled', invoice, preimage);
});
});

this.serviceComponents.swapManager.nursery.on('invoice.failedToPay', (invoice) => {
this.emit('invoice.failedToPay', invoice);
});
}

/**
Expand Down
5 changes: 5 additions & 0 deletions lib/swap/SwapNursery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type SwapMaps = {
interface SwapNursery {
on(event: 'refund', listener: (lockupTransactionHash: string) => void): this;
emit(event: 'refund', lockupTransactionHash: string): boolean;

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

class SwapNursery extends EventEmitter {
Expand Down Expand Up @@ -94,6 +97,8 @@ class SwapNursery extends EventEmitter {

if (payInvoice.paymentError !== '') {
this.logger.warn(`Could not pay ${currency.symbol} invoice ${details.invoice}: ${payInvoice.paymentError}`);

this.emit('invoice.failedToPay', details.invoice);
return;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/wallet/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ class Wallet {

utxo.set('confirmed', true);
await utxo.save();
} else {
this.chainClient.zmqClient.utxos.add(transactionId);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions proto/boltzrpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ service Boltz {
/* Subscribes to a stream of confirmed transactions to addresses that were specified with "ListenOnAddress" */
rpc SubscribeTransactions (SubscribeTransactionsRequest) returns (stream SubscribeTransactionsResponse);

/* Subscribes to a stream of settled invoices and those paid by Boltz */
/* Subscribes to a stream of invoice events */
rpc SubscribeInvoices (SubscribeInvoicesRequest) returns (stream SubscribeInvoicesResponse);

/* Subscribes to a stream of lockup transactions that Boltz refunds */
Expand Down Expand Up @@ -56,7 +56,8 @@ enum OrderSide {

enum InvoiceEvent {
PAID = 0;
SETTLED = 1;
FAILED_TO_PAY = 1;
SETTLED = 2;
}

message GetInfoRequest {}
Expand Down

0 comments on commit 98bfa5c

Please sign in to comment.