Skip to content

Commit

Permalink
fix(channel): remove unsupported ways to reopen channel by a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Sep 4, 2024
1 parent c8fbffe commit f3746a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
17 changes: 2 additions & 15 deletions src/channel/Base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import EventEmitter from 'events';
import { w3cwebsocket as W3CWebSocket } from 'websocket';
import { snakeToPascal } from '../utils/string';
import { buildTx, unpackTx } from '../tx/builder';
import { unpackTx } from '../tx/builder';
import { Tag } from '../tx/builder/constants';
import * as handlers from './handlers';
import {
Expand Down Expand Up @@ -249,8 +249,7 @@ export default class Channel {
* signed state and then terminates.
*
* The channel can be reestablished by instantiating another Channel instance
* with two extra params: existingChannelId and offchainTx (returned from leave
* method as channelId and signedTx respectively).
* with two extra params: existingChannelId and existingFsmId.
*
* @example
* ```js
Expand Down Expand Up @@ -290,16 +289,4 @@ export default class Channel {
};
});
}

static async reconnect(options: ChannelOptions, txParams: any): Promise<Channel> {
const { sign } = options;

return Channel.initialize({
...options,
reconnectTx: await sign(
'reconnect',
buildTx({ ...txParams, tag: Tag.ChannelClientReconnectTx }),
),
});
}
}
19 changes: 3 additions & 16 deletions src/channel/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
ChannelError,
} from '../utils/errors';
import { encodeContractAddress } from '../utils/crypto';
import { buildTx } from '../tx/builder';
import { ensureError } from '../utils/other';

export interface ChannelEvents {
Expand Down Expand Up @@ -53,7 +52,6 @@ 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}
*/
interface CommonChannelOptions {
existingFsmId?: Encoded.Bytearray;
/**
* Channel url (for example: "ws://localhost:3001")
*/
Expand Down Expand Up @@ -118,10 +116,9 @@ interface CommonChannelOptions {
*/
existingChannelId?: Encoded.Channel;
/**
* Offchain transaction (required if reestablishing a channel)
* Existing FSM id (required if reestablishing a channel)
*/
offChainTx?: Encoded.Transaction;
reconnectTx?: Encoded.Transaction;
existingFsmId?: Encoded.Bytearray;
/**
* The time waiting for a new event to be initiated (default: 600000)
*/
Expand Down Expand Up @@ -174,7 +171,6 @@ interface CommonChannelOptions {
* Function which verifies and signs transactions
*/
sign: SignTxWithTag;
offchainTx?: Encoded.Transaction;
}

export type ChannelOptions = CommonChannelOptions & ({
Expand Down Expand Up @@ -439,16 +435,7 @@ export async function initialize(
onopen: async (event: Event) => {
resolve();
changeStatus(channel, 'connected', event);
if (channelOptions.reconnectTx != null) {
enterState(channel, { handler: openHandler });
const { signedTx } = await channel.state();
if (signedTx == null) {
throw new ChannelError('`signedTx` missed in state while reconnection');
}
changeState(channel, buildTx(signedTx));
} else {
enterState(channel, { handler: connectionHandler });
}
enterState(channel, { handler: connectionHandler });
ping(channel);
},
onclose: (event: ICloseEvent) => {
Expand Down

0 comments on commit f3746a1

Please sign in to comment.