Skip to content

Commit

Permalink
Update getChannel types
Browse files Browse the repository at this point in the history
  • Loading branch information
bkiac committed Jun 16, 2024
1 parent 8af8333 commit 7f9324d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
27 changes: 23 additions & 4 deletions lnd_methods/info/get_channel.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import type {MergeExclusive} from 'type-fest';
import {
AuthenticatedLightningArgs,
AuthenticatedLightningMethod,
ChannelPolicy,
} from '../../typescript';

export type GetChannelArgs = AuthenticatedLightningArgs<{
/** Standard Format Channel Id */
id: string;
}>;
export type GetChannelArgs = AuthenticatedLightningArgs<
MergeExclusive<
{
/** Standard Format Channel Id */
id: string;
},
{
/** Funding Outpoint Transaction Id Hex String */
transaction_id: string;
/** Funding Outpoint Transaction Output Index Number */
transaction_vout: number;
}
>
>;

export type GetChannelResult = {
/** Maximum Tokens */
Expand All @@ -27,6 +38,14 @@ export type GetChannelResult = {
* Get graph information about a channel on the network
*
* Requires `info:read` permission
*
* `inbound_base_discount_mtokens` is not supported on LND 0.17.5 and below
*
* `inbound_rate_discount` is not supported on LND 0.17.5 and below
*
* `transaction_id` is not supported on LND 0.18.0 and below
*
* `transaction_vout` is not supported on LND 0.18.0 and below
*/
export const getChannel: AuthenticatedLightningMethod<
GetChannelArgs,
Expand Down
12 changes: 10 additions & 2 deletions test/typescript/get_channel.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ import {AuthenticatedLnd} from '../../lnd_grpc';
import {getChannel, GetChannelResult} from '../../lnd_methods';

const lnd = {} as AuthenticatedLnd;
const id = '00';
const id = 'id';
const transaction_id = 'tx_id';
const transaction_vout = 0;

expectError(getChannel());
expectError(getChannel({}));

// Expect error because only one of id or transaction_id/transaction_vout is allowed
expectError(getChannel({lnd, id, transaction_id, transaction_vout}));

expectType<GetChannelResult>(await getChannel({lnd, id}));
expectType<GetChannelResult>(
await getChannel({lnd, transaction_id, transaction_vout}),
);

expectType<void>(
getChannel({lnd, id}, (error, result) => {
expectType<GetChannelResult>(result);
})
}),
);

0 comments on commit 7f9324d

Please sign in to comment.