Skip to content

Commit

Permalink
fix(channel): accept host only if initiator
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jul 17, 2024
1 parent 2b064d8 commit cfdfd72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
28 changes: 18 additions & 10 deletions src/channel/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export type SignTx = (tx: Encoded.Transaction, options?: SignOptions) => (
/**
* @see {@link https://github.com/aeternity/protocol/blob/6734de2e4c7cce7e5e626caa8305fb535785131d/node/api/channels_api_usage.md#channel-establishing-parameters}
*/
export interface ChannelOptions {
interface CommonChannelOptions {
existingFsmId?: Encoded.Bytearray;
/**
* Channel url (for example: "ws://localhost:3001")
Expand Down Expand Up @@ -92,17 +92,9 @@ export interface ChannelOptions {
*/
ttl?: number;
/**
* Host of the responder's node
*/
host: string;
/**
* The port of the responders node
* The port of the responder's node
*/
port: number;
/**
* Participant role
*/
role: 'initiator' | 'responder';
/**
* How to calculate minimum depth (default: txfee)
*/
Expand Down Expand Up @@ -185,6 +177,22 @@ export interface ChannelOptions {
offchainTx?: Encoded.Transaction;
}

export type ChannelOptions = CommonChannelOptions & ({
/**
* Participant role
*/
role: 'initiator';
/**
* Host of the responder's node
*/
host: string;
} | {
/**
* Participant role
*/
role: 'responder';
});

export interface ChannelHandler extends Function {
enter?: Function;
}
Expand Down
8 changes: 4 additions & 4 deletions test/integration/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '../../src';
import { pause } from '../../src/utils/other';
import {
ChannelOptions, notify, SignTx, SignTxWithTag,
notify, SignTx, SignTxWithTag,
} from '../../src/channel/internal';
import { appendSignature } from '../../src/channel/handlers';
import { assertNotNull, ensureEqual } from '../utils';
Expand Down Expand Up @@ -88,7 +88,7 @@ async function waitForChannel(channel: Channel): Promise<void> {
assertNotNull(signedTx);
return buildTx(signedTx);
};
const sharedParams: Omit<ChannelOptions, 'sign'> = {
const sharedParams = {
url: channelUrl,
pushAmount: 3,
initiatorAmount: 1e15,
Expand All @@ -98,8 +98,8 @@ async function waitForChannel(channel: Channel): Promise<void> {
host: 'localhost',
port: 3114,
lockPeriod: 1,
initiatorId: 'ak_',
responderId: 'ak_',
initiatorId: 'ak_' as Encoded.AccountAddress,
responderId: 'ak_' as Encoded.AccountAddress,
role: 'initiator',
minimumDepth: 0,
};
Expand Down

0 comments on commit cfdfd72

Please sign in to comment.