diff --git a/lib/lightning/LndClient.ts b/lib/lightning/LndClient.ts index 1ef5d41a..56e4f2fa 100644 --- a/lib/lightning/LndClient.ts +++ b/lib/lightning/LndClient.ts @@ -285,12 +285,12 @@ class LndClient extends BaseClient implements LightningClient { } /** - * Gets the total funds available across all open channels in satoshis + * Gets a list of all open channels */ - public channelBalance = () => { - const request = new lndrpc.ChannelBalanceRequest(); + public listChannels = () => { + const request = new lndrpc.ListChannelsRequest(); - return this.unaryCall('channelBalance', request); + return this.unaryCall('listChannels', request); } /** diff --git a/lib/proto/boltzrpc_pb.d.ts b/lib/proto/boltzrpc_pb.d.ts index b3683d3d..fe6372b6 100644 --- a/lib/proto/boltzrpc_pb.d.ts +++ b/lib/proto/boltzrpc_pb.d.ts @@ -227,9 +227,6 @@ export namespace GetBalanceResponse { } export class Balance extends jspb.Message { - getChannelBalance(): number; - setChannelBalance(value: number): void; - hasWalletBalance(): boolean; clearWalletBalance(): void; @@ -237,6 +234,12 @@ export class Balance extends jspb.Message { setWalletBalance(value?: WalletBalance): void; + hasLightningBalance(): boolean; + clearLightningBalance(): void; + getLightningBalance(): LightningBalance | undefined; + setLightningBalance(value?: LightningBalance): void; + + serializeBinary(): Uint8Array; toObject(includeInstance?: boolean): Balance.AsObject; static toObject(includeInstance: boolean, msg: Balance): Balance.AsObject; @@ -249,8 +252,8 @@ export class Balance extends jspb.Message { export namespace Balance { export type AsObject = { - channelBalance: number, walletBalance?: WalletBalance.AsObject, + lightningBalance?: LightningBalance.AsObject, } } @@ -283,6 +286,31 @@ export namespace WalletBalance { } } +export class LightningBalance extends jspb.Message { + getLocalBalance(): number; + setLocalBalance(value: number): void; + + getRemoteBalance(): number; + setRemoteBalance(value: number): void; + + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): LightningBalance.AsObject; + static toObject(includeInstance: boolean, msg: LightningBalance): LightningBalance.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: LightningBalance, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): LightningBalance; + static deserializeBinaryFromReader(message: LightningBalance, reader: jspb.BinaryReader): LightningBalance; +} + +export namespace LightningBalance { + export type AsObject = { + localBalance: number, + remoteBalance: number, + } +} + export class NewAddressRequest extends jspb.Message { getCurrency(): string; setCurrency(value: string): void; diff --git a/lib/proto/boltzrpc_pb.js b/lib/proto/boltzrpc_pb.js index 2fec0210..8b5c8fa4 100644 --- a/lib/proto/boltzrpc_pb.js +++ b/lib/proto/boltzrpc_pb.js @@ -29,6 +29,7 @@ goog.exportSymbol('proto.boltzrpc.GetInfoResponse', null, global); goog.exportSymbol('proto.boltzrpc.GetTransactionRequest', null, global); goog.exportSymbol('proto.boltzrpc.GetTransactionResponse', null, global); goog.exportSymbol('proto.boltzrpc.InvoiceEvent', null, global); +goog.exportSymbol('proto.boltzrpc.LightningBalance', null, global); goog.exportSymbol('proto.boltzrpc.ListenOnAddressRequest', null, global); goog.exportSymbol('proto.boltzrpc.ListenOnAddressResponse', null, global); goog.exportSymbol('proto.boltzrpc.LndChannels', null, global); @@ -625,19 +626,19 @@ proto.boltzrpc.ChainInfo.deserializeBinaryFromReader = function(msg, reader) { var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint32()); msg.setVersion(value); break; case 2: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint64()); msg.setProtocolversion(value); break; case 3: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint64()); msg.setBlocks(value); break; case 4: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint64()); msg.setConnections(value); break; case 5: @@ -675,28 +676,28 @@ proto.boltzrpc.ChainInfo.serializeBinaryToWriter = function(message, writer) { var f = undefined; f = message.getVersion(); if (f !== 0) { - writer.writeInt32( + writer.writeUint32( 1, f ); } f = message.getProtocolversion(); if (f !== 0) { - writer.writeInt32( + writer.writeUint64( 2, f ); } f = message.getBlocks(); if (f !== 0) { - writer.writeInt32( + writer.writeUint64( 3, f ); } f = message.getConnections(); if (f !== 0) { - writer.writeInt32( + writer.writeUint64( 4, f ); @@ -712,7 +713,7 @@ proto.boltzrpc.ChainInfo.serializeBinaryToWriter = function(message, writer) { /** - * optional int32 version = 1; + * optional uint32 version = 1; * @return {number} */ proto.boltzrpc.ChainInfo.prototype.getVersion = function() { @@ -727,7 +728,7 @@ proto.boltzrpc.ChainInfo.prototype.setVersion = function(value) { /** - * optional int32 protocolversion = 2; + * optional uint64 protocolversion = 2; * @return {number} */ proto.boltzrpc.ChainInfo.prototype.getProtocolversion = function() { @@ -742,7 +743,7 @@ proto.boltzrpc.ChainInfo.prototype.setProtocolversion = function(value) { /** - * optional int32 blocks = 3; + * optional uint64 blocks = 3; * @return {number} */ proto.boltzrpc.ChainInfo.prototype.getBlocks = function() { @@ -757,7 +758,7 @@ proto.boltzrpc.ChainInfo.prototype.setBlocks = function(value) { /** - * optional int32 connections = 4; + * optional uint64 connections = 4; * @return {number} */ proto.boltzrpc.ChainInfo.prototype.getConnections = function() { @@ -883,7 +884,7 @@ proto.boltzrpc.LndInfo.deserializeBinaryFromReader = function(msg, reader) { msg.setLndChannels(value); break; case 3: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint64()); msg.setBlockHeight(value); break; case 4: @@ -936,7 +937,7 @@ proto.boltzrpc.LndInfo.serializeBinaryToWriter = function(message, writer) { } f = message.getBlockHeight(); if (f !== 0) { - writer.writeInt32( + writer.writeUint64( 3, f ); @@ -997,7 +998,7 @@ proto.boltzrpc.LndInfo.prototype.hasLndChannels = function() { /** - * optional int32 block_height = 3; + * optional uint64 block_height = 3; * @return {number} */ proto.boltzrpc.LndInfo.prototype.getBlockHeight = function() { @@ -1113,15 +1114,15 @@ proto.boltzrpc.LndChannels.deserializeBinaryFromReader = function(msg, reader) { var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint32()); msg.setActive(value); break; case 2: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint32()); msg.setInactive(value); break; case 3: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint32()); msg.setPending(value); break; default: @@ -1155,21 +1156,21 @@ proto.boltzrpc.LndChannels.serializeBinaryToWriter = function(message, writer) { var f = undefined; f = message.getActive(); if (f !== 0) { - writer.writeInt32( + writer.writeUint32( 1, f ); } f = message.getInactive(); if (f !== 0) { - writer.writeInt32( + writer.writeUint32( 2, f ); } f = message.getPending(); if (f !== 0) { - writer.writeInt32( + writer.writeUint32( 3, f ); @@ -1178,7 +1179,7 @@ proto.boltzrpc.LndChannels.serializeBinaryToWriter = function(message, writer) { /** - * optional int32 active = 1; + * optional uint32 active = 1; * @return {number} */ proto.boltzrpc.LndChannels.prototype.getActive = function() { @@ -1193,7 +1194,7 @@ proto.boltzrpc.LndChannels.prototype.setActive = function(value) { /** - * optional int32 inactive = 2; + * optional uint32 inactive = 2; * @return {number} */ proto.boltzrpc.LndChannels.prototype.getInactive = function() { @@ -1208,7 +1209,7 @@ proto.boltzrpc.LndChannels.prototype.setInactive = function(value) { /** - * optional int32 pending = 3; + * optional uint32 pending = 3; * @return {number} */ proto.boltzrpc.LndChannels.prototype.getPending = function() { @@ -1555,8 +1556,8 @@ proto.boltzrpc.Balance.prototype.toObject = function(opt_includeInstance) { */ proto.boltzrpc.Balance.toObject = function(includeInstance, msg) { var f, obj = { - channelBalance: jspb.Message.getFieldWithDefault(msg, 1, 0), - walletBalance: (f = msg.getWalletBalance()) && proto.boltzrpc.WalletBalance.toObject(includeInstance, f) + walletBalance: (f = msg.getWalletBalance()) && proto.boltzrpc.WalletBalance.toObject(includeInstance, f), + lightningBalance: (f = msg.getLightningBalance()) && proto.boltzrpc.LightningBalance.toObject(includeInstance, f) }; if (includeInstance) { @@ -1594,14 +1595,15 @@ proto.boltzrpc.Balance.deserializeBinaryFromReader = function(msg, reader) { var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {number} */ (reader.readInt64()); - msg.setChannelBalance(value); - break; - case 2: var value = new proto.boltzrpc.WalletBalance; reader.readMessage(value,proto.boltzrpc.WalletBalance.deserializeBinaryFromReader); msg.setWalletBalance(value); break; + case 2: + var value = new proto.boltzrpc.LightningBalance; + reader.readMessage(value,proto.boltzrpc.LightningBalance.deserializeBinaryFromReader); + msg.setLightningBalance(value); + break; default: reader.skipField(); break; @@ -1631,57 +1633,73 @@ proto.boltzrpc.Balance.prototype.serializeBinary = function() { */ proto.boltzrpc.Balance.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = message.getChannelBalance(); - if (f !== 0) { - writer.writeInt64( + f = message.getWalletBalance(); + if (f != null) { + writer.writeMessage( 1, - f + f, + proto.boltzrpc.WalletBalance.serializeBinaryToWriter ); } - f = message.getWalletBalance(); + f = message.getLightningBalance(); if (f != null) { writer.writeMessage( 2, f, - proto.boltzrpc.WalletBalance.serializeBinaryToWriter + proto.boltzrpc.LightningBalance.serializeBinaryToWriter ); } }; /** - * optional int64 channel_balance = 1; - * @return {number} + * optional WalletBalance wallet_balance = 1; + * @return {?proto.boltzrpc.WalletBalance} */ -proto.boltzrpc.Balance.prototype.getChannelBalance = function() { - return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); +proto.boltzrpc.Balance.prototype.getWalletBalance = function() { + return /** @type{?proto.boltzrpc.WalletBalance} */ ( + jspb.Message.getWrapperField(this, proto.boltzrpc.WalletBalance, 1)); }; -/** @param {number} value */ -proto.boltzrpc.Balance.prototype.setChannelBalance = function(value) { - jspb.Message.setProto3IntField(this, 1, value); +/** @param {?proto.boltzrpc.WalletBalance|undefined} value */ +proto.boltzrpc.Balance.prototype.setWalletBalance = function(value) { + jspb.Message.setWrapperField(this, 1, value); +}; + + +proto.boltzrpc.Balance.prototype.clearWalletBalance = function() { + this.setWalletBalance(undefined); }; /** - * optional WalletBalance wallet_balance = 2; - * @return {?proto.boltzrpc.WalletBalance} + * Returns whether this field is set. + * @return {boolean} */ -proto.boltzrpc.Balance.prototype.getWalletBalance = function() { - return /** @type{?proto.boltzrpc.WalletBalance} */ ( - jspb.Message.getWrapperField(this, proto.boltzrpc.WalletBalance, 2)); +proto.boltzrpc.Balance.prototype.hasWalletBalance = function() { + return jspb.Message.getField(this, 1) != null; }; -/** @param {?proto.boltzrpc.WalletBalance|undefined} value */ -proto.boltzrpc.Balance.prototype.setWalletBalance = function(value) { +/** + * optional LightningBalance lightning_balance = 2; + * @return {?proto.boltzrpc.LightningBalance} + */ +proto.boltzrpc.Balance.prototype.getLightningBalance = function() { + return /** @type{?proto.boltzrpc.LightningBalance} */ ( + jspb.Message.getWrapperField(this, proto.boltzrpc.LightningBalance, 2)); +}; + + +/** @param {?proto.boltzrpc.LightningBalance|undefined} value */ +proto.boltzrpc.Balance.prototype.setLightningBalance = function(value) { jspb.Message.setWrapperField(this, 2, value); }; -proto.boltzrpc.Balance.prototype.clearWalletBalance = function() { - this.setWalletBalance(undefined); +proto.boltzrpc.Balance.prototype.clearLightningBalance = function() { + this.setLightningBalance(undefined); }; @@ -1689,7 +1707,7 @@ proto.boltzrpc.Balance.prototype.clearWalletBalance = function() { * Returns whether this field is set. * @return {boolean} */ -proto.boltzrpc.Balance.prototype.hasWalletBalance = function() { +proto.boltzrpc.Balance.prototype.hasLightningBalance = function() { return jspb.Message.getField(this, 2) != null; }; @@ -1781,15 +1799,15 @@ proto.boltzrpc.WalletBalance.deserializeBinaryFromReader = function(msg, reader) var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setTotalBalance(value); break; case 2: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setConfirmedBalance(value); break; case 3: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setUnconfirmedBalance(value); break; default: @@ -1823,21 +1841,21 @@ proto.boltzrpc.WalletBalance.serializeBinaryToWriter = function(message, writer) var f = undefined; f = message.getTotalBalance(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 1, f ); } f = message.getConfirmedBalance(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 2, f ); } f = message.getUnconfirmedBalance(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 3, f ); @@ -1846,7 +1864,7 @@ proto.boltzrpc.WalletBalance.serializeBinaryToWriter = function(message, writer) /** - * optional int64 total_balance = 1; + * optional uint64 total_balance = 1; * @return {number} */ proto.boltzrpc.WalletBalance.prototype.getTotalBalance = function() { @@ -1861,7 +1879,7 @@ proto.boltzrpc.WalletBalance.prototype.setTotalBalance = function(value) { /** - * optional int64 confirmed_balance = 2; + * optional uint64 confirmed_balance = 2; * @return {number} */ proto.boltzrpc.WalletBalance.prototype.getConfirmedBalance = function() { @@ -1876,7 +1894,7 @@ proto.boltzrpc.WalletBalance.prototype.setConfirmedBalance = function(value) { /** - * optional int64 unconfirmed_balance = 3; + * optional uint64 unconfirmed_balance = 3; * @return {number} */ proto.boltzrpc.WalletBalance.prototype.getUnconfirmedBalance = function() { @@ -1891,6 +1909,175 @@ proto.boltzrpc.WalletBalance.prototype.setUnconfirmedBalance = function(value) { +/** + * 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.LightningBalance = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.boltzrpc.LightningBalance, jspb.Message); +if (goog.DEBUG && !COMPILED) { + proto.boltzrpc.LightningBalance.displayName = 'proto.boltzrpc.LightningBalance'; +} + + +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.LightningBalance.prototype.toObject = function(opt_includeInstance) { + return proto.boltzrpc.LightningBalance.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.LightningBalance} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.boltzrpc.LightningBalance.toObject = function(includeInstance, msg) { + var f, obj = { + localBalance: jspb.Message.getFieldWithDefault(msg, 1, 0), + remoteBalance: jspb.Message.getFieldWithDefault(msg, 2, 0) + }; + + 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.LightningBalance} + */ +proto.boltzrpc.LightningBalance.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.boltzrpc.LightningBalance; + return proto.boltzrpc.LightningBalance.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.boltzrpc.LightningBalance} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.boltzrpc.LightningBalance} + */ +proto.boltzrpc.LightningBalance.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {number} */ (reader.readUint64()); + msg.setLocalBalance(value); + break; + case 2: + var value = /** @type {number} */ (reader.readUint64()); + msg.setRemoteBalance(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.boltzrpc.LightningBalance.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.boltzrpc.LightningBalance.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.LightningBalance} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.boltzrpc.LightningBalance.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getLocalBalance(); + if (f !== 0) { + writer.writeUint64( + 1, + f + ); + } + f = message.getRemoteBalance(); + if (f !== 0) { + writer.writeUint64( + 2, + f + ); + } +}; + + +/** + * optional uint64 local_balance = 1; + * @return {number} + */ +proto.boltzrpc.LightningBalance.prototype.getLocalBalance = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 1, 0)); +}; + + +/** @param {number} value */ +proto.boltzrpc.LightningBalance.prototype.setLocalBalance = function(value) { + jspb.Message.setProto3IntField(this, 1, value); +}; + + +/** + * optional uint64 remote_balance = 2; + * @return {number} + */ +proto.boltzrpc.LightningBalance.prototype.getRemoteBalance = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); +}; + + +/** @param {number} value */ +proto.boltzrpc.LightningBalance.prototype.setRemoteBalance = function(value) { + jspb.Message.setProto3IntField(this, 2, value); +}; + + + /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a @@ -2602,7 +2789,7 @@ proto.boltzrpc.GetFeeEstimationRequest.deserializeBinaryFromReader = function(ms msg.setCurrency(value); break; case 2: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint64()); msg.setBlocks(value); break; default: @@ -2643,7 +2830,7 @@ proto.boltzrpc.GetFeeEstimationRequest.serializeBinaryToWriter = function(messag } f = message.getBlocks(); if (f !== 0) { - writer.writeInt32( + writer.writeUint64( 2, f ); @@ -2667,7 +2854,7 @@ proto.boltzrpc.GetFeeEstimationRequest.prototype.setCurrency = function(value) { /** - * optional int32 blocks = 2; + * optional uint64 blocks = 2; * @return {number} */ proto.boltzrpc.GetFeeEstimationRequest.prototype.getBlocks = function() { @@ -2768,7 +2955,7 @@ proto.boltzrpc.GetFeeEstimationResponse.deserializeBinaryFromReader = function(m case 1: var value = msg.getFeesMap(); reader.readMessage(value, function(message, reader) { - jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readInt32, null, ""); + jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readUint32, null, ""); }); break; default: @@ -2802,13 +2989,13 @@ proto.boltzrpc.GetFeeEstimationResponse.serializeBinaryToWriter = function(messa var f = undefined; f = message.getFeesMap(true); if (f && f.getLength() > 0) { - f.serializeBinary(1, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeInt32); + f.serializeBinary(1, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeUint32); } }; /** - * map fees = 1; + * map fees = 1; * @param {boolean=} opt_noLazyCreate Do not create the map if * empty, instead returning `undefined` * @return {!jspb.Map} @@ -4385,7 +4572,7 @@ proto.boltzrpc.CreateSwapRequest.deserializeBinaryFromReader = function(msg, rea msg.setRate(value); break; case 5: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setFee(value); break; case 6: @@ -4401,7 +4588,7 @@ proto.boltzrpc.CreateSwapRequest.deserializeBinaryFromReader = function(msg, rea msg.setOutputType(value); break; case 9: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setTimeoutBlockNumber(value); break; default: @@ -4463,7 +4650,7 @@ proto.boltzrpc.CreateSwapRequest.serializeBinaryToWriter = function(message, wri } f = message.getFee(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 5, f ); @@ -4491,7 +4678,7 @@ proto.boltzrpc.CreateSwapRequest.serializeBinaryToWriter = function(message, wri } f = message.getTimeoutBlockNumber(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 9, f ); @@ -4560,7 +4747,7 @@ proto.boltzrpc.CreateSwapRequest.prototype.setRate = function(value) { /** - * optional int64 fee = 5; + * optional uint64 fee = 5; * @return {number} */ proto.boltzrpc.CreateSwapRequest.prototype.getFee = function() { @@ -4620,7 +4807,7 @@ proto.boltzrpc.CreateSwapRequest.prototype.setOutputType = function(value) { /** - * optional int64 timeout_block_number = 9; + * optional uint64 timeout_block_number = 9; * @return {number} */ proto.boltzrpc.CreateSwapRequest.prototype.getTimeoutBlockNumber = function() { @@ -4726,7 +4913,7 @@ proto.boltzrpc.CreateSwapResponse.deserializeBinaryFromReader = function(msg, re msg.setRedeemScript(value); break; case 2: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setTimeoutBlockHeight(value); break; case 3: @@ -4734,7 +4921,7 @@ proto.boltzrpc.CreateSwapResponse.deserializeBinaryFromReader = function(msg, re msg.setAddress(value); break; case 4: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setExpectedAmount(value); break; default: @@ -4775,7 +4962,7 @@ proto.boltzrpc.CreateSwapResponse.serializeBinaryToWriter = function(message, wr } f = message.getTimeoutBlockHeight(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 2, f ); @@ -4789,7 +4976,7 @@ proto.boltzrpc.CreateSwapResponse.serializeBinaryToWriter = function(message, wr } f = message.getExpectedAmount(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 4, f ); @@ -4813,7 +5000,7 @@ proto.boltzrpc.CreateSwapResponse.prototype.setRedeemScript = function(value) { /** - * optional int64 timeout_block_height = 2; + * optional uint64 timeout_block_height = 2; * @return {number} */ proto.boltzrpc.CreateSwapResponse.prototype.getTimeoutBlockHeight = function() { @@ -4843,7 +5030,7 @@ proto.boltzrpc.CreateSwapResponse.prototype.setAddress = function(value) { /** - * optional int64 expected_amount = 4; + * optional uint64 expected_amount = 4; * @return {number} */ proto.boltzrpc.CreateSwapResponse.prototype.getExpectedAmount = function() { @@ -4965,7 +5152,7 @@ proto.boltzrpc.CreateReverseSwapRequest.deserializeBinaryFromReader = function(m msg.setRate(value); break; case 5: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setFee(value); break; case 6: @@ -4973,11 +5160,11 @@ proto.boltzrpc.CreateReverseSwapRequest.deserializeBinaryFromReader = function(m msg.setClaimPublicKey(value); break; case 7: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setAmount(value); break; case 8: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setTimeoutBlockNumber(value); break; default: @@ -5039,7 +5226,7 @@ proto.boltzrpc.CreateReverseSwapRequest.serializeBinaryToWriter = function(messa } f = message.getFee(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 5, f ); @@ -5053,14 +5240,14 @@ proto.boltzrpc.CreateReverseSwapRequest.serializeBinaryToWriter = function(messa } f = message.getAmount(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 7, f ); } f = message.getTimeoutBlockNumber(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 8, f ); @@ -5129,7 +5316,7 @@ proto.boltzrpc.CreateReverseSwapRequest.prototype.setRate = function(value) { /** - * optional int64 fee = 5; + * optional uint64 fee = 5; * @return {number} */ proto.boltzrpc.CreateReverseSwapRequest.prototype.getFee = function() { @@ -5159,7 +5346,7 @@ proto.boltzrpc.CreateReverseSwapRequest.prototype.setClaimPublicKey = function(v /** - * optional int64 amount = 7; + * optional uint64 amount = 7; * @return {number} */ proto.boltzrpc.CreateReverseSwapRequest.prototype.getAmount = function() { @@ -5174,7 +5361,7 @@ proto.boltzrpc.CreateReverseSwapRequest.prototype.setAmount = function(value) { /** - * optional int64 timeout_block_number = 8; + * optional uint64 timeout_block_number = 8; * @return {number} */ proto.boltzrpc.CreateReverseSwapRequest.prototype.getTimeoutBlockNumber = function() { @@ -5534,11 +5721,11 @@ proto.boltzrpc.SendCoinsRequest.deserializeBinaryFromReader = function(msg, read msg.setAddress(value); break; case 3: - var value = /** @type {number} */ (reader.readInt64()); + var value = /** @type {number} */ (reader.readUint64()); msg.setAmount(value); break; case 4: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint32()); msg.setSatPerVbyte(value); break; default: @@ -5586,14 +5773,14 @@ proto.boltzrpc.SendCoinsRequest.serializeBinaryToWriter = function(message, writ } f = message.getAmount(); if (f !== 0) { - writer.writeInt64( + writer.writeUint64( 3, f ); } f = message.getSatPerVbyte(); if (f !== 0) { - writer.writeInt32( + writer.writeUint32( 4, f ); @@ -5632,7 +5819,7 @@ proto.boltzrpc.SendCoinsRequest.prototype.setAddress = function(value) { /** - * optional int64 amount = 3; + * optional uint64 amount = 3; * @return {number} */ proto.boltzrpc.SendCoinsRequest.prototype.getAmount = function() { @@ -5647,7 +5834,7 @@ proto.boltzrpc.SendCoinsRequest.prototype.setAmount = function(value) { /** - * optional int32 sat_per_vbyte = 4; + * optional uint32 sat_per_vbyte = 4; * @return {number} */ proto.boltzrpc.SendCoinsRequest.prototype.getSatPerVbyte = function() { @@ -5751,7 +5938,7 @@ proto.boltzrpc.SendCoinsResponse.deserializeBinaryFromReader = function(msg, rea msg.setTransactionHash(value); break; case 2: - var value = /** @type {number} */ (reader.readInt32()); + var value = /** @type {number} */ (reader.readUint32()); msg.setVout(value); break; default: @@ -5792,7 +5979,7 @@ proto.boltzrpc.SendCoinsResponse.serializeBinaryToWriter = function(message, wri } f = message.getVout(); if (f !== 0) { - writer.writeInt32( + writer.writeUint32( 2, f ); @@ -5816,7 +6003,7 @@ proto.boltzrpc.SendCoinsResponse.prototype.setTransactionHash = function(value) /** - * optional int32 vout = 2; + * optional uint32 vout = 2; * @return {number} */ proto.boltzrpc.SendCoinsResponse.prototype.getVout = function() { diff --git a/lib/service/Service.ts b/lib/service/Service.ts index 1443fd59..d5b387c2 100644 --- a/lib/service/Service.ts +++ b/lib/service/Service.ts @@ -16,6 +16,7 @@ import { CurrencyInfo, WalletBalance, GetInfoResponse, + LightningBalance, GetBalanceResponse, GetFeeEstimationResponse, } from '../proto/boltzrpc_pb'; @@ -173,7 +174,7 @@ class Service extends EventEmitter { const response = new GetBalanceResponse(); const map = response.getBalancesMap(); - const getBalance = async (wallet: Wallet, symbol: string) => { + const getBalance = async (symbol: string, wallet: Wallet) => { const balance = new Balance(); const walletObject = new WalletBalance(); @@ -185,26 +186,41 @@ class Service extends EventEmitter { balance.setWalletBalance(walletObject); - const currencyInfo = this.serviceComponents.currencies.get(symbol)!; - const channelBalance = await currencyInfo.lndClient.channelBalance(); + const currencyInfo = this.serviceComponents.currencies.get(symbol); - balance.setChannelBalance(channelBalance.balance); + if (currencyInfo) { + const lightningObject = new LightningBalance(); + const { channelsList } = await currencyInfo.lndClient.listChannels(); + + let localBalance = 0; + let remoteBalance = 0; + + channelsList.forEach((channel) => { + localBalance += channel.localBalance; + remoteBalance += channel.remoteBalance; + }); + + lightningObject.setLocalBalance(localBalance); + lightningObject.setRemoteBalance(remoteBalance); + + balance.setLightningBalance(lightningObject); + } return balance; }; - if (!emptyCurrency) { + if (emptyCurrency) { + for (const [symbol, wallet] of walletManager.wallets) { + map.set(symbol, await getBalance(symbol, wallet)); + } + } else { const wallet = walletManager.wallets.get(args.currency); if (!wallet) { throw Errors.CURRENCY_NOT_FOUND(args.currency); } - map.set(args.currency, await getBalance(wallet, args.currency)); - } else { - for (const [symbol, wallet] of walletManager.wallets) { - map.set(symbol, await getBalance(wallet, symbol)); - } + map.set(args.currency, await getBalance(args.currency, wallet)); } return response; diff --git a/package.json b/package.json index dd1752b3..3526bb56 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Backend of boltz", "main": "dist/Boltz.js", "scripts": { - "proto": "cross-os proto && cross-os protoFixDeprecation", + "proto": "cross-os proto", "compile": "cross-os precompile && tsc && cross-os postcompile", "compile:watch": "tsc -w", "start": "node bin/boltzd", @@ -34,11 +34,6 @@ "darwin": "rsync -am --include '*/' --include '*.js*' --exclude '*' lib/proto/ dist/proto", "win32": "xcopy /s lib\\proto\\*.js* dist\\proto\\* >nul" }, - "protoFixDeprecation": { - "linux": "sed -i -- 's/new Buffer(/Buffer.from(/g' lib/proto/*.js", - "darwin": "sed -i '' 's/new Buffer(/Buffer.from(/g' lib/proto/*.js", - "win32": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./winFixDeprecation.ps1" - }, "proto": { "linux": "./node_modules/grpc-tools/bin/protoc --js_out='import_style=commonjs,binary:lib/proto' --ts_out='lib/proto' --grpc_out='lib/proto' --plugin='protoc-gen-grpc=node_modules/.bin/grpc_tools_node_protoc_plugin' --plugin='protoc-gen-ts=node_modules/grpc_tools_node_protoc_ts/bin/protoc-gen-ts' -I='proto' proto/*.proto proto/google/api/*.proto proto/google/protobuf/*.proto", "darwin": "./node_modules/grpc-tools/bin/protoc --js_out='import_style=commonjs,binary:lib/proto' --ts_out='lib/proto' --grpc_out='lib/proto' --plugin='protoc-gen-grpc=node_modules/.bin/grpc_tools_node_protoc_plugin' --plugin='protoc-gen-ts=node_modules/grpc_tools_node_protoc_ts/bin/protoc-gen-ts' -I='proto' proto/*.proto proto/google/api/*.proto proto/google/protobuf/*.proto", diff --git a/proto/boltzrpc.proto b/proto/boltzrpc.proto index 6d53d53b..72e48ac4 100644 --- a/proto/boltzrpc.proto +++ b/proto/boltzrpc.proto @@ -72,23 +72,23 @@ message CurrencyInfo { } message ChainInfo { - int32 version = 1; - int32 protocolversion = 2; - int32 blocks = 3; - int32 connections = 4; + uint32 version = 1; + uint64 protocolversion = 2; + uint64 blocks = 3; + uint64 connections = 4; string error = 5; } message LndInfo { string version = 1; LndChannels lnd_channels = 2; - int32 block_height = 3; + uint64 block_height = 3; string error = 4; } message LndChannels { - int32 active = 1; - int32 inactive = 2; - int32 pending = 3; + uint32 active = 1; + uint32 inactive = 2; + uint32 pending = 3; } message GetBalanceRequest { @@ -98,13 +98,17 @@ message GetBalanceResponse { map balances = 1; } message Balance { - int64 channel_balance = 1; - WalletBalance wallet_balance = 2; + WalletBalance wallet_balance = 1; + LightningBalance lightning_balance = 2; } message WalletBalance { - int64 total_balance = 1; - int64 confirmed_balance = 2; - int64 unconfirmed_balance = 3; + uint64 total_balance = 1; + uint64 confirmed_balance = 2; + uint64 unconfirmed_balance = 3; +} +message LightningBalance { + uint64 local_balance = 1; + uint64 remote_balance = 2; } message NewAddressRequest { @@ -125,10 +129,10 @@ message GetTransactionResponse { message GetFeeEstimationRequest { string currency = 1; - int32 blocks = 2; + uint64 blocks = 2; } message GetFeeEstimationResponse { - map fees = 1; + map fees = 1; } message BroadcastTransactionRequest { @@ -168,17 +172,17 @@ message CreateSwapRequest { string quote_currency = 2; OrderSide order_side = 3; float rate = 4; - int64 fee = 5; + uint64 fee = 5; string invoice = 6; string refund_public_key = 7; OutputType output_type = 8; - int64 timeout_block_number = 9; + uint64 timeout_block_number = 9; } message CreateSwapResponse { string redeem_script = 1; - int64 timeout_block_height = 2; + uint64 timeout_block_height = 2; string address = 3; - int64 expected_amount = 4; + uint64 expected_amount = 4; } message CreateReverseSwapRequest { @@ -186,11 +190,11 @@ message CreateReverseSwapRequest { string quote_currency = 2; OrderSide order_side = 3; float rate = 4; - int64 fee = 5; + uint64 fee = 5; string claim_public_key = 6; // Amount of the invoice that will be returned - int64 amount = 7; - int64 timeout_block_number = 8; + uint64 amount = 7; + uint64 timeout_block_number = 8; } message CreateReverseSwapResponse { string invoice = 1; @@ -203,10 +207,10 @@ message CreateReverseSwapResponse { message SendCoinsRequest { string currency = 1; string address = 2; - int64 amount = 3; - int32 sat_per_vbyte = 4; + uint64 amount = 3; + uint32 sat_per_vbyte = 4; } message SendCoinsResponse { string transaction_hash = 1; - int32 vout = 2; + uint32 vout = 2; } diff --git a/winFixDeprecation.ps1 b/winFixDeprecation.ps1 deleted file mode 100644 index 3cdb9348..00000000 --- a/winFixDeprecation.ps1 +++ /dev/null @@ -1,6 +0,0 @@ -$InputFiles = Get-Item "lib/proto/*.js" -$OldString = 'new Buffer' -$NewString = 'Buffer.from' -$InputFiles | ForEach { - (Get-Content -Path $_.FullName).Replace($OldString,$NewString) | Set-Content -Path $_.FullName -}