diff --git a/lib/grpc/GrpcServer.ts b/lib/grpc/GrpcServer.ts index 54ae3e30..cf866c84 100644 --- a/lib/grpc/GrpcServer.ts +++ b/lib/grpc/GrpcServer.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import assert from 'assert'; -import { pki, md } from 'node-forge'; import grpc, { Server } from 'grpc'; +import { pki, md } from 'node-forge'; import Errors from './Errors'; import Logger from '../Logger'; import GrpcService from './GrpcService'; @@ -28,10 +28,9 @@ class GrpcServer { getFeeEstimation: grpcService.getFeeEstimation, broadcastTransaction: grpcService.broadcastTransaction, listenOnAddress: grpcService.listenOnAddress, + subscribeSwapEvents: grpcService.subscribeSwapEvents, subscribeTransactions: grpcService.subscribeTransactions, subscribeInvoices: grpcService.subscribeInvoices, - subscribeClaims: grpcService.subscribeClaims, - subscribeRefunds: grpcService.subscribeRefunds, subscribeChannelBackups: grpcService.subscribeChannelBackups, createSwap: grpcService.createSwap, createReverseSwap: grpcService.createReverseSwap, diff --git a/lib/grpc/GrpcService.ts b/lib/grpc/GrpcService.ts index 664afc52..cdcdd03a 100644 --- a/lib/grpc/GrpcService.ts +++ b/lib/grpc/GrpcService.ts @@ -7,10 +7,9 @@ import Service from '../service/Service'; import * as boltzrpc from '../proto/boltzrpc_pb'; class GrpcService { + private swapEventSubscriptions: ServerWriteableStream[] = []; private transactionSubscriptions: ServerWriteableStream[] = []; private invoiceSubscriptions: ServerWriteableStream[] = []; - private claimSubscriptions: ServerWriteableStream[] = []; - private refundSubscriptions: ServerWriteableStream[] = []; private channelBackupSubscriptions: ServerWriteableStream[] = []; constructor(private service: Service) { @@ -90,6 +89,10 @@ class GrpcService { } } + public subscribeSwapEvents: handleServerStreamingCall = async (call) => { + this.registerSubscription(call, this.swapEventSubscriptions); + } + public subscribeTransactions: handleServerStreamingCall = async (call) => { this.registerSubscription(call, this.transactionSubscriptions); } @@ -98,14 +101,6 @@ class GrpcService { this.registerSubscription(call, this.invoiceSubscriptions); } - public subscribeClaims: handleServerStreamingCall = async (call) => { - this.registerSubscription(call, this.claimSubscriptions); - } - - public subscribeRefunds: handleServerStreamingCall = async (call) => { - this.registerSubscription(call, this.refundSubscriptions); - } - public subscribeChannelBackups: handleServerStreamingCall = async (call) => { this.registerSubscription(call, this.channelBackupSubscriptions); } @@ -213,25 +208,48 @@ class GrpcService { }); }); - // Claim subscription + // Swap event subscriptions this.service.on('claim', (lockupTransactionHash: string, lockupVout: number, minerFee: number) => { - this.claimSubscriptions.forEach((subscription) => { - const response = new boltzrpc.SubscribeClaimsResponse(); - response.setLockupTransactionHash(lockupTransactionHash); - response.setLockupVout(lockupVout); - response.setMinerFee(minerFee); + this.swapEventSubscriptions.forEach((subscription) => { + const response = new boltzrpc.SubscribeSwapEventsResponse(); + const claimDetails = new boltzrpc.ClaimDetails(); + + claimDetails.setLockupTransactionHash(lockupTransactionHash); + claimDetails.setLockupVout(lockupVout); + claimDetails.setMinerFee(minerFee); + + response.setEvent(boltzrpc.SwapEvent.CLAIM); + response.setClaimDetails(claimDetails); + + subscription.write(response); + }); + }); + + this.service.on('abort', (invoice: string) => { + this.swapEventSubscriptions.forEach((subscription) => { + const response = new boltzrpc.SubscribeSwapEventsResponse(); + const abortDetails = new boltzrpc.AbortDetails(); + + abortDetails.setInvoice(invoice); + + response.setEvent(boltzrpc.SwapEvent.ABORT); + response.setAbortDetails(abortDetails); subscription.write(response); }); }); - // Refund subscription this.service.on('refund', (lockupTransactionHash: string, lockupVout: number, minerFee: number) => { - this.refundSubscriptions.forEach((subscription) => { - const response = new boltzrpc.SubscribeRefundsResponse(); - response.setLockupTransactionHash(lockupTransactionHash); - response.setLockupVout(lockupVout); - response.setMinerFee(minerFee); + this.swapEventSubscriptions.forEach((subscription) => { + const response = new boltzrpc.SubscribeSwapEventsResponse(); + const refundDetails = new boltzrpc.RefundDetails(); + + refundDetails.setLockupTransactionHash(lockupTransactionHash); + refundDetails.setLockupVout(lockupVout); + refundDetails.setMinerFee(minerFee); + + response.setEvent(boltzrpc.SwapEvent.REFUND); + response.setRefundDetails(refundDetails); subscription.write(response); }); diff --git a/lib/proto/boltzrpc_grpc_pb.d.ts b/lib/proto/boltzrpc_grpc_pb.d.ts index 55b29bc1..226427be 100644 --- a/lib/proto/boltzrpc_grpc_pb.d.ts +++ b/lib/proto/boltzrpc_grpc_pb.d.ts @@ -17,10 +17,9 @@ interface IBoltzService extends grpc.ServiceDefinition; responseDeserialize: grpc.deserialize; } +interface IBoltzService_ISubscribeSwapEvents extends grpc.MethodDefinition { + path: string; // "/boltzrpc.Boltz/SubscribeSwapEvents" + requestStream: boolean; // false + responseStream: boolean; // true + requestSerialize: grpc.serialize; + requestDeserialize: grpc.deserialize; + responseSerialize: grpc.serialize; + responseDeserialize: grpc.deserialize; +} interface IBoltzService_ISubscribeTransactions extends grpc.MethodDefinition { path: string; // "/boltzrpc.Boltz/SubscribeTransactions" requestStream: boolean; // false @@ -132,24 +140,6 @@ interface IBoltzService_ISubscribeInvoices extends grpc.MethodDefinition; responseDeserialize: grpc.deserialize; } -interface IBoltzService_ISubscribeClaims extends grpc.MethodDefinition { - path: string; // "/boltzrpc.Boltz/SubscribeClaims" - requestStream: boolean; // false - responseStream: boolean; // true - requestSerialize: grpc.serialize; - requestDeserialize: grpc.deserialize; - responseSerialize: grpc.serialize; - responseDeserialize: grpc.deserialize; -} -interface IBoltzService_ISubscribeRefunds extends grpc.MethodDefinition { - path: string; // "/boltzrpc.Boltz/SubscribeRefunds" - requestStream: boolean; // false - responseStream: boolean; // true - requestSerialize: grpc.serialize; - requestDeserialize: grpc.deserialize; - responseSerialize: grpc.serialize; - responseDeserialize: grpc.deserialize; -} interface IBoltzService_ISubscribeChannelBackups extends grpc.MethodDefinition { path: string; // "/boltzrpc.Boltz/SubscribeChannelBackups" requestStream: boolean; // false @@ -173,10 +163,9 @@ export interface IBoltzServer { createSwap: grpc.handleUnaryCall; createReverseSwap: grpc.handleUnaryCall; listenOnAddress: grpc.handleUnaryCall; + subscribeSwapEvents: grpc.handleServerStreamingCall; subscribeTransactions: grpc.handleServerStreamingCall; subscribeInvoices: grpc.handleServerStreamingCall; - subscribeClaims: grpc.handleServerStreamingCall; - subscribeRefunds: grpc.handleServerStreamingCall; subscribeChannelBackups: grpc.handleServerStreamingCall; } @@ -211,14 +200,12 @@ export interface IBoltzClient { listenOnAddress(request: boltzrpc_pb.ListenOnAddressRequest, callback: (error: grpc.ServiceError | null, response: boltzrpc_pb.ListenOnAddressResponse) => void): grpc.ClientUnaryCall; listenOnAddress(request: boltzrpc_pb.ListenOnAddressRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: boltzrpc_pb.ListenOnAddressResponse) => void): grpc.ClientUnaryCall; listenOnAddress(request: boltzrpc_pb.ListenOnAddressRequest, metadata: grpc.Metadata, options: Partial, callback: (error: grpc.ServiceError | null, response: boltzrpc_pb.ListenOnAddressResponse) => void): grpc.ClientUnaryCall; + subscribeSwapEvents(request: boltzrpc_pb.SubscribeSwapEventsRequest, options?: Partial): grpc.ClientReadableStream; + subscribeSwapEvents(request: boltzrpc_pb.SubscribeSwapEventsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; subscribeTransactions(request: boltzrpc_pb.SubscribeTransactionsRequest, options?: Partial): grpc.ClientReadableStream; subscribeTransactions(request: boltzrpc_pb.SubscribeTransactionsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; subscribeInvoices(request: boltzrpc_pb.SubscribeInvoicesRequest, options?: Partial): grpc.ClientReadableStream; subscribeInvoices(request: boltzrpc_pb.SubscribeInvoicesRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; - subscribeClaims(request: boltzrpc_pb.SubscribeClaimsRequest, options?: Partial): grpc.ClientReadableStream; - subscribeClaims(request: boltzrpc_pb.SubscribeClaimsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; - subscribeRefunds(request: boltzrpc_pb.SubscribeRefundsRequest, options?: Partial): grpc.ClientReadableStream; - subscribeRefunds(request: boltzrpc_pb.SubscribeRefundsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; subscribeChannelBackups(request: boltzrpc_pb.SubscribeChannelBackupsRequest, options?: Partial): grpc.ClientReadableStream; subscribeChannelBackups(request: boltzrpc_pb.SubscribeChannelBackupsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; } @@ -255,14 +242,12 @@ export class BoltzClient extends grpc.Client implements IBoltzClient { public listenOnAddress(request: boltzrpc_pb.ListenOnAddressRequest, callback: (error: grpc.ServiceError | null, response: boltzrpc_pb.ListenOnAddressResponse) => void): grpc.ClientUnaryCall; public listenOnAddress(request: boltzrpc_pb.ListenOnAddressRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: boltzrpc_pb.ListenOnAddressResponse) => void): grpc.ClientUnaryCall; public listenOnAddress(request: boltzrpc_pb.ListenOnAddressRequest, metadata: grpc.Metadata, options: Partial, callback: (error: grpc.ServiceError | null, response: boltzrpc_pb.ListenOnAddressResponse) => void): grpc.ClientUnaryCall; + public subscribeSwapEvents(request: boltzrpc_pb.SubscribeSwapEventsRequest, options?: Partial): grpc.ClientReadableStream; + public subscribeSwapEvents(request: boltzrpc_pb.SubscribeSwapEventsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; public subscribeTransactions(request: boltzrpc_pb.SubscribeTransactionsRequest, options?: Partial): grpc.ClientReadableStream; public subscribeTransactions(request: boltzrpc_pb.SubscribeTransactionsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; public subscribeInvoices(request: boltzrpc_pb.SubscribeInvoicesRequest, options?: Partial): grpc.ClientReadableStream; public subscribeInvoices(request: boltzrpc_pb.SubscribeInvoicesRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; - public subscribeClaims(request: boltzrpc_pb.SubscribeClaimsRequest, options?: Partial): grpc.ClientReadableStream; - public subscribeClaims(request: boltzrpc_pb.SubscribeClaimsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; - public subscribeRefunds(request: boltzrpc_pb.SubscribeRefundsRequest, options?: Partial): grpc.ClientReadableStream; - public subscribeRefunds(request: boltzrpc_pb.SubscribeRefundsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; public subscribeChannelBackups(request: boltzrpc_pb.SubscribeChannelBackupsRequest, options?: Partial): grpc.ClientReadableStream; public subscribeChannelBackups(request: boltzrpc_pb.SubscribeChannelBackupsRequest, metadata?: grpc.Metadata, options?: Partial): grpc.ClientReadableStream; } diff --git a/lib/proto/boltzrpc_grpc_pb.js b/lib/proto/boltzrpc_grpc_pb.js index 3798f693..6dc7bdac 100644 --- a/lib/proto/boltzrpc_grpc_pb.js +++ b/lib/proto/boltzrpc_grpc_pb.js @@ -246,28 +246,6 @@ function deserialize_boltzrpc_SubscribeChannelBackupsRequest(buffer_arg) { return boltzrpc_pb.SubscribeChannelBackupsRequest.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_boltzrpc_SubscribeClaimsRequest(arg) { - if (!(arg instanceof boltzrpc_pb.SubscribeClaimsRequest)) { - throw new Error('Expected argument of type boltzrpc.SubscribeClaimsRequest'); - } - return Buffer.from(arg.serializeBinary()); -} - -function deserialize_boltzrpc_SubscribeClaimsRequest(buffer_arg) { - return boltzrpc_pb.SubscribeClaimsRequest.deserializeBinary(new Uint8Array(buffer_arg)); -} - -function serialize_boltzrpc_SubscribeClaimsResponse(arg) { - if (!(arg instanceof boltzrpc_pb.SubscribeClaimsResponse)) { - throw new Error('Expected argument of type boltzrpc.SubscribeClaimsResponse'); - } - return Buffer.from(arg.serializeBinary()); -} - -function deserialize_boltzrpc_SubscribeClaimsResponse(buffer_arg) { - return boltzrpc_pb.SubscribeClaimsResponse.deserializeBinary(new Uint8Array(buffer_arg)); -} - function serialize_boltzrpc_SubscribeInvoicesRequest(arg) { if (!(arg instanceof boltzrpc_pb.SubscribeInvoicesRequest)) { throw new Error('Expected argument of type boltzrpc.SubscribeInvoicesRequest'); @@ -290,26 +268,26 @@ function deserialize_boltzrpc_SubscribeInvoicesResponse(buffer_arg) { return boltzrpc_pb.SubscribeInvoicesResponse.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_boltzrpc_SubscribeRefundsRequest(arg) { - if (!(arg instanceof boltzrpc_pb.SubscribeRefundsRequest)) { - throw new Error('Expected argument of type boltzrpc.SubscribeRefundsRequest'); +function serialize_boltzrpc_SubscribeSwapEventsRequest(arg) { + if (!(arg instanceof boltzrpc_pb.SubscribeSwapEventsRequest)) { + throw new Error('Expected argument of type boltzrpc.SubscribeSwapEventsRequest'); } return Buffer.from(arg.serializeBinary()); } -function deserialize_boltzrpc_SubscribeRefundsRequest(buffer_arg) { - return boltzrpc_pb.SubscribeRefundsRequest.deserializeBinary(new Uint8Array(buffer_arg)); +function deserialize_boltzrpc_SubscribeSwapEventsRequest(buffer_arg) { + return boltzrpc_pb.SubscribeSwapEventsRequest.deserializeBinary(new Uint8Array(buffer_arg)); } -function serialize_boltzrpc_SubscribeRefundsResponse(arg) { - if (!(arg instanceof boltzrpc_pb.SubscribeRefundsResponse)) { - throw new Error('Expected argument of type boltzrpc.SubscribeRefundsResponse'); +function serialize_boltzrpc_SubscribeSwapEventsResponse(arg) { + if (!(arg instanceof boltzrpc_pb.SubscribeSwapEventsResponse)) { + throw new Error('Expected argument of type boltzrpc.SubscribeSwapEventsResponse'); } return Buffer.from(arg.serializeBinary()); } -function deserialize_boltzrpc_SubscribeRefundsResponse(buffer_arg) { - return boltzrpc_pb.SubscribeRefundsResponse.deserializeBinary(new Uint8Array(buffer_arg)); +function deserialize_boltzrpc_SubscribeSwapEventsResponse(buffer_arg) { + return boltzrpc_pb.SubscribeSwapEventsResponse.deserializeBinary(new Uint8Array(buffer_arg)); } function serialize_boltzrpc_SubscribeTransactionsRequest(arg) { @@ -456,6 +434,18 @@ var BoltzService = exports.BoltzService = { responseSerialize: serialize_boltzrpc_ListenOnAddressResponse, responseDeserialize: deserialize_boltzrpc_ListenOnAddressResponse, }, + // Subscribes to a stream of swap events + subscribeSwapEvents: { + path: '/boltzrpc.Boltz/SubscribeSwapEvents', + requestStream: false, + responseStream: true, + requestType: boltzrpc_pb.SubscribeSwapEventsRequest, + responseType: boltzrpc_pb.SubscribeSwapEventsResponse, + requestSerialize: serialize_boltzrpc_SubscribeSwapEventsRequest, + requestDeserialize: deserialize_boltzrpc_SubscribeSwapEventsRequest, + responseSerialize: serialize_boltzrpc_SubscribeSwapEventsResponse, + responseDeserialize: deserialize_boltzrpc_SubscribeSwapEventsResponse, + }, // Subscribes to a stream of confirmed transactions to addresses that were specified with "ListenOnAddress" subscribeTransactions: { path: '/boltzrpc.Boltz/SubscribeTransactions', @@ -480,30 +470,6 @@ var BoltzService = exports.BoltzService = { responseSerialize: serialize_boltzrpc_SubscribeInvoicesResponse, responseDeserialize: deserialize_boltzrpc_SubscribeInvoicesResponse, }, - // Subscribes to a stream of swap outputs that Boltz claims - subscribeClaims: { - path: '/boltzrpc.Boltz/SubscribeClaims', - requestStream: false, - responseStream: true, - requestType: boltzrpc_pb.SubscribeClaimsRequest, - responseType: boltzrpc_pb.SubscribeClaimsResponse, - requestSerialize: serialize_boltzrpc_SubscribeClaimsRequest, - requestDeserialize: deserialize_boltzrpc_SubscribeClaimsRequest, - responseSerialize: serialize_boltzrpc_SubscribeClaimsResponse, - responseDeserialize: deserialize_boltzrpc_SubscribeClaimsResponse, - }, - // Subscribes to a stream of lockup transactions that Boltz refunds - subscribeRefunds: { - path: '/boltzrpc.Boltz/SubscribeRefunds', - requestStream: false, - responseStream: true, - requestType: boltzrpc_pb.SubscribeRefundsRequest, - responseType: boltzrpc_pb.SubscribeRefundsResponse, - requestSerialize: serialize_boltzrpc_SubscribeRefundsRequest, - requestDeserialize: deserialize_boltzrpc_SubscribeRefundsRequest, - responseSerialize: serialize_boltzrpc_SubscribeRefundsResponse, - responseDeserialize: deserialize_boltzrpc_SubscribeRefundsResponse, - }, // Subscribes to a stream of channel backups subscribeChannelBackups: { path: '/boltzrpc.Boltz/SubscribeChannelBackups', diff --git a/lib/proto/boltzrpc_pb.d.ts b/lib/proto/boltzrpc_pb.d.ts index d5a83a3f..81db9d24 100644 --- a/lib/proto/boltzrpc_pb.d.ts +++ b/lib/proto/boltzrpc_pb.d.ts @@ -684,24 +684,80 @@ export namespace SubscribeInvoicesResponse { } -export class SubscribeClaimsRequest extends jspb.Message { +export class SubscribeSwapEventsRequest extends jspb.Message { serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): SubscribeClaimsRequest.AsObject; - static toObject(includeInstance: boolean, msg: SubscribeClaimsRequest): SubscribeClaimsRequest.AsObject; + toObject(includeInstance?: boolean): SubscribeSwapEventsRequest.AsObject; + static toObject(includeInstance: boolean, msg: SubscribeSwapEventsRequest): SubscribeSwapEventsRequest.AsObject; static extensions: {[key: number]: jspb.ExtensionFieldInfo}; static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: SubscribeClaimsRequest, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): SubscribeClaimsRequest; - static deserializeBinaryFromReader(message: SubscribeClaimsRequest, reader: jspb.BinaryReader): SubscribeClaimsRequest; + static serializeBinaryToWriter(message: SubscribeSwapEventsRequest, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): SubscribeSwapEventsRequest; + static deserializeBinaryFromReader(message: SubscribeSwapEventsRequest, reader: jspb.BinaryReader): SubscribeSwapEventsRequest; } -export namespace SubscribeClaimsRequest { +export namespace SubscribeSwapEventsRequest { export type AsObject = { } } -export class SubscribeClaimsResponse extends jspb.Message { +export class SubscribeSwapEventsResponse extends jspb.Message { + getEvent(): SwapEvent; + setEvent(value: SwapEvent): void; + + + hasClaimDetails(): boolean; + clearClaimDetails(): void; + getClaimDetails(): ClaimDetails | undefined; + setClaimDetails(value?: ClaimDetails): void; + + + hasAbortDetails(): boolean; + clearAbortDetails(): void; + getAbortDetails(): AbortDetails | undefined; + setAbortDetails(value?: AbortDetails): void; + + + hasRefundDetails(): boolean; + clearRefundDetails(): void; + getRefundDetails(): RefundDetails | undefined; + setRefundDetails(value?: RefundDetails): void; + + + getEventDetailsCase(): SubscribeSwapEventsResponse.EventDetailsCase; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): SubscribeSwapEventsResponse.AsObject; + static toObject(includeInstance: boolean, msg: SubscribeSwapEventsResponse): SubscribeSwapEventsResponse.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: SubscribeSwapEventsResponse, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): SubscribeSwapEventsResponse; + static deserializeBinaryFromReader(message: SubscribeSwapEventsResponse, reader: jspb.BinaryReader): SubscribeSwapEventsResponse; +} + +export namespace SubscribeSwapEventsResponse { + export type AsObject = { + event: SwapEvent, + claimDetails?: ClaimDetails.AsObject, + abortDetails?: AbortDetails.AsObject, + refundDetails?: RefundDetails.AsObject, + } + + export enum EventDetailsCase { + EVENTDETAILS_NOT_SET = 0, + + CLAIM_DETAILS = 2, + + ABORT_DETAILS = 3, + + REFUND_DETAILS = 4, + + } + +} + +export class ClaimDetails extends jspb.Message { getLockupTransactionHash(): string; setLockupTransactionHash(value: string): void; @@ -713,16 +769,16 @@ export class SubscribeClaimsResponse extends jspb.Message { serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): SubscribeClaimsResponse.AsObject; - static toObject(includeInstance: boolean, msg: SubscribeClaimsResponse): SubscribeClaimsResponse.AsObject; + toObject(includeInstance?: boolean): ClaimDetails.AsObject; + static toObject(includeInstance: boolean, msg: ClaimDetails): ClaimDetails.AsObject; static extensions: {[key: number]: jspb.ExtensionFieldInfo}; static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: SubscribeClaimsResponse, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): SubscribeClaimsResponse; - static deserializeBinaryFromReader(message: SubscribeClaimsResponse, reader: jspb.BinaryReader): SubscribeClaimsResponse; + static serializeBinaryToWriter(message: ClaimDetails, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): ClaimDetails; + static deserializeBinaryFromReader(message: ClaimDetails, reader: jspb.BinaryReader): ClaimDetails; } -export namespace SubscribeClaimsResponse { +export namespace ClaimDetails { export type AsObject = { lockupTransactionHash: string, lockupVout: number, @@ -730,24 +786,28 @@ export namespace SubscribeClaimsResponse { } } -export class SubscribeRefundsRequest extends jspb.Message { +export class AbortDetails extends jspb.Message { + getInvoice(): string; + setInvoice(value: string): void; + serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): SubscribeRefundsRequest.AsObject; - static toObject(includeInstance: boolean, msg: SubscribeRefundsRequest): SubscribeRefundsRequest.AsObject; + toObject(includeInstance?: boolean): AbortDetails.AsObject; + static toObject(includeInstance: boolean, msg: AbortDetails): AbortDetails.AsObject; static extensions: {[key: number]: jspb.ExtensionFieldInfo}; static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: SubscribeRefundsRequest, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): SubscribeRefundsRequest; - static deserializeBinaryFromReader(message: SubscribeRefundsRequest, reader: jspb.BinaryReader): SubscribeRefundsRequest; + static serializeBinaryToWriter(message: AbortDetails, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): AbortDetails; + static deserializeBinaryFromReader(message: AbortDetails, reader: jspb.BinaryReader): AbortDetails; } -export namespace SubscribeRefundsRequest { +export namespace AbortDetails { export type AsObject = { + invoice: string, } } -export class SubscribeRefundsResponse extends jspb.Message { +export class RefundDetails extends jspb.Message { getLockupTransactionHash(): string; setLockupTransactionHash(value: string): void; @@ -759,16 +819,16 @@ export class SubscribeRefundsResponse extends jspb.Message { serializeBinary(): Uint8Array; - toObject(includeInstance?: boolean): SubscribeRefundsResponse.AsObject; - static toObject(includeInstance: boolean, msg: SubscribeRefundsResponse): SubscribeRefundsResponse.AsObject; + toObject(includeInstance?: boolean): RefundDetails.AsObject; + static toObject(includeInstance: boolean, msg: RefundDetails): RefundDetails.AsObject; static extensions: {[key: number]: jspb.ExtensionFieldInfo}; static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; - static serializeBinaryToWriter(message: SubscribeRefundsResponse, writer: jspb.BinaryWriter): void; - static deserializeBinary(bytes: Uint8Array): SubscribeRefundsResponse; - static deserializeBinaryFromReader(message: SubscribeRefundsResponse, reader: jspb.BinaryReader): SubscribeRefundsResponse; + static serializeBinaryToWriter(message: RefundDetails, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): RefundDetails; + static deserializeBinaryFromReader(message: RefundDetails, reader: jspb.BinaryReader): RefundDetails; } -export namespace SubscribeRefundsResponse { +export namespace RefundDetails { export type AsObject = { lockupTransactionHash: string, lockupVout: number, @@ -1076,3 +1136,9 @@ export enum InvoiceEvent { FAILED_TO_PAY = 1, SETTLED = 2, } + +export enum SwapEvent { + CLAIM = 0, + ABORT = 1, + REFUND = 2, +} diff --git a/lib/proto/boltzrpc_pb.js b/lib/proto/boltzrpc_pb.js index c80f2c80..1ad5e89b 100644 --- a/lib/proto/boltzrpc_pb.js +++ b/lib/proto/boltzrpc_pb.js @@ -11,12 +11,14 @@ var jspb = require('google-protobuf'); var goog = jspb; var global = Function('return this')(); +goog.exportSymbol('proto.boltzrpc.AbortDetails', null, global); goog.exportSymbol('proto.boltzrpc.Balance', null, global); goog.exportSymbol('proto.boltzrpc.BroadcastTransactionRequest', null, global); goog.exportSymbol('proto.boltzrpc.BroadcastTransactionResponse', null, global); goog.exportSymbol('proto.boltzrpc.ChainInfo', null, global); goog.exportSymbol('proto.boltzrpc.ChannelBackup', null, global); goog.exportSymbol('proto.boltzrpc.ChannelBalance', null, global); +goog.exportSymbol('proto.boltzrpc.ClaimDetails', null, global); goog.exportSymbol('proto.boltzrpc.CreateReverseSwapRequest', null, global); goog.exportSymbol('proto.boltzrpc.CreateReverseSwapResponse', null, global); goog.exportSymbol('proto.boltzrpc.CreateSwapRequest', null, global); @@ -40,17 +42,17 @@ goog.exportSymbol('proto.boltzrpc.NewAddressRequest', null, global); goog.exportSymbol('proto.boltzrpc.NewAddressResponse', null, global); goog.exportSymbol('proto.boltzrpc.OrderSide', null, global); goog.exportSymbol('proto.boltzrpc.OutputType', null, global); +goog.exportSymbol('proto.boltzrpc.RefundDetails', null, global); goog.exportSymbol('proto.boltzrpc.SendCoinsRequest', null, global); goog.exportSymbol('proto.boltzrpc.SendCoinsResponse', null, global); goog.exportSymbol('proto.boltzrpc.SubscribeChannelBackupsRequest', null, global); -goog.exportSymbol('proto.boltzrpc.SubscribeClaimsRequest', null, global); -goog.exportSymbol('proto.boltzrpc.SubscribeClaimsResponse', null, global); goog.exportSymbol('proto.boltzrpc.SubscribeInvoicesRequest', null, global); goog.exportSymbol('proto.boltzrpc.SubscribeInvoicesResponse', null, global); -goog.exportSymbol('proto.boltzrpc.SubscribeRefundsRequest', null, global); -goog.exportSymbol('proto.boltzrpc.SubscribeRefundsResponse', null, global); +goog.exportSymbol('proto.boltzrpc.SubscribeSwapEventsRequest', null, global); +goog.exportSymbol('proto.boltzrpc.SubscribeSwapEventsResponse', null, global); goog.exportSymbol('proto.boltzrpc.SubscribeTransactionsRequest', null, global); goog.exportSymbol('proto.boltzrpc.SubscribeTransactionsResponse', null, global); +goog.exportSymbol('proto.boltzrpc.SwapEvent', null, global); goog.exportSymbol('proto.boltzrpc.WalletBalance', null, global); /** @@ -4532,12 +4534,12 @@ proto.boltzrpc.SubscribeInvoicesResponse.prototype.hasRoutingFee = function() { * @extends {jspb.Message} * @constructor */ -proto.boltzrpc.SubscribeClaimsRequest = function(opt_data) { +proto.boltzrpc.SubscribeSwapEventsRequest = function(opt_data) { jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; -goog.inherits(proto.boltzrpc.SubscribeClaimsRequest, jspb.Message); +goog.inherits(proto.boltzrpc.SubscribeSwapEventsRequest, jspb.Message); if (goog.DEBUG && !COMPILED) { - proto.boltzrpc.SubscribeClaimsRequest.displayName = 'proto.boltzrpc.SubscribeClaimsRequest'; + proto.boltzrpc.SubscribeSwapEventsRequest.displayName = 'proto.boltzrpc.SubscribeSwapEventsRequest'; } @@ -4552,8 +4554,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ -proto.boltzrpc.SubscribeClaimsRequest.prototype.toObject = function(opt_includeInstance) { - return proto.boltzrpc.SubscribeClaimsRequest.toObject(opt_includeInstance, this); +proto.boltzrpc.SubscribeSwapEventsRequest.prototype.toObject = function(opt_includeInstance) { + return proto.boltzrpc.SubscribeSwapEventsRequest.toObject(opt_includeInstance, this); }; @@ -4562,11 +4564,11 @@ proto.boltzrpc.SubscribeClaimsRequest.prototype.toObject = function(opt_includeI * @param {boolean|undefined} includeInstance Whether to include the JSPB * instance for transitional soy proto support: * http://goto/soy-param-migration - * @param {!proto.boltzrpc.SubscribeClaimsRequest} msg The msg instance to transform. + * @param {!proto.boltzrpc.SubscribeSwapEventsRequest} msg The msg instance to transform. * @return {!Object} * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.boltzrpc.SubscribeClaimsRequest.toObject = function(includeInstance, msg) { +proto.boltzrpc.SubscribeSwapEventsRequest.toObject = function(includeInstance, msg) { var f, obj = { }; @@ -4582,23 +4584,23 @@ proto.boltzrpc.SubscribeClaimsRequest.toObject = function(includeInstance, msg) /** * Deserializes binary data (in protobuf wire format). * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.boltzrpc.SubscribeClaimsRequest} + * @return {!proto.boltzrpc.SubscribeSwapEventsRequest} */ -proto.boltzrpc.SubscribeClaimsRequest.deserializeBinary = function(bytes) { +proto.boltzrpc.SubscribeSwapEventsRequest.deserializeBinary = function(bytes) { var reader = new jspb.BinaryReader(bytes); - var msg = new proto.boltzrpc.SubscribeClaimsRequest; - return proto.boltzrpc.SubscribeClaimsRequest.deserializeBinaryFromReader(msg, reader); + var msg = new proto.boltzrpc.SubscribeSwapEventsRequest; + return proto.boltzrpc.SubscribeSwapEventsRequest.deserializeBinaryFromReader(msg, reader); }; /** * Deserializes binary data (in protobuf wire format) from the * given reader into the given message object. - * @param {!proto.boltzrpc.SubscribeClaimsRequest} msg The message object to deserialize into. + * @param {!proto.boltzrpc.SubscribeSwapEventsRequest} msg The message object to deserialize into. * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.boltzrpc.SubscribeClaimsRequest} + * @return {!proto.boltzrpc.SubscribeSwapEventsRequest} */ -proto.boltzrpc.SubscribeClaimsRequest.deserializeBinaryFromReader = function(msg, reader) { +proto.boltzrpc.SubscribeSwapEventsRequest.deserializeBinaryFromReader = function(msg, reader) { while (reader.nextField()) { if (reader.isEndGroup()) { break; @@ -4618,9 +4620,9 @@ proto.boltzrpc.SubscribeClaimsRequest.deserializeBinaryFromReader = function(msg * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.boltzrpc.SubscribeClaimsRequest.prototype.serializeBinary = function() { +proto.boltzrpc.SubscribeSwapEventsRequest.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - proto.boltzrpc.SubscribeClaimsRequest.serializeBinaryToWriter(this, writer); + proto.boltzrpc.SubscribeSwapEventsRequest.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; @@ -4628,11 +4630,11 @@ proto.boltzrpc.SubscribeClaimsRequest.prototype.serializeBinary = function() { /** * Serializes the given message to binary data (in protobuf wire * format), writing to the given BinaryWriter. - * @param {!proto.boltzrpc.SubscribeClaimsRequest} message + * @param {!proto.boltzrpc.SubscribeSwapEventsRequest} message * @param {!jspb.BinaryWriter} writer * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.boltzrpc.SubscribeClaimsRequest.serializeBinaryToWriter = function(message, writer) { +proto.boltzrpc.SubscribeSwapEventsRequest.serializeBinaryToWriter = function(message, writer) { var f = undefined; }; @@ -4648,12 +4650,313 @@ proto.boltzrpc.SubscribeClaimsRequest.serializeBinaryToWriter = function(message * @extends {jspb.Message} * @constructor */ -proto.boltzrpc.SubscribeClaimsResponse = function(opt_data) { +proto.boltzrpc.SubscribeSwapEventsResponse = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, proto.boltzrpc.SubscribeSwapEventsResponse.oneofGroups_); +}; +goog.inherits(proto.boltzrpc.SubscribeSwapEventsResponse, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.boltzrpc.SubscribeSwapEventsResponse.displayName = 'proto.boltzrpc.SubscribeSwapEventsResponse'; +} +/** + * 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.boltzrpc.SubscribeSwapEventsResponse.oneofGroups_ = [[2,3,4]]; + +/** + * @enum {number} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.EventDetailsCase = { + EVENT_DETAILS_NOT_SET: 0, + CLAIM_DETAILS: 2, + ABORT_DETAILS: 3, + REFUND_DETAILS: 4 +}; + +/** + * @return {proto.boltzrpc.SubscribeSwapEventsResponse.EventDetailsCase} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.getEventDetailsCase = function() { + return /** @type {proto.boltzrpc.SubscribeSwapEventsResponse.EventDetailsCase} */(jspb.Message.computeOneofCase(this, proto.boltzrpc.SubscribeSwapEventsResponse.oneofGroups_[0])); +}; + + + +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.boltzrpc.SubscribeSwapEventsResponse.prototype.toObject = function(opt_includeInstance) { + return proto.boltzrpc.SubscribeSwapEventsResponse.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.boltzrpc.SubscribeSwapEventsResponse} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.boltzrpc.SubscribeSwapEventsResponse.toObject = function(includeInstance, msg) { + var f, obj = { + event: jspb.Message.getFieldWithDefault(msg, 1, 0), + claimDetails: (f = msg.getClaimDetails()) && proto.boltzrpc.ClaimDetails.toObject(includeInstance, f), + abortDetails: (f = msg.getAbortDetails()) && proto.boltzrpc.AbortDetails.toObject(includeInstance, f), + refundDetails: (f = msg.getRefundDetails()) && proto.boltzrpc.RefundDetails.toObject(includeInstance, f) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.boltzrpc.SubscribeSwapEventsResponse} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.boltzrpc.SubscribeSwapEventsResponse; + return proto.boltzrpc.SubscribeSwapEventsResponse.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.boltzrpc.SubscribeSwapEventsResponse} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.boltzrpc.SubscribeSwapEventsResponse} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {!proto.boltzrpc.SwapEvent} */ (reader.readEnum()); + msg.setEvent(value); + break; + case 2: + var value = new proto.boltzrpc.ClaimDetails; + reader.readMessage(value,proto.boltzrpc.ClaimDetails.deserializeBinaryFromReader); + msg.setClaimDetails(value); + break; + case 3: + var value = new proto.boltzrpc.AbortDetails; + reader.readMessage(value,proto.boltzrpc.AbortDetails.deserializeBinaryFromReader); + msg.setAbortDetails(value); + break; + case 4: + var value = new proto.boltzrpc.RefundDetails; + reader.readMessage(value,proto.boltzrpc.RefundDetails.deserializeBinaryFromReader); + msg.setRefundDetails(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.boltzrpc.SubscribeSwapEventsResponse.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.boltzrpc.SubscribeSwapEventsResponse} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.boltzrpc.SubscribeSwapEventsResponse.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getEvent(); + if (f !== 0.0) { + writer.writeEnum( + 1, + f + ); + } + f = message.getClaimDetails(); + if (f != null) { + writer.writeMessage( + 2, + f, + proto.boltzrpc.ClaimDetails.serializeBinaryToWriter + ); + } + f = message.getAbortDetails(); + if (f != null) { + writer.writeMessage( + 3, + f, + proto.boltzrpc.AbortDetails.serializeBinaryToWriter + ); + } + f = message.getRefundDetails(); + if (f != null) { + writer.writeMessage( + 4, + f, + proto.boltzrpc.RefundDetails.serializeBinaryToWriter + ); + } +}; + + +/** + * optional SwapEvent event = 1; + * @return {!proto.boltzrpc.SwapEvent} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.getEvent = function() { + return /** @type {!proto.boltzrpc.SwapEvent} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); +}; + + +/** @param {!proto.boltzrpc.SwapEvent} value */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.setEvent = function(value) { + jspb.Message.setProto3EnumField(this, 1, value); +}; + + +/** + * optional ClaimDetails claim_details = 2; + * @return {?proto.boltzrpc.ClaimDetails} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.getClaimDetails = function() { + return /** @type{?proto.boltzrpc.ClaimDetails} */ ( + jspb.Message.getWrapperField(this, proto.boltzrpc.ClaimDetails, 2)); +}; + + +/** @param {?proto.boltzrpc.ClaimDetails|undefined} value */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.setClaimDetails = function(value) { + jspb.Message.setOneofWrapperField(this, 2, proto.boltzrpc.SubscribeSwapEventsResponse.oneofGroups_[0], value); +}; + + +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.clearClaimDetails = function() { + this.setClaimDetails(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.hasClaimDetails = function() { + return jspb.Message.getField(this, 2) != null; +}; + + +/** + * optional AbortDetails abort_details = 3; + * @return {?proto.boltzrpc.AbortDetails} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.getAbortDetails = function() { + return /** @type{?proto.boltzrpc.AbortDetails} */ ( + jspb.Message.getWrapperField(this, proto.boltzrpc.AbortDetails, 3)); +}; + + +/** @param {?proto.boltzrpc.AbortDetails|undefined} value */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.setAbortDetails = function(value) { + jspb.Message.setOneofWrapperField(this, 3, proto.boltzrpc.SubscribeSwapEventsResponse.oneofGroups_[0], value); +}; + + +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.clearAbortDetails = function() { + this.setAbortDetails(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.hasAbortDetails = function() { + return jspb.Message.getField(this, 3) != null; +}; + + +/** + * optional RefundDetails refund_details = 4; + * @return {?proto.boltzrpc.RefundDetails} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.getRefundDetails = function() { + return /** @type{?proto.boltzrpc.RefundDetails} */ ( + jspb.Message.getWrapperField(this, proto.boltzrpc.RefundDetails, 4)); +}; + + +/** @param {?proto.boltzrpc.RefundDetails|undefined} value */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.setRefundDetails = function(value) { + jspb.Message.setOneofWrapperField(this, 4, proto.boltzrpc.SubscribeSwapEventsResponse.oneofGroups_[0], value); +}; + + +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.clearRefundDetails = function() { + this.setRefundDetails(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.boltzrpc.SubscribeSwapEventsResponse.prototype.hasRefundDetails = function() { + return jspb.Message.getField(this, 4) != null; +}; + + + +/** + * 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.boltzrpc.ClaimDetails = function(opt_data) { jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; -goog.inherits(proto.boltzrpc.SubscribeClaimsResponse, jspb.Message); +goog.inherits(proto.boltzrpc.ClaimDetails, jspb.Message); if (goog.DEBUG && !COMPILED) { - proto.boltzrpc.SubscribeClaimsResponse.displayName = 'proto.boltzrpc.SubscribeClaimsResponse'; + proto.boltzrpc.ClaimDetails.displayName = 'proto.boltzrpc.ClaimDetails'; } @@ -4668,8 +4971,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ -proto.boltzrpc.SubscribeClaimsResponse.prototype.toObject = function(opt_includeInstance) { - return proto.boltzrpc.SubscribeClaimsResponse.toObject(opt_includeInstance, this); +proto.boltzrpc.ClaimDetails.prototype.toObject = function(opt_includeInstance) { + return proto.boltzrpc.ClaimDetails.toObject(opt_includeInstance, this); }; @@ -4678,11 +4981,11 @@ proto.boltzrpc.SubscribeClaimsResponse.prototype.toObject = function(opt_include * @param {boolean|undefined} includeInstance Whether to include the JSPB * instance for transitional soy proto support: * http://goto/soy-param-migration - * @param {!proto.boltzrpc.SubscribeClaimsResponse} msg The msg instance to transform. + * @param {!proto.boltzrpc.ClaimDetails} msg The msg instance to transform. * @return {!Object} * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.boltzrpc.SubscribeClaimsResponse.toObject = function(includeInstance, msg) { +proto.boltzrpc.ClaimDetails.toObject = function(includeInstance, msg) { var f, obj = { lockupTransactionHash: jspb.Message.getFieldWithDefault(msg, 1, ""), lockupVout: jspb.Message.getFieldWithDefault(msg, 2, 0), @@ -4700,23 +5003,23 @@ proto.boltzrpc.SubscribeClaimsResponse.toObject = function(includeInstance, msg) /** * Deserializes binary data (in protobuf wire format). * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.boltzrpc.SubscribeClaimsResponse} + * @return {!proto.boltzrpc.ClaimDetails} */ -proto.boltzrpc.SubscribeClaimsResponse.deserializeBinary = function(bytes) { +proto.boltzrpc.ClaimDetails.deserializeBinary = function(bytes) { var reader = new jspb.BinaryReader(bytes); - var msg = new proto.boltzrpc.SubscribeClaimsResponse; - return proto.boltzrpc.SubscribeClaimsResponse.deserializeBinaryFromReader(msg, reader); + var msg = new proto.boltzrpc.ClaimDetails; + return proto.boltzrpc.ClaimDetails.deserializeBinaryFromReader(msg, reader); }; /** * Deserializes binary data (in protobuf wire format) from the * given reader into the given message object. - * @param {!proto.boltzrpc.SubscribeClaimsResponse} msg The message object to deserialize into. + * @param {!proto.boltzrpc.ClaimDetails} msg The message object to deserialize into. * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.boltzrpc.SubscribeClaimsResponse} + * @return {!proto.boltzrpc.ClaimDetails} */ -proto.boltzrpc.SubscribeClaimsResponse.deserializeBinaryFromReader = function(msg, reader) { +proto.boltzrpc.ClaimDetails.deserializeBinaryFromReader = function(msg, reader) { while (reader.nextField()) { if (reader.isEndGroup()) { break; @@ -4748,9 +5051,9 @@ proto.boltzrpc.SubscribeClaimsResponse.deserializeBinaryFromReader = function(ms * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.boltzrpc.SubscribeClaimsResponse.prototype.serializeBinary = function() { +proto.boltzrpc.ClaimDetails.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - proto.boltzrpc.SubscribeClaimsResponse.serializeBinaryToWriter(this, writer); + proto.boltzrpc.ClaimDetails.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; @@ -4758,11 +5061,11 @@ proto.boltzrpc.SubscribeClaimsResponse.prototype.serializeBinary = function() { /** * Serializes the given message to binary data (in protobuf wire * format), writing to the given BinaryWriter. - * @param {!proto.boltzrpc.SubscribeClaimsResponse} message + * @param {!proto.boltzrpc.ClaimDetails} message * @param {!jspb.BinaryWriter} writer * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.boltzrpc.SubscribeClaimsResponse.serializeBinaryToWriter = function(message, writer) { +proto.boltzrpc.ClaimDetails.serializeBinaryToWriter = function(message, writer) { var f = undefined; f = message.getLockupTransactionHash(); if (f.length > 0) { @@ -4792,13 +5095,13 @@ proto.boltzrpc.SubscribeClaimsResponse.serializeBinaryToWriter = function(messag * optional string lockup_transaction_hash = 1; * @return {string} */ -proto.boltzrpc.SubscribeClaimsResponse.prototype.getLockupTransactionHash = function() { +proto.boltzrpc.ClaimDetails.prototype.getLockupTransactionHash = function() { return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); }; /** @param {string} value */ -proto.boltzrpc.SubscribeClaimsResponse.prototype.setLockupTransactionHash = function(value) { +proto.boltzrpc.ClaimDetails.prototype.setLockupTransactionHash = function(value) { jspb.Message.setProto3StringField(this, 1, value); }; @@ -4807,13 +5110,13 @@ proto.boltzrpc.SubscribeClaimsResponse.prototype.setLockupTransactionHash = func * optional uint32 lockup_vout = 2; * @return {number} */ -proto.boltzrpc.SubscribeClaimsResponse.prototype.getLockupVout = function() { +proto.boltzrpc.ClaimDetails.prototype.getLockupVout = function() { return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); }; /** @param {number} value */ -proto.boltzrpc.SubscribeClaimsResponse.prototype.setLockupVout = function(value) { +proto.boltzrpc.ClaimDetails.prototype.setLockupVout = function(value) { jspb.Message.setProto3IntField(this, 2, value); }; @@ -4822,13 +5125,13 @@ proto.boltzrpc.SubscribeClaimsResponse.prototype.setLockupVout = function(value) * optional uint32 miner_fee = 3; * @return {number} */ -proto.boltzrpc.SubscribeClaimsResponse.prototype.getMinerFee = function() { +proto.boltzrpc.ClaimDetails.prototype.getMinerFee = function() { return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); }; /** @param {number} value */ -proto.boltzrpc.SubscribeClaimsResponse.prototype.setMinerFee = function(value) { +proto.boltzrpc.ClaimDetails.prototype.setMinerFee = function(value) { jspb.Message.setProto3IntField(this, 3, value); }; @@ -4844,12 +5147,12 @@ proto.boltzrpc.SubscribeClaimsResponse.prototype.setMinerFee = function(value) { * @extends {jspb.Message} * @constructor */ -proto.boltzrpc.SubscribeRefundsRequest = function(opt_data) { +proto.boltzrpc.AbortDetails = function(opt_data) { jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; -goog.inherits(proto.boltzrpc.SubscribeRefundsRequest, jspb.Message); +goog.inherits(proto.boltzrpc.AbortDetails, jspb.Message); if (goog.DEBUG && !COMPILED) { - proto.boltzrpc.SubscribeRefundsRequest.displayName = 'proto.boltzrpc.SubscribeRefundsRequest'; + proto.boltzrpc.AbortDetails.displayName = 'proto.boltzrpc.AbortDetails'; } @@ -4864,8 +5167,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ -proto.boltzrpc.SubscribeRefundsRequest.prototype.toObject = function(opt_includeInstance) { - return proto.boltzrpc.SubscribeRefundsRequest.toObject(opt_includeInstance, this); +proto.boltzrpc.AbortDetails.prototype.toObject = function(opt_includeInstance) { + return proto.boltzrpc.AbortDetails.toObject(opt_includeInstance, this); }; @@ -4874,13 +5177,13 @@ proto.boltzrpc.SubscribeRefundsRequest.prototype.toObject = function(opt_include * @param {boolean|undefined} includeInstance Whether to include the JSPB * instance for transitional soy proto support: * http://goto/soy-param-migration - * @param {!proto.boltzrpc.SubscribeRefundsRequest} msg The msg instance to transform. + * @param {!proto.boltzrpc.AbortDetails} msg The msg instance to transform. * @return {!Object} * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.boltzrpc.SubscribeRefundsRequest.toObject = function(includeInstance, msg) { +proto.boltzrpc.AbortDetails.toObject = function(includeInstance, msg) { var f, obj = { - + invoice: jspb.Message.getFieldWithDefault(msg, 1, "") }; if (includeInstance) { @@ -4894,29 +5197,33 @@ proto.boltzrpc.SubscribeRefundsRequest.toObject = function(includeInstance, msg) /** * Deserializes binary data (in protobuf wire format). * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.boltzrpc.SubscribeRefundsRequest} + * @return {!proto.boltzrpc.AbortDetails} */ -proto.boltzrpc.SubscribeRefundsRequest.deserializeBinary = function(bytes) { +proto.boltzrpc.AbortDetails.deserializeBinary = function(bytes) { var reader = new jspb.BinaryReader(bytes); - var msg = new proto.boltzrpc.SubscribeRefundsRequest; - return proto.boltzrpc.SubscribeRefundsRequest.deserializeBinaryFromReader(msg, reader); + var msg = new proto.boltzrpc.AbortDetails; + return proto.boltzrpc.AbortDetails.deserializeBinaryFromReader(msg, reader); }; /** * Deserializes binary data (in protobuf wire format) from the * given reader into the given message object. - * @param {!proto.boltzrpc.SubscribeRefundsRequest} msg The message object to deserialize into. + * @param {!proto.boltzrpc.AbortDetails} msg The message object to deserialize into. * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.boltzrpc.SubscribeRefundsRequest} + * @return {!proto.boltzrpc.AbortDetails} */ -proto.boltzrpc.SubscribeRefundsRequest.deserializeBinaryFromReader = function(msg, reader) { +proto.boltzrpc.AbortDetails.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.setInvoice(value); + break; default: reader.skipField(); break; @@ -4930,9 +5237,9 @@ proto.boltzrpc.SubscribeRefundsRequest.deserializeBinaryFromReader = function(ms * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.boltzrpc.SubscribeRefundsRequest.prototype.serializeBinary = function() { +proto.boltzrpc.AbortDetails.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - proto.boltzrpc.SubscribeRefundsRequest.serializeBinaryToWriter(this, writer); + proto.boltzrpc.AbortDetails.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; @@ -4940,12 +5247,34 @@ proto.boltzrpc.SubscribeRefundsRequest.prototype.serializeBinary = function() { /** * Serializes the given message to binary data (in protobuf wire * format), writing to the given BinaryWriter. - * @param {!proto.boltzrpc.SubscribeRefundsRequest} message + * @param {!proto.boltzrpc.AbortDetails} message * @param {!jspb.BinaryWriter} writer * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.boltzrpc.SubscribeRefundsRequest.serializeBinaryToWriter = function(message, writer) { +proto.boltzrpc.AbortDetails.serializeBinaryToWriter = function(message, writer) { var f = undefined; + f = message.getInvoice(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } +}; + + +/** + * optional string invoice = 1; + * @return {string} + */ +proto.boltzrpc.AbortDetails.prototype.getInvoice = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** @param {string} value */ +proto.boltzrpc.AbortDetails.prototype.setInvoice = function(value) { + jspb.Message.setProto3StringField(this, 1, value); }; @@ -4960,12 +5289,12 @@ proto.boltzrpc.SubscribeRefundsRequest.serializeBinaryToWriter = function(messag * @extends {jspb.Message} * @constructor */ -proto.boltzrpc.SubscribeRefundsResponse = function(opt_data) { +proto.boltzrpc.RefundDetails = function(opt_data) { jspb.Message.initialize(this, opt_data, 0, -1, null, null); }; -goog.inherits(proto.boltzrpc.SubscribeRefundsResponse, jspb.Message); +goog.inherits(proto.boltzrpc.RefundDetails, jspb.Message); if (goog.DEBUG && !COMPILED) { - proto.boltzrpc.SubscribeRefundsResponse.displayName = 'proto.boltzrpc.SubscribeRefundsResponse'; + proto.boltzrpc.RefundDetails.displayName = 'proto.boltzrpc.RefundDetails'; } @@ -4980,8 +5309,8 @@ if (jspb.Message.GENERATE_TO_OBJECT) { * for transitional soy proto support: http://goto/soy-param-migration * @return {!Object} */ -proto.boltzrpc.SubscribeRefundsResponse.prototype.toObject = function(opt_includeInstance) { - return proto.boltzrpc.SubscribeRefundsResponse.toObject(opt_includeInstance, this); +proto.boltzrpc.RefundDetails.prototype.toObject = function(opt_includeInstance) { + return proto.boltzrpc.RefundDetails.toObject(opt_includeInstance, this); }; @@ -4990,11 +5319,11 @@ proto.boltzrpc.SubscribeRefundsResponse.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.boltzrpc.SubscribeRefundsResponse} msg The msg instance to transform. + * @param {!proto.boltzrpc.RefundDetails} msg The msg instance to transform. * @return {!Object} * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.boltzrpc.SubscribeRefundsResponse.toObject = function(includeInstance, msg) { +proto.boltzrpc.RefundDetails.toObject = function(includeInstance, msg) { var f, obj = { lockupTransactionHash: jspb.Message.getFieldWithDefault(msg, 1, ""), lockupVout: jspb.Message.getFieldWithDefault(msg, 2, 0), @@ -5012,23 +5341,23 @@ proto.boltzrpc.SubscribeRefundsResponse.toObject = function(includeInstance, msg /** * Deserializes binary data (in protobuf wire format). * @param {jspb.ByteSource} bytes The bytes to deserialize. - * @return {!proto.boltzrpc.SubscribeRefundsResponse} + * @return {!proto.boltzrpc.RefundDetails} */ -proto.boltzrpc.SubscribeRefundsResponse.deserializeBinary = function(bytes) { +proto.boltzrpc.RefundDetails.deserializeBinary = function(bytes) { var reader = new jspb.BinaryReader(bytes); - var msg = new proto.boltzrpc.SubscribeRefundsResponse; - return proto.boltzrpc.SubscribeRefundsResponse.deserializeBinaryFromReader(msg, reader); + var msg = new proto.boltzrpc.RefundDetails; + return proto.boltzrpc.RefundDetails.deserializeBinaryFromReader(msg, reader); }; /** * Deserializes binary data (in protobuf wire format) from the * given reader into the given message object. - * @param {!proto.boltzrpc.SubscribeRefundsResponse} msg The message object to deserialize into. + * @param {!proto.boltzrpc.RefundDetails} msg The message object to deserialize into. * @param {!jspb.BinaryReader} reader The BinaryReader to use. - * @return {!proto.boltzrpc.SubscribeRefundsResponse} + * @return {!proto.boltzrpc.RefundDetails} */ -proto.boltzrpc.SubscribeRefundsResponse.deserializeBinaryFromReader = function(msg, reader) { +proto.boltzrpc.RefundDetails.deserializeBinaryFromReader = function(msg, reader) { while (reader.nextField()) { if (reader.isEndGroup()) { break; @@ -5060,9 +5389,9 @@ proto.boltzrpc.SubscribeRefundsResponse.deserializeBinaryFromReader = function(m * Serializes the message to binary data (in protobuf wire format). * @return {!Uint8Array} */ -proto.boltzrpc.SubscribeRefundsResponse.prototype.serializeBinary = function() { +proto.boltzrpc.RefundDetails.prototype.serializeBinary = function() { var writer = new jspb.BinaryWriter(); - proto.boltzrpc.SubscribeRefundsResponse.serializeBinaryToWriter(this, writer); + proto.boltzrpc.RefundDetails.serializeBinaryToWriter(this, writer); return writer.getResultBuffer(); }; @@ -5070,11 +5399,11 @@ proto.boltzrpc.SubscribeRefundsResponse.prototype.serializeBinary = function() { /** * Serializes the given message to binary data (in protobuf wire * format), writing to the given BinaryWriter. - * @param {!proto.boltzrpc.SubscribeRefundsResponse} message + * @param {!proto.boltzrpc.RefundDetails} message * @param {!jspb.BinaryWriter} writer * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.boltzrpc.SubscribeRefundsResponse.serializeBinaryToWriter = function(message, writer) { +proto.boltzrpc.RefundDetails.serializeBinaryToWriter = function(message, writer) { var f = undefined; f = message.getLockupTransactionHash(); if (f.length > 0) { @@ -5104,13 +5433,13 @@ proto.boltzrpc.SubscribeRefundsResponse.serializeBinaryToWriter = function(messa * optional string lockup_transaction_hash = 1; * @return {string} */ -proto.boltzrpc.SubscribeRefundsResponse.prototype.getLockupTransactionHash = function() { +proto.boltzrpc.RefundDetails.prototype.getLockupTransactionHash = function() { return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); }; /** @param {string} value */ -proto.boltzrpc.SubscribeRefundsResponse.prototype.setLockupTransactionHash = function(value) { +proto.boltzrpc.RefundDetails.prototype.setLockupTransactionHash = function(value) { jspb.Message.setProto3StringField(this, 1, value); }; @@ -5119,13 +5448,13 @@ proto.boltzrpc.SubscribeRefundsResponse.prototype.setLockupTransactionHash = fun * optional uint32 lockup_vout = 2; * @return {number} */ -proto.boltzrpc.SubscribeRefundsResponse.prototype.getLockupVout = function() { +proto.boltzrpc.RefundDetails.prototype.getLockupVout = function() { return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); }; /** @param {number} value */ -proto.boltzrpc.SubscribeRefundsResponse.prototype.setLockupVout = function(value) { +proto.boltzrpc.RefundDetails.prototype.setLockupVout = function(value) { jspb.Message.setProto3IntField(this, 2, value); }; @@ -5134,13 +5463,13 @@ proto.boltzrpc.SubscribeRefundsResponse.prototype.setLockupVout = function(value * optional uint32 miner_fee = 3; * @return {number} */ -proto.boltzrpc.SubscribeRefundsResponse.prototype.getMinerFee = function() { +proto.boltzrpc.RefundDetails.prototype.getMinerFee = function() { return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); }; /** @param {number} value */ -proto.boltzrpc.SubscribeRefundsResponse.prototype.setMinerFee = function(value) { +proto.boltzrpc.RefundDetails.prototype.setMinerFee = function(value) { jspb.Message.setProto3IntField(this, 3, value); }; @@ -7093,4 +7422,13 @@ proto.boltzrpc.InvoiceEvent = { SETTLED: 2 }; +/** + * @enum {number} + */ +proto.boltzrpc.SwapEvent = { + CLAIM: 0, + ABORT: 1, + REFUND: 2 +}; + goog.object.extend(exports, proto.boltzrpc); diff --git a/lib/service/Service.ts b/lib/service/Service.ts index 217696af..0043209f 100644 --- a/lib/service/Service.ts +++ b/lib/service/Service.ts @@ -47,6 +47,9 @@ interface Service { on(event: 'claim', listener: (lockupTransactionHash: string, lockupVout: number, minerFee: number) => void): this; emit(event: 'claim', lockupTransactionHash: string, lockupVout: number, minerFee: number): boolean; + on(event: 'abort', listener: (invoice: string) => void): this; + emit(event: 'abort', invoice: string): boolean; + on(event: 'refund', listener: (lockupTransactionHash: string, lockupVout: number, minerFee: number) => void): this; emit(event: 'refund', lockupTransactionHash: string, lockupVout: number, minerFee: number): boolean; @@ -110,9 +113,8 @@ class Service extends EventEmitter { constructor(private serviceComponents: ServiceComponents) { super(); - this.subscribeClaims(); - this.subscribeRefunds(); this.subscribeInvoices(); + this.subscribeSwapEvents(); this.subscribeTransactions(); this.subscribeChannelBackups(); } @@ -449,18 +451,17 @@ class Service extends EventEmitter { } /** - * Subscribes to a stream of swap outputs that Boltz claims + * Subscribes to a stream of swap events */ - private subscribeClaims = () => { + private subscribeSwapEvents = () => { this.serviceComponents.swapManager.nursery.on('claim', (lockupTransactionHash, vout, minerFee) => { this.emit('claim', lockupTransactionHash, vout, minerFee); }); - } - /** - * Subscribes to a stream of lockup transactions that Boltz refunds - */ - private subscribeRefunds = () => { + this.serviceComponents.swapManager.nursery.on('abort', (invoice) => { + this.emit('abort', invoice); + }); + this.serviceComponents.swapManager.nursery.on('refund', (lockupTransactionHash, vout, minerFee) => { this.emit('refund', lockupTransactionHash, vout, minerFee); }); diff --git a/lib/swap/SwapManager.ts b/lib/swap/SwapManager.ts index 337c2b78..abead0ee 100644 --- a/lib/swap/SwapManager.ts +++ b/lib/swap/SwapManager.ts @@ -21,6 +21,8 @@ class SwapManager { if (!this.currencies.get(currency.symbol)) { const swapMaps = { swaps: new Map(), + swapTimeouts: new Map(), + reverseSwaps: new Map(), }; @@ -47,9 +49,17 @@ class SwapManager { * @param outputType what kind of adress should be returned * @param timeoutBlockNumber after how many blocks the onchain script should time out */ - public createSwap = async (baseCurrency: string, quoteCurrency: string, orderSide: OrderSide, rate: number, - fee: number, invoice: string, refundPublicKey: Buffer, outputType: OutputType, timeoutBlockNumber: number) => { - + public createSwap = async ( + baseCurrency: string, + quoteCurrency: string, + orderSide: OrderSide, + rate: number, + fee: number, + invoice: string, + refundPublicKey: Buffer, + outputType: OutputType, + timeoutBlockNumber: number, + ) => { const { sendingCurrency, receivingCurrency } = this.getCurrencies(baseCurrency, quoteCurrency, orderSide); this.logger.silly(`Sending ${sendingCurrency.symbol} on Lightning and receiving ${receivingCurrency.symbol} on the chain`); @@ -83,14 +93,19 @@ class SwapManager { const expectedAmount = this.calculateExpectedAmount(numSatoshis, this.getRate(rate, orderSide)) + fee; - receivingCurrency.swaps.set(getHexString(outputScript), { - invoice, - outputType, - redeemScript, - expectedAmount, - claimKeys: keys, - lndClient: sendingCurrency.lndClient, - }); + this.nursery.addSwap( + receivingCurrency, + { + invoice, + outputType, + redeemScript, + expectedAmount, + claimKeys: keys, + lndClient: sendingCurrency.lndClient, + }, + outputScript, + timeoutBlockHeight, + ); receivingCurrency.chainClient.updateOutputFilter([outputScript]); @@ -114,9 +129,16 @@ class SwapManager { * @param amount amount of the invoice * @param timeoutBlockNumber after how many blocks the onchain script should time out */ - public createReverseSwap = async (baseCurrency: string, quoteCurrency: string, orderSide: OrderSide, rate: number, - fee: number, claimPublicKey: Buffer, amount: number, timeoutBlockNumber: number) => { - + public createReverseSwap = async ( + baseCurrency: string, + quoteCurrency: string, + orderSide: OrderSide, + rate: number, + fee: number, + claimPublicKey: Buffer, + amount: number, + timeoutBlockNumber: number, + ) => { const { sendingCurrency, receivingCurrency } = this.getCurrencies(baseCurrency, quoteCurrency, orderSide); this.logger.silly(`Sending ${sendingCurrency.symbol} on the chain and receiving ${receivingCurrency.symbol} on Lightning`); diff --git a/lib/swap/SwapNursery.ts b/lib/swap/SwapNursery.ts index c7d440ab..e035deea 100644 --- a/lib/swap/SwapNursery.ts +++ b/lib/swap/SwapNursery.ts @@ -28,19 +28,27 @@ type SwapMaps = { // A map between the output scripts and the swaps details swaps: Map; + // A map between the timeout block heights and the output scripts of the normal swaps + swapTimeouts: Map; + // A map between the timeout block heights and the reverse swaps details reverseSwaps: Map; }; interface SwapNursery { + // Swap related events on(event: 'claim', listener: (lockupTransactionHash: string, lockupVout: number, minerFee: number) => void): this; emit(event: 'claim', lockupTransactionHash: string, lockupVout: number, minerFee: number): boolean; - on(event: 'refund', listener: (lockupTransactionHash: string, lockupVout: number, minerFee: number) => void): this; - emit(event: 'refund', lockupTransactionHash: string, lockupVout: number, minerFee: number): boolean; + on(event: 'abort', listener: (invoice: string) => void): this; + emit(event: 'abort', invoice: string): boolean; on(event: 'invoice.failedToPay', listener: (invoice: string) => void): this; emit(event: 'invoice.failedToPay', invoice: string): boolean; + + // Reverse swap related events + on(event: 'refund', listener: (lockupTransactionHash: string, lockupVout: number, minerFee: number) => void): this; + emit(event: 'refund', lockupTransactionHash: string, lockupVout: number, minerFee: number): boolean; } class SwapNursery extends EventEmitter { @@ -48,6 +56,24 @@ class SwapNursery extends EventEmitter { super(); } + public addSwap = ( + maps: SwapMaps, + details: SwapDetails, + rawOutputScript: Buffer, + timeoutBlockHeight: number, + ) => { + const outputScript = getHexString(rawOutputScript); + maps.swaps.set(outputScript, details); + + const swapTimeouts = maps.swapTimeouts.get(timeoutBlockHeight); + + if (swapTimeouts) { + swapTimeouts.push(outputScript); + } else { + maps.swapTimeouts.set(timeoutBlockHeight, [outputScript]); + } + } + public bindCurrency = (currency: Currency, maps: SwapMaps) => { currency.chainClient.on('transaction.relevant.block', async (transaction: Transaction) => { let vout = 0; @@ -77,6 +103,23 @@ class SwapNursery extends EventEmitter { }); currency.chainClient.on('block', async (height: number) => { + const swapTimeouts = maps.swapTimeouts.get(height); + + if (swapTimeouts) { + swapTimeouts.forEach((outputScript) => { + const swap = maps.swaps.get(outputScript); + + if (swap) { + this.logger.verbose(`Aborting swap: ${swap.invoice}`); + this.emit('abort', swap.invoice); + + maps.swaps.delete(outputScript); + } + }); + + maps.swapTimeouts.delete(height); + } + const reverseSwaps = maps.reverseSwaps.get(height); if (reverseSwaps) { diff --git a/package-lock.json b/package-lock.json index 236992f4..fcedb450 100644 --- a/package-lock.json +++ b/package-lock.json @@ -106,13 +106,13 @@ "dev": true }, "@types/inquirer": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-6.0.1.tgz", - "integrity": "sha512-O9rEHE9iBvYaFAGS0fAlDzqY/3CsOrRKzni4zwnAEce2JrHUEbXAce2Pwwe8ZGzmQkucwSXn1tSiKig37INgfA==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/@types/inquirer/-/inquirer-6.0.3.tgz", + "integrity": "sha512-lBsdZScFMaFYYIE3Y6CWX22B9VeY2NerT1kyU2heTc3u/W6a+Om6Au2q0rMzBrzynN0l4QoABhI0cbNdyz6fDg==", "dev": true, "requires": { "@types/through": "*", - "rxjs": ">=6.4.0" + "rxjs": "^6.4.0" }, "dependencies": { "rxjs": { @@ -133,14 +133,14 @@ "dev": true }, "@types/node": { - "version": "12.0.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.0.tgz", - "integrity": "sha512-Jrb/x3HT4PTJp6a4avhmJCDEVrPdqLfl3e8GGMbpkGGdwAV5UGlIs4vVEfsHHfylZVOKZWpOqmqFH8CbfOZ6kg==" + "version": "12.0.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.2.tgz", + "integrity": "sha512-5tabW/i+9mhrfEOUcLDu2xBPsHJ+X5Orqy9FKpale3SjDA17j5AEpYq5vfy3oAeAHGcvANRCO3NV3d2D6q3NiA==" }, "@types/node-forge": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-0.8.2.tgz", - "integrity": "sha512-tj6TSHR2JUvHMryMTsy+vAZ4Fnu6EBxJ22CAGhm+B1/B5ASMeYTOfeIa8KD6Y+GGMvm0Gora45NptakUAnwy0g==", + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-0.8.3.tgz", + "integrity": "sha512-cDc9enmIRJdF5b3rkKsDMBhE/UrvwbDEwCYL8y9k/v7HUWPaSeK6lG2LF1SrrkqFyKPkQBTFL940YZGO+OSbaQ==", "dev": true, "requires": { "@types/node": "*" @@ -800,20 +800,21 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "optional": true, "requires": { "file-uri-to-path": "1.0.0" } }, "bip32": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/bip32/-/bip32-2.0.2.tgz", - "integrity": "sha512-Wws0wBYp+KViCTJLLalmOUhefd1puJslme6ks1HPRuEEXGA28HNRVcx6aIGnH0VNYr/NqoUMYf/QakCjbXcElQ==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/bip32/-/bip32-2.0.3.tgz", + "integrity": "sha512-Tg4dHUXiYBkJyCQq4g++C2PqKcZRveVqy7cKxyl88Uai7MmmknFGaF88odYrXcXk5EMyrlXLuAMC3yEiLxRnNA==", "requires": { "@types/node": "10.12.18", "bs58check": "^2.1.1", "create-hash": "^1.2.0", "create-hmac": "^1.1.7", - "tiny-secp256k1": "^1.0.0", + "tiny-secp256k1": "^1.1.0", "typeforce": "^1.11.5", "wif": "^2.0.6" }, @@ -862,13 +863,13 @@ "integrity": "sha512-pef6gxZFztEhaE9RY9HmWVmiIHqCb2OyS4HPKkpc6CIiiOa3Qmuoylxc5P2EkU3w+5eTSifI9SEZC88idAIGow==" }, "bitcoinjs-lib": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/bitcoinjs-lib/-/bitcoinjs-lib-5.0.3.tgz", - "integrity": "sha512-uc1htf5acG5vcwyhOnES1MFIe21fNn+0VnJLNAcw1/uAQGDF0SNfzEA8SUwnMZ4J26zHiAmk6hVnlVl8yYOTPA==", + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/bitcoinjs-lib/-/bitcoinjs-lib-5.0.4.tgz", + "integrity": "sha512-xX+nTIBeTn8p4R4CbQaArvAjSt5gKsYTEWmFcD8hlH6ZDXaACvQVk1m7XpqNGP/84Wpd6FTIZoaYycLYfM95xA==", "requires": { "@types/node": "10.12.18", "bech32": "^1.1.2", - "bip32": "^2.0.0", + "bip32": "^2.0.3", "bip66": "^1.1.0", "bitcoin-ops": "^1.4.0", "bs58check": "^2.0.0", @@ -877,7 +878,7 @@ "merkle-lib": "^2.0.10", "pushdata-bitcoin": "^1.0.1", "randombytes": "^2.0.1", - "tiny-secp256k1": "^1.0.0", + "tiny-secp256k1": "^1.1.1", "typeforce": "^1.11.3", "varuint-bitcoin": "^1.0.4", "wif": "^2.0.1" @@ -900,9 +901,9 @@ } }, "bluebird": { - "version": "3.5.4", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.4.tgz", - "integrity": "sha512-FG+nFEZChJrbQ9tIccIfZJBz3J7mLrAhxakAbnrJWn8d7aKOC+LWifa0G+p4ZqKp4y13T7juYvdhq9NzKdsrjw==" + "version": "3.5.5", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", + "integrity": "sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==" }, "bn.js": { "version": "4.11.8", @@ -1254,6 +1255,7 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", "integrity": "sha512-4FG+RSG9DL7uEwRUZXZn3SS34DiDPfzP0VOiEwtUWlE+AR2EIg+hSyvrIgUUfhdgR/UkAeW2QHgeP+hWrXs7jQ==", + "dev": true, "requires": { "string-width": "^2.1.1", "strip-ansi": "^4.0.0", @@ -1263,12 +1265,14 @@ "ansi-regex": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", - "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=" + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true }, "strip-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, "requires": { "ansi-regex": "^3.0.0" } @@ -2341,7 +2345,8 @@ "file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", - "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==", + "optional": true }, "fill-range": { "version": "4.0.0", @@ -3449,9 +3454,9 @@ "dev": true }, "grpc": { - "version": "1.20.3", - "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.20.3.tgz", - "integrity": "sha512-GsEsi0NVj6usS/xor8pF/xDbDiwZQR59aZl5NUZ59Sy2bdPQFZ3UePr5wevZjHboirRCIQCKRI1cCgvSWUe2ag==", + "version": "1.21.1", + "resolved": "https://registry.npmjs.org/grpc/-/grpc-1.21.1.tgz", + "integrity": "sha512-PFsZQazf62nP05a0xm23mlImMuw5oVlqF/0zakmsdqJgvbABe+d6VThY2PfhqJmWEL/FhQ6QNYsxS5EAM6++7g==", "requires": { "lodash.camelcase": "^4.3.0", "lodash.clone": "^4.5.0", @@ -3634,9 +3639,9 @@ } }, "nan": { - "version": "2.13.2", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz", - "integrity": "sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw==" + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==" }, "needle": { "version": "2.3.1", @@ -3776,7 +3781,7 @@ }, "dependencies": { "glob": { - "version": "7.1.3", + "version": "7.1.4", "bundled": true, "requires": { "fs.realpath": "^1.0.0", @@ -5801,6 +5806,12 @@ "integrity": "sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw==", "dev": true }, + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==", + "dev": true + }, "debug": { "version": "3.2.6", "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", @@ -5824,6 +5835,26 @@ "path-is-absolute": "^1.0.0" } }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "dev": true, + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "dev": true, + "requires": { + "ansi-regex": "^4.1.0" + } + }, "supports-color": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.0.0.tgz", @@ -5832,6 +5863,25 @@ "requires": { "has-flag": "^3.0.0" } + }, + "yargs": { + "version": "13.2.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.2.2.tgz", + "integrity": "sha512-WyEoxgyTD3w5XRpAQNYUB9ycVH/PQrToaTXdYXRdOXvEy1l19br+VJsc0vcO8PTGg5ro/l/GY7F/JMEBmI0BxA==", + "dev": true, + "requires": { + "cliui": "^4.0.0", + "find-up": "^3.0.0", + "get-caller-file": "^2.0.1", + "os-locale": "^3.1.0", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^3.0.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^13.0.0" + } } } }, @@ -6017,9 +6067,9 @@ } }, "node-forge": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.8.2.tgz", - "integrity": "sha512-mXQ9GBq1N3uDCyV1pdSzgIguwgtVpM7f5/5J4ipz12PKWElmPpVWLDuWl8iXmhysr21+WmX/OJ5UKx82wjomgg==" + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.8.4.tgz", + "integrity": "sha512-UOfdpxivIYY4g5tqp5FNRNgROVNxRACUxxJREntJLFaJr1E0UEqFtUIk0F/jYx/E+Y6sVXd0KDi/m5My0yGCVw==" }, "node-pre-gyp": { "version": "0.11.0", @@ -6544,7 +6594,7 @@ }, "os-locale": { "version": "1.4.0", - "resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", "requires": { "lcid": "^1.0.0" @@ -6552,7 +6602,7 @@ }, "string-width": { "version": "1.0.2", - "resolved": "http://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "requires": { "code-point-at": "^1.0.0", @@ -6567,7 +6617,7 @@ }, "yargs": { "version": "3.32.0", - "resolved": "http://registry.npmjs.org/yargs/-/yargs-3.32.0.tgz", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-3.32.0.tgz", "integrity": "sha1-AwiOnr+edWtpdRYR0qXvWRSCyZU=", "requires": { "camelcase": "^2.0.1", @@ -7052,9 +7102,9 @@ } }, "sequelize": { - "version": "5.8.5", - "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.8.5.tgz", - "integrity": "sha512-FvI3ceqYnNmgbBDeMvD7kdPFAnqelchiMavM+v+1SC+J19M4NThLSxrYL+yJWUJCSe++dHTyv2MEe7OBDVL6mw==", + "version": "5.8.6", + "resolved": "https://registry.npmjs.org/sequelize/-/sequelize-5.8.6.tgz", + "integrity": "sha512-u6KJuMBNLAE44PkGUTlevBseb6BV/n5r8CDGmYe1VxcGxdlWXYUiNXlEFEW0OL6ie+yXYV7dnPHa/fDi1M7gMw==", "requires": { "bluebird": "^3.5.0", "cls-bluebird": "^2.1.0", @@ -7650,21 +7700,31 @@ "dev": true }, "tiny-secp256k1": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/tiny-secp256k1/-/tiny-secp256k1-1.1.0.tgz", - "integrity": "sha512-DIl0SCUIVcPrk/oOiq8/YgQ69Beayw4XSW2icyXJN8xfKMmxo5XM8gXVG1Ex+rYsHg2xuEpNFeeU6J4CtqQFrA==", + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/tiny-secp256k1/-/tiny-secp256k1-1.1.2.tgz", + "integrity": "sha512-InukePecGvfngAEmPR/AIVpAmBTBCdO7tFuMKCpQDE6Zr+lQVT/hDArPkUUolPPpCgwbN/yk2rSAGhJsoIl4hA==", "requires": { - "bindings": "^1.3.0", "bn.js": "^4.11.8", "create-hmac": "^1.1.7", "elliptic": "^6.4.0", - "nan": "^2.12.1" + "tiny-secp256k1-native": "1.1.x" + } + }, + "tiny-secp256k1-native": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/tiny-secp256k1-native/-/tiny-secp256k1-native-1.1.0.tgz", + "integrity": "sha512-ZEt41e4pvq52Zs6MqNZpbDH3qg5fQkOCH9bzGsVPtlLeo9tdfNFz2XfjiKzo1Rc+Yvv4cb0lzy7ClQ3FbE4kKg==", + "optional": true, + "requires": { + "bindings": "^1.3.0", + "nan": "^2.13.2" }, "dependencies": { "nan": { - "version": "2.13.2", - "resolved": "https://registry.npmjs.org/nan/-/nan-2.13.2.tgz", - "integrity": "sha512-TghvYc72wlMGMVMluVo9WRJc0mB8KxxF/gZ4YYFy7V2ZQX9l7rgbPg7vjS9mt6U5HXODVFVI2bOduCzwOMv/lw==" + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", + "optional": true } } }, @@ -7863,23 +7923,42 @@ } }, "ts-node": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.1.0.tgz", - "integrity": "sha512-34jpuOrxDuf+O6iW1JpgTRDFynUZ1iEqtYruBqh35gICNjN8x+LpVcPAcwzLPi9VU6mdA3ym+x233nZmZp445A==", + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.1.1.tgz", + "integrity": "sha512-nd+mdxDP2BjQlyumBCMSU3IQLEjSla1X3uSzDfQ4M5OEZ3iDC01gjhs0FX29jyolATwLKB7YoRJ1Asbxd9EEoA==", "dev": true, "requires": { "arg": "^4.1.0", - "diff": "^3.1.0", + "diff": "^4.0.1", "make-error": "^1.1.1", "source-map-support": "^0.5.6", "yn": "^3.0.0" + }, + "dependencies": { + "diff": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.1.tgz", + "integrity": "sha512-s2+XdvhPCOF01LRQBC8hf4vhbVmI2CGS5aZnxLJlT5FtdhPCDFq80q++zK2KlrVorVDdL5BOGZ/VfLrVtYNF+Q==", + "dev": true + } } }, "ts-protoc-gen": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/ts-protoc-gen/-/ts-protoc-gen-0.9.0.tgz", - "integrity": "sha512-cFEUTY9U9o6C4DPPfMHk2ZUdIAKL91hZN1fyx5Stz3g56BDVOC7hk+r5fEMCAGaaIgi2akkT1a2hrxu1wo2Phg==", - "dev": true + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/ts-protoc-gen/-/ts-protoc-gen-0.10.0.tgz", + "integrity": "sha512-EEbgDWNHK3CvcNhmib94I4HMO23qLddjLRdXW8EUE11VJxbi3n5J0l2DiX/L1pijOaPTkbEoRK+zQinKgKGqsw==", + "dev": true, + "requires": { + "google-protobuf": "^3.6.1" + }, + "dependencies": { + "google-protobuf": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/google-protobuf/-/google-protobuf-3.7.1.tgz", + "integrity": "sha512-6fvlUey6cNKtWSEn1bt4CT4wc2EID1fVluHS1dOnqIlxyIu3cBid2BvWE8Rwl6wN+hRTgiAKhfyydAGV/weZYQ==", + "dev": true + } + } }, "tslib": { "version": "1.9.3", @@ -8446,11 +8525,11 @@ "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==" }, "yargs": { - "version": "13.2.2", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.2.2.tgz", - "integrity": "sha512-WyEoxgyTD3w5XRpAQNYUB9ycVH/PQrToaTXdYXRdOXvEy1l19br+VJsc0vcO8PTGg5ro/l/GY7F/JMEBmI0BxA==", + "version": "13.2.4", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.2.4.tgz", + "integrity": "sha512-HG/DWAJa1PAnHT9JAhNa8AbAv3FPaiLzioSjCcmuXXhP8MlpHO5vwls4g4j6n30Z74GVQj8Xa62dWVx1QCGklg==", "requires": { - "cliui": "^4.0.0", + "cliui": "^5.0.0", "find-up": "^3.0.0", "get-caller-file": "^2.0.1", "os-locale": "^3.1.0", @@ -8460,7 +8539,7 @@ "string-width": "^3.0.0", "which-module": "^2.0.0", "y18n": "^4.0.0", - "yargs-parser": "^13.0.0" + "yargs-parser": "^13.1.0" }, "dependencies": { "ansi-regex": { @@ -8468,6 +8547,16 @@ "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==" }, + "cliui": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", + "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", + "requires": { + "string-width": "^3.1.0", + "strip-ansi": "^5.2.0", + "wrap-ansi": "^5.1.0" + } + }, "string-width": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", @@ -8485,6 +8574,25 @@ "requires": { "ansi-regex": "^4.1.0" } + }, + "wrap-ansi": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", + "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", + "requires": { + "ansi-styles": "^3.2.0", + "string-width": "^3.0.0", + "strip-ansi": "^5.0.0" + } + }, + "yargs-parser": { + "version": "13.1.0", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.0.tgz", + "integrity": "sha512-Yq+32PrijHRri0vVKQEm+ys8mbqWjLiwQkMFNXEENutzLPP0bE4Lcd4iA3OQY5HF+GD3xXxf0MEHb8E4/SA3AA==", + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } } } }, @@ -8492,6 +8600,7 @@ "version": "13.0.0", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.0.0.tgz", "integrity": "sha512-w2LXjoL8oRdRQN+hOyppuXs+V/fVAYtpcrRxZuF7Kt/Oc+Jr2uAcVntaUTNT6w5ihoWfFDpNY8CPx1QskxZ/pw==", + "dev": true, "requires": { "camelcase": "^5.0.0", "decamelize": "^1.2.0" diff --git a/package.json b/package.json index 3f20782b..de437df6 100644 --- a/package.json +++ b/package.json @@ -50,21 +50,21 @@ ], "dependencies": { "async-lock": "^1.2.0", - "bip32": "^2.0.2", + "bip32": "^2.0.3", "bip39": "^3.0.2", - "bitcoinjs-lib": "^5.0.3", + "bitcoinjs-lib": "^5.0.4", "boltz-core": "^0.0.7", "cross-os": "^1.3.0", - "grpc": "^1.20.3", + "grpc": "^1.21.1", "inquirer": "^6.3.1", - "node-forge": "^0.8.2", - "sequelize": "^5.8.5", + "node-forge": "^0.8.4", + "sequelize": "^5.8.6", "sqlite3": "^4.0.8", "toml": "^3.0.0", "typescript": "^3.4.5", "uuid": "^3.3.2", "winston": "^3.2.1", - "yargs": "^13.2.2", + "yargs": "^13.2.4", "zeromq": "^5.1.0" }, "devDependencies": { @@ -73,10 +73,10 @@ "@types/chai-as-promised": "^7.1.0", "@types/exit-hook": "^2.2.1", "@types/ini": "^1.3.30", - "@types/inquirer": "6.0.1", + "@types/inquirer": "6.0.3", "@types/mocha": "^5.2.6", - "@types/node": "^12.0.0", - "@types/node-forge": "^0.8.2", + "@types/node": "^12.0.2", + "@types/node-forge": "^0.8.3", "@types/uuid": "^3.4.4", "@types/yargs": "^13.0.0", "@types/zeromq": "^4.6.2", @@ -89,8 +89,8 @@ "mocha": "^6.1.4", "nodemon": "^1.19.0", "ts-mockito": "^2.3.1", - "ts-node": "^8.1.0", - "ts-protoc-gen": "^0.9.0", + "ts-node": "^8.1.1", + "ts-protoc-gen": "^0.10.0", "tslint": "^5.16.0", "tslint-config-airbnb": "^5.11.1", "tslint-no-circular-imports": "^0.6.2" diff --git a/proto/boltzrpc.proto b/proto/boltzrpc.proto index 29e242ea..cdc90c13 100644 --- a/proto/boltzrpc.proto +++ b/proto/boltzrpc.proto @@ -39,18 +39,15 @@ service Boltz { rpc ListenOnAddress (ListenOnAddressRequest) returns (ListenOnAddressResponse); + /* Subscribes to a stream of swap events */ + rpc SubscribeSwapEvents (SubscribeSwapEventsRequest) returns (stream SubscribeSwapEventsResponse); + /* 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 invoice events */ rpc SubscribeInvoices (SubscribeInvoicesRequest) returns (stream SubscribeInvoicesResponse); - /* Subscribes to a stream of swap outputs that Boltz claims */ - rpc SubscribeClaims (SubscribeClaimsRequest) returns (stream SubscribeClaimsResponse); - - /* Subscribes to a stream of lockup transactions that Boltz refunds */ - rpc SubscribeRefunds (SubscribeRefundsRequest) returns (stream SubscribeRefundsResponse); - /* Subscribes to a stream of channel backups */ rpc SubscribeChannelBackups (SubscribeChannelBackupsRequest) returns (stream ChannelBackup); } @@ -69,9 +66,17 @@ enum OrderSide { enum InvoiceEvent { PAID = 0; FAILED_TO_PAY = 1; + SETTLED = 2; } +enum SwapEvent { + CLAIM = 0; + ABORT= 1; + + REFUND = 2; +} + message GetInfoRequest {} message GetInfoResponse { string version = 1; @@ -184,16 +189,30 @@ message SubscribeInvoicesResponse { } } -message SubscribeClaimsRequest {} -message SubscribeClaimsResponse { +message SubscribeSwapEventsRequest {} +message SubscribeSwapEventsResponse { + SwapEvent event = 1; + + oneof event_details { + ClaimDetails claim_details = 2; + AbortDetails abort_details = 3; + + RefundDetails refund_details = 4; + } +} + +message ClaimDetails { string lockup_transaction_hash = 1; uint32 lockup_vout = 2; uint32 miner_fee = 3; } -message SubscribeRefundsRequest {} -message SubscribeRefundsResponse { +message AbortDetails { + string invoice = 1; +} + +message RefundDetails { string lockup_transaction_hash = 1; uint32 lockup_vout = 2;